Monday, June 26, 2023

ORM Framework for Kotlin

In Kotlin, ORM (Object-Relational Mapping) libraries provide a convenient way to interact with databases using object-oriented programming paradigms. There are several popular ORM libraries available for Kotlin that you can use to simplify database operations. Here are a few examples:


1. Exposed: Exposed is a lightweight ORM library for Kotlin that provides a DSL (Domain Specific Language) for defining database schemas, querying, and updating data. It has support for various database backends like MySQL, PostgreSQL, SQLite, and more.


   To use Exposed, you need to add the Exposed dependency to your project's build.gradle file:


   dependencies {

       implementation "org.jetbrains.exposed:exposed-core:0.32.1"

       implementation "org.jetbrains.exposed:exposed-dao:0.32.1"

       implementation "org.jetbrains.exposed:exposed-jdbc:0.32.1"

       implementation "org.jetbrains.exposed:exposed-java-time:0.32.1"

   }



   You can then define your database schema using the Exposed DSL, create tables, and perform CRUD (Create, Read, Update, Delete) operations on your data.


2. Hibernate: Hibernate is a widely used ORM framework in the Java ecosystem, but it also works well with Kotlin. It provides powerful features for mapping objects to database tables, lazy loading, caching, and more. Hibernate supports various database backends and provides a high-level query language called HQL (Hibernate Query Language).


   To use Hibernate with Kotlin, you need to add the Hibernate dependencies to your project. Here's an example using Gradle:


   dependencies {

       implementation "org.hibernate:hibernate-core:5.6.1.Final"

       implementation "org.hibernate:hibernate-entitymanager:5.6.1.Final"

   }



   You can then define your entity classes with annotations and use Hibernate APIs to perform database operations.


3. Ktorm: Ktorm is another Kotlin-centric ORM library that focuses on type-safety and compile-time safety. It provides a fluent DSL for defining database schemas, querying, and updating data. Ktorm supports multiple databases and has features like transactions, connection pooling, and data mapping.


   To use Ktorm, add the Ktorm dependencies to your project's build.gradle file:


   dependencies {

       implementation "org.ktorm:ktorm-core:3.6.0"

       implementation "org.ktorm:ktorm-support-{database}:3.6.0"

   }



   Replace `{database}` with the database you're using (e.g., `mysql`, `postgresql`, `h2`, etc.). Then, you can define your database schema using Ktorm's DSL and perform various operations on your data.


These are just a few examples of ORM libraries available for Kotlin. Depending on your requirements and preferences, you can choose the one that best fits your needs. Remember to refer to the documentation and guides provided by each library to understand their usage and features in more detail.

Tuesday, June 5, 2012

Mobile Browser Limitations

If you are developing web application for Mobile Browser, you should consider limitations of different Mobile browsers.

-In Windows Mobile (IE Mobile 6.12) window event object not supported. Also note that setAttribute/getAttribute not working for custom Attributes.
-In Blackberry, insertAdjucentHTML not supported. getAttribute return "" when there is no attribute
 In dynamic HTML elements it replaces _ and : by space.
-iPhone browser does not support XSL load. xsl:include/xsl:import not working in iPhone browser.

Wednesday, April 7, 2010

HttpClient SocketException

12:57:05,812 ERROR [STDERR] java.net.SocketException: Software caused connection abort: socket write error
12:57:05,812 ERROR [STDERR] at java.net.SocketOutputStream.socketWrite0(Native Method)
12:57:05,812 ERROR [STDERR] at java.net.SocketOutputStream.socketWrite(Unknown Source)

If you are getting above exception when submitting data using HttpClient, Please check following things.

- If HttpClient is posting data to PHP site(Apache Web Server), check LimitRequestBody setting in PHP website(Apache Web Server).

Please refer http://httpd.apache.org/docs/1.3/mod/core.html#limitrequestbody

- If HttpClient is posting data to IIS (ASP site), check maxRequestLength attribute of httpRuntime Element in web.config file of ASP website in IIS.

Please refer http://msdn.microsoft.com/en-us/library/e1f13641%28VS.71%29.aspx

Sunday, November 29, 2009

Applet Caching not working

If your applet always downloads the jar even though jar is cached, Make sure you have not disabled the URLConnection's caching via the API: URLConnection.setUseCaches and URLConnection.SetDefaultUseCaches.

ImageIcon's underlying mechanism for fetching the resource is a URLConnection. Calling URLConnection.setDefaultUseCaches(false), sets a "part of the static state of all URLConnections" which cause the JRE to ignore the cache and redownload the entire jar every time it accessed. Simply removing all instances of setDefaultUseCaches will solve the problem.

http://java.sun.com/j2se/1.5.0/docs/guide/plugin/developer_guide/applet_caching.html

Sunday, May 10, 2009

Not enough storage is available to complete this operation

In IE createStyleSheet throws javascript error Not "enough storage is available to complete this operation".

document.createStyleSheet(cssfile);

To handle it swallow javascript error by catching exception.

try {
    document.createStyleSheet(cssfile)
} catch(e) {}

Saturday, April 25, 2009

Clear session on Browser Close

In web application, it is common that user sign in, do some work and close browser(By clicking X) with doing proper Sign Out. In such case, user session is still active and will be cleared only after specified session out period. If the specified timeout is small than it should not be problem. But if specified timeout is long in that case it is important to clear user session on browser close becuase clearing session on server will remove unused objects from server and hence reduce memory leak.

Here is possible solutions to handle it.

1) One approach is to use frames in your application. After user Sign In, Load application in Frameset as below.


<FRAMESET rows="0, *" onbeforeunload="javascript:callServer()">
<FRAME src="sessionFrame"> // Blank frame unloaded when browser close.
<FRAME src="mainFrame"> // Your Application pages
</FRAMESET>



When user closes browser(By clicking X), it will unload frameset and call callServer() javascript function. In callServer() function make server call(using XMLHttpRequest or submit Html Form) to clear session.

Tuesday, December 16, 2008

JBOSS Portal vs Liferay Portal

Feature Comparison
Feature Liferay(5.1+) JBoss Portal(2.7)
Out of the box Tools Has rich set of out of the box portlets Not too much out of the box portlets
Single Click configuration (altering a page layout, adding new applications and content, and changing look and feel can all be done in a couple of clicks) Supported Supported
Dynamic Drag and Drop(move different elements around in the portal by) Supported Supported
SSO Supported Supported
Role Based Authorization support Supported Supported
Communities and Organizations Liferay users can be intuitively grouped into a hierarchy of "organizations" or cross-organizational "communities," providing flexibility and ease of administration. Not Supported
Personal User Pages All users get a personal space that can be made public (published as a website with a unique friendly URL) or kept private. You can customize how the space looks, what tools and applications are included Not provided
Internationalization support Out of the box internationalization support provided for 22 languages. No out of the box internationalization support available
Wikis Provides robust wiki support Provided
Activity tracking Display most recent activity Not provided
Message Boards Supported (Can be very easily created) Supported
Instant Message Support A friends list automatically displays the names of all other logged-in portal users. If you have something to say, just IM them. Not provided
Alerts and Announcements Broadcast messages to different group of users whether they are simple announcements or "newsletter"-like in purpose Not provided
Blog Support Provided Not Provided
Calendar Rich calendar support(Can add events) Support
Password Policies Liferay provides flexible password policy through Enterprise Admin Portlet. you can apply different rule sets to different sets of portal users. Not Provided

Similarities

•Both are JSR-168 compliant.
•Both are open source.

Differences
•JBoss Portal can only be installed on Jboss application server whereas Liferay works in any J2EE container or servlet container.
•Liferay has been around longer than JBoss Portal.
•The CMS features are very minimal in JBoss Portal because all that one can do is create html pages using a rich text editor and do some file manipulation activities (create directory, move and copy files and so on.
•The CMS portlet in Liferay is more feature rich than that of JBoss in the sense that one can create custom content types and own templates. This helps separate content form its presentation. It is also very easy to create new pages and add them automatically to the navigation bar.
•Liferay has a larger portal community.
•Liferay has more enterprise clients that have run the portal for many years with hundreds of thousands of users.
•Liferay comes with many useful portlets so you don't have to configure much. But, it also has many external portlets and themes available. JBoss has fewer portlets.
•Though Liferay works with almost any application server, I have found users complaining about setup with any other AS take longer time. Whereas setting up JBoss Portal is a straightforward, three-step process of editing some configuration files, creating the database, and starting the portal. Reference
•Also people felt Liferay portal to be bit slow but stable.
•Liferay is under the MIT (similar to Apache/BSD) style license. JBoss is LGPL.

References
Liferay Vs JBoss
Portal Polls Survey
JBoss to Liferay Migration Reason
Liferay User Experience Customization
Liferay Technical Spec

Glossary:
•Out of the box: A ready-made software, hardware, or combination package that meets a need that would otherwise require a special development effort.

Tuesday, September 23, 2008

Eclipse PlugIns

1)Fast Code Eclipse Plugin

Fast Code is a free eclipse plugin designed to help write code faster in a spring based applications. But it can be configured to work with many other kinds of applications as well.
It is free eclipse plugin for faster java development. It can help you code faster in a spring based application. It is capable of :

* Automatically create DAO to Service and Service to Action, e.g. FooDAO to FooService and FooService to FooAction.
* Automatically create one DAO to another with different name, e.g. FooDAO (with methods getFoo, saveFoo) to BarDAO (with methods getBar, saveBar).
* Also create spring based configurations.
* Easily navigate from DAO to Service and Service to DAO.
* Easily navigate from hibernate pojos to .hbm files.
* Easily create List, ArrayList, Map, HashMap initializers or fields in a class.
* Easily copy a field, just highlight and right click, go inside Fast Code pop up menu and click 'Copy Field'
* You can highlight part of the field name also.
* Some of the features can be turned off/on or configured in Windows->Preference->Fast Code Preference.

Reference: http://fast-code.sourceforge.net

2)UCDetector

UCDetector (Unnecessary Code Detector) is a eclipse PlugIn tool to find unnecessary (dead) public java code. For example classes, methods or fields which have no references. UCDetector creates markers for the following problems, which appear in the eclipse problem view.
* Unnecessary (dead) code
* Code where the visibility could be changed to protected, default or private
* Methods of fields, which can be final
UCDetector also finds cyclic dependencies between classes in your code. This cycle classes are shown in s special cycle view.

Reference: http://www.ucdetector.org

Friday, July 11, 2008

Eclipse 3.4 - New Features

Here are descriptions of some of the more interesting or significant changes made to the Java development tools for the 3.4 release of Eclipse.

Java Editor Breadcrumb
The Java editor now offers a breadcrumb which shows the path to the element at the cursor position. The breadcrumb can be enabled via the Toggle Breadcrumb tool bar button or by pressing Alt+Shift+B. Each element in the breadcrumb can be selected and actions can be invoked through a context menu or keyboard short cuts.Furthermore the breadcrumb lets you navigate to other elements via drop-downs.

Rich Javadoc Hover
The Javadoc hover can now be used to navigate Javadoc.
Follow links in Javadoc
Go forward and backward in the navigation history
Show the current content in the Javadoc view
Open the declaration of the current element
Open the current content in an external browser
Resize the hover
Move the hover (start dragging in the toolbar area)

Rich Java problem hover
The problem hover now offers all available quick fixes for a problem and shows a tool bar on F2 or when you move the mouse into it. Quick fixes can be executed by clicking on the links. The actions in the tool bar let you configure the annotation preferences and the problem severity.

Content assist improvements
Content Assist (Ctrl+Space) has been improved in several areas.
Content assist can now use the type of the enclosing instanceof condition to offer more field and method access proposals. The required cast will be inserted when such a proposal is selected.
Content assist for static members also work if the type has not been imported yet. The required import will be added when such a proposal is selected.
Content assist can now propose methods with unknown types.
Content assist on method invocations shows the guessed arguments.

Quick assists
New quick assists (Ctrl+1) have been added in this release.

Highlighting numbers in Java code
The Java editor can now show numbers with their own custom color.

Mark read and write occurrences
Mark Occurrences (Alt+Shift+O) now marks read and write accesses with different colors.

Occurrences in File improvements

Several improvements have been added to Search > Occurrences in File:

The quick menu (Ctrl+Shift+U) now only shows the searches applicable for the current selection. If only one search kind is possible, the shortcut will directly invoke the search.
The menu now offers all searches available by Mark Occurrences.
Matches are now highlighted with different colors for read and write accesses in the search view.
The search view offers a Link with Editor mode where the view input is connected to the current editor selection.

Java compiler on multi-CPU machines
The Eclipse Compiler for Java is now taking advantage of the multi-threading capability of multi-CPU machines. Our measurements show improvements up to 30%. Results depend on the JRE and platform used.

Support for external class folders
Class folders located outside the workspace (external) can now be added to the build path. To add an external class folder use the Java Build Path page of the project properties, select the Libraries tab and push the Add External Class Folder button.

Flexible ZIP archive extensions
It is now possible to add ZIP archives to the build path with file extensions other than .zip or .jar. It is now, for example, possible to add a .rar file on the build path.

Call Hierarchy view works with fields and types
The Call Hierarchy view in caller mode now works with more kinds of elements:
The children of a field are all members that access the field (read and write accesses).
The children of a type or an instance initializer are all constructors of the type

Runnable JAR export wizard
The Runnable JAR File Export wizard can create a JAR file based on a launch configuration. The generated JAR file contains all class files from the project including class files from required JARs and projects.
The generated JAR can be executed with the command: java -jar generated_file.jar
or, on most operating systems, by double-clicking the file.

More Java search options
Type reference search can now be limited to specific match locations in the code. For example, you can find references in cast expressions, or in field and local variable types.
The following example shows how to search for all catch clauses in your code (search for references to '*' and limit to catch clauses):

Paste creates snippet for members and statements
Paste (Ctrl+V) in the Package Explorer view now supports members and statements. Eclipse creates the required enclosing elements for you.

Enhanced debug hover
When debugging, hovers for variables have been enhanced to display an object inspector. The inspector will display logical structures according to the toggle setting in the visible Variables or Expressions view.

Saturday, July 5, 2008

SpringSource Application server

SpringSource announced a new application server that it claims will "liberate" Java users from "antiquated legacy Java technologies."
SpringSource Application Platform is a completely module-based Java application server that is designed to run enterprise Java applications and Spring-powered applications with a new degree of flexibility and reliability. The SpringSource Application Platform is based on the new SpringSource Dynamic Module Kernel™ (dm-Kernel). The dm-Kernel provides a module-based backbone for the server, which also harnesses the power of Spring, Apache Tomcat and OSGi-based technologies.
The product is now in beta at SpringSource's Web site.

Production Benefits
* Real time application and server updates
* Better resource utilization
* Side by side resource versioning
* Longer server uptime
* Run new and old web applications

Development Benefits
* Faster iterative development
* Small server footprint
* More manageable applications
* Greater code reuse

Reference http://www.springsource.com

OSGi technology - Dynamic module system for Java

OSGi technology is Universal Middleware. OSGi technology provides a service-oriented, component-based environment for developers and offers standardized ways to manage the software lifecycle. These capabilities greatly increase the value of a wide range of computers and devices that use the Java platform.OSGi technology adopters benefit from improved time-to-market and reduced development costs because OSGi technology provides for the integration of pre-built and pre-tested component subsystems. The technology also reduces maintenance costs and advances unique new aftermarket opportunities because networks can be utilized to dynamically update or deliver services and applications in the field.

The OSGi framework can be divided in two main elements:

* Services Platform

A services platform is defined as a software platform that supports the service orientation interaction. This interaction involves three main actors: service providers, service requesters and a service registry, although only the service registry belongs to the services platform. In the service orientation interaction, service providers publish service descriptions, and service requesters discover services and bind to the service providers. Publication and discovery are based on a service description.
In the context of OSGi, a service is described as a Java class or interface, the service interface, along with a variable number of attributes, the service properties, that are name and value pairs. Service properties allow different service providers that provide services with the same service interface to be differentiated. The service registry allows service providers to be discovered through queries formulated in an LDAP syntax. Additionnaly, notification mechanisms allow service requesters to receive events signalling changes in the service registry; these changes include the publication or retrieval of a particular service.
In OSGi, service providers and requesters are part of an entity called a bundle that is both a logical as well as physical entity. Service interfaces are implemented by objects created by the bundle. In standard OSGi, the bundle is responsible for run-time service dependency management activities which include publication, discovery and binding as well as adapting to changes resulting from dynamic availability (arrival or departure) of services that are bound to the bundle.

* Deployment infrastructure


Physically, a bundle correspond to a delivery and deployment unit that is materialized by a JAR file that contains code and resources (i.e., images, libraries, etc.) along with a file that contains information about the bundle, the manifest file. The OSGi framework provides mechanisms to support continuous deployment activities (for example a local console or an administration web page). These deployment activities include installation, removal, update, starting (activation) and stopping (de-activation) of a physical bundle. Once a bundle is installed in the platform, it can be activated if deployment dependencies that are associated to the bundle are fulfilled (these dependencies are described in the next section).
Reference
http://www.osgi.org
http://gravity.sourceforge.net/servicebinder/osginutshell.html

ORM Framework for Kotlin

In Kotlin, ORM (Object-Relational Mapping) libraries provide a convenient way to interact with databases using object-oriented programming p...