Tips, observations, bugs and problems from the world of java,j2ee, Spring, Weblogic,Tomcat,Hibernate, Oracle, MySQL and many other technologies.
Monday, 3 December 2012
Monday, 26 November 2012
Hibernate
Introduction:-
Hibernate is a free tool used in Java
programming that allows data to be inserted, removed or changed in a database without paying a lot of attention to how it gets there. So SQL is used—Hibernate does that.
Hibernate was founded by Mr.
Gavin King, an Australian developer who needed to solve a problem and ended up creating Hibernate, an open source tool that is amazingly useful.
When Can I Use Hibernate:
- Hibernate can be used in any Java program that needs to access a relational database.
- Hibernate does not need an application server to run in.
- Hibernate can be used in any Java class with really no other dependencies other than on a single Hibernate JAR file and one configuration file.
When Should I Use Hibernate:
According to The Man himself [Gavin King], you should only consider using Hibernate if:
- You have a non-trivial application.
- You have more than 10 tables in your relational DB.
- Your application uses an object-oriented Domain Model.
- If your application does a lot of business logic—and does much more than just display tables of data on a webpage—then it is a good candidate for Hibernate.
- Hibernate is best in applications with complex data models, with hundreds of tables and complex inter-relationships.
- In a normal JDBC application, you deal with populating a List of POJOs with data you manually pulled from a ResultSet.
How Hibernate Works:
- Hibernate does not force you to change your POJOs.
- Hibernate does not force you to implement any interface.
- Hibernate works on any POJO.
- Hibernate requires 1 overall configuration file.
- That 1 configuration file tells Hibernate
- à Which classes you want to store in the database.
- Each mapped class needs an additional configuration file.
- à How each class relates to the tables and columns
- in the database.
Labels:
HIbernate
Location:
Bangalore, Karnataka, India
Thursday, 8 November 2012
Monday, 5 November 2012
Pagination with BC4J
There are two ways to to do pagination in BC4J.
There is one in build pagination is available in BC4J.
Create you VO object.
then
vo.setAccessmode(RowSet.PAGING_MODE);
vo.setWhereClauseParam(0,25);//for ROWNUM <= section
vo.setWhereClauseParam(1,0);//for ROWNUM> SECTION
Other-way to do this is.
Have one method like below
setPagingQuery(ViewObjectImpl vo){
vo.setQuery("SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM(" +
vo.getQuery() + ")IQ WHERE ROWNUM < " + end +
") WHERE Z_R_N >" + start);
}
then before your do execute your query. just call
setPagingQuery(this);
excecuteQuery();
There is one in build pagination is available in BC4J.
Create you VO object.
then
vo.setAccessmode(RowSet.PAGING_MODE);
vo.setWhereClauseParam(0,25);//for ROWNUM <= section
vo.setWhereClauseParam(1,0);//for ROWNUM> SECTION
Other-way to do this is.
Have one method like below
setPagingQuery(ViewObjectImpl vo){
vo.setQuery("SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM(" +
vo.getQuery() + ")IQ WHERE ROWNUM < " + end +
") WHERE Z_R_N >" + start);
}
then before your do execute your query. just call
setPagingQuery(this);
excecuteQuery();
How to get the five highest-paid people—a top- N query
SELECT * FROM ( SELECT * FROM emp ORDER BY sal DESC ) WHERE ROWNUM <= 5; |
Friday, 26 October 2012
Java Executor Framework Example
import java.util.concurrent.atomic.AtomicInteger; public class Counter { private AtomicInteger value = new AtomicInteger(); public int getValue(){ return value.get(); } public int increment(){ return value.incrementAndGet(); } // Alternative implementation as increment but just make the // implementation explicit public int incrementLongVersion(){ int oldValue = value.get(); while (!value.compareAndSet(oldValue, oldValue+1)){ oldValue = value.get(); } return oldValue+1; } }
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class Test { private static final int NTHREDS = 10; public static void main(String[] args) { final Counter counter = new Counter(); List<Future<Integer>> list = new ArrayList<Future<Integer>>(); ExecutorService executor = Executors.newFixedThreadPool(NTHREDS); for (int i = 0; i < 500; i++) { Callable<Integer> worker = new Callable<Integer>() { @Override public Integer call() throws Exception { int number = counter.increment(); System.out.println(number); return number ; } }; Future<Integer> submit= executor.submit(worker); list.add(submit); } // This will make the executor accept no new threads // and finish all existing threads in the queue executor.shutdown(); // Wait until all threads are finish while (!executor.isTerminated()) { } Set<Integer> set = new HashSet<Integer>(); for (Future<Integer> future : list) { try { set.add(future.get()); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } if (list.size()!=set.size()){ throw new RuntimeException("Double-entries!!!"); } } }
Monday, 15 October 2012
How to find out n th salary from a Table
SELECT MIN(Sal) FROM TableName
WHERE Sal IN
(SELECT TOP n Sal FROM TableName ORDER BY Sal DESC)
WHERE Sal IN
(SELECT TOP n Sal FROM TableName ORDER BY Sal DESC)
Wednesday, 18 July 2012
How to work with OA BC4j in normal oc4j container(Not EBS oc4j container)
First i would like to tell that the OA BC4j is not same as normal BC4J .. It is extended version of BC4j.
So few configuration changes required to make it work in normal oc4j
First we need to copy following files to one folder (Let say applib) in in oc4j server.
../applib/mdsrt.jar"/>
../applib/fwk.jar"/>
../applib/fwkcabo.jar"/>
../applib/fwkjbo.jar"/>
../applib/diagnostics.jar"/>
../applib/concurrent.jar"/>
../applib/collections.jar"/>
../applib/atg.jar"/>
../applib/lesson.jar"/>
../applib/nls_charset12.jar"/>
../applib/oamMaintMode.jar"/>
../applib/part.jar"/>
../applib/req.jar"/>
../applib/svc.jar"/>
Then we need change server.xml to change our adf to new version like below
<shared-library name="adf.oracle.domain" version="10.1.3.1" library-compatible="true">
<code-source path="/u01/app/oracle/product/oas_1/BC4J/lib"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/commons-cli-1.0.jar"/>
<!-- <code-source path="/u01/app/oracle/product/oas_1/mds/lib/concurrent.jar"/> -->
<!-- <code-source path="/u01/app/oracle/product/oas_1/mds/lib/mdsrt.jar"/> -->
<code-source path="/u01/app/oracle/product/oas_1/jlib/share.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/regexp.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/xmlef.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adfmtl.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adfui.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adf-connections.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/dc-adapters.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/ord/jlib/ordim.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/ord/jlib/ordhttp.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/ojmisc.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/jdev-cm.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/lib/xsqlserializers.jar"/>
<code-source path="../applib/mdsrt.jar"/>
<code-source path="../applib/fwk.jar"/>
<code-source path="../applib/fwkcabo.jar"/>
<code-source path="../applib/fwkjbo.jar"/>
<code-source path="../applib/diagnostics.jar"/>
<code-source path="../applib/concurrent.jar"/>
<code-source path="../applib/collections.jar"/>
<code-source path="../applib/atg.jar"/>
<code-source path="../applib/lesson.jar"/>
<code-source path="../applib/nls_charset12.jar"/>
<code-source path="../applib/oamMaintMode.jar"/>
<code-source path="../applib/part.jar"/>
<code-source path="../applib/req.jar"/>
<code-source path="../applib/svc.jar"/>
<code-source path="../applib/uix2.jar"/>
<code-source path="../applib/uix2-install.jar"/>
<code-source path="../applib/wsp.jar"/>
<import-shared-library name="oracle.xml"/>
<import-shared-library name="oracle.jdbc"/>
<import-shared-library name="oracle.gdk"/>
<import-shared-library name="oracle.cache"/>
<import-shared-library name="oracle.dms"/>
<import-shared-library name="oracle.sqlj"/>
<import-shared-library name="oracle.toplink"/>
<import-shared-library name="oracle.ws.core"/>
<import-shared-library name="oracle.ws.client"/>
<import-shared-library name="oracle.xml.security"/>
<import-shared-library name="oracle.ws.security"/>
<import-shared-library name="oracle.ws.reliability"/>
<import-shared-library name="oracle.jwsdl"/>
<import-shared-library name="oracle.http.client"/>
<import-shared-library name="oracle.expression-evaluator"/>
</shared-library>
<shared-library name="adf.generic.domain" version="10.1.3.1" library-compatible="true">
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/bc4jdomgnrc.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/lib"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/commons-cli-1.0.jar"/>
<!-- <code-source path="/u01/app/oracle/product/oas_1/mds/lib/concurrent.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/mds/lib/mdsrt.jar"/> -->
<code-source path="/u01/app/oracle/product/oas_1/jlib/share.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/regexp.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/xmlef.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adfmtl.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adfui.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adf-connections.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/dc-adapters.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/ord/jlib/ordim.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/ord/jlib/ordhttp.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/ojmisc.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/jdev-cm.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/lib/xsqlserializers.jar"/>
<code-source path="../applib/mdsrt.jar"/>
<code-source path="../applib/fwk.jar"/>
<code-source path="../applib/fwkcabo.jar"/>
<code-source path="../applib/fwkjbo.jar"/>
<code-source path="../applib/diagnostics.jar"/>
<code-source path="../applib/concurrent.jar"/>
<code-source path="../applib/collections.jar"/>
<code-source path="../applib/atg.jar"/>
<code-source path="../applib/lesson.jar"/>
<code-source path="../applib/nls_charset12.jar"/>
<code-source path="../applib/oamMaintMode.jar"/>
<code-source path="../applib/part.jar"/>
<code-source path="../applib/req.jar"/>
<code-source path="../applib/svc.jar"/>
<code-source path="../applib/uix2.jar"/>
<code-source path="../applib/uix2-install.jar"/>
<code-source path="../applib/wsp.jar"/>
<import-shared-library name="oracle.xml"/>
<import-shared-library name="oracle.jdbc"/>
<import-shared-library name="oracle.gdk"/>
<import-shared-library name="oracle.cache"/>
<import-shared-library name="oracle.dms"/>
<import-shared-library name="oracle.sqlj"/>
<import-shared-library name="oracle.toplink"/>
<import-shared-library name="oracle.ws.core"/>
<import-shared-library name="oracle.ws.client"/>
<import-shared-library name="oracle.xml.security"/>
<import-shared-library name="oracle.ws.security"/>
<import-shared-library name="oracle.ws.reliability"/>
<import-shared-library name="oracle.jwsdl"/>
<import-shared-library name="oracle.http.client"/>
<import-shared-library name="oracle.expression-evaluator"/>
</shared-library>
We need comment out the path for concurrent.jar and mdsrt.jar for existing setup and add new path.
Please reach out to me in case in help required on this.
So few configuration changes required to make it work in normal oc4j
First we need to copy following files to one folder (Let say applib) in in oc4j server.
../applib/mdsrt.jar"/>
../applib/fwk.jar"/>
../applib/fwkcabo.jar"/>
../applib/fwkjbo.jar"/>
../applib/diagnostics.jar"/>
../applib/concurrent.jar"/>
../applib/collections.jar"/>
../applib/atg.jar"/>
../applib/lesson.jar"/>
../applib/nls_charset12.jar"/>
../applib/oamMaintMode.jar"/>
../applib/part.jar"/>
../applib/req.jar"/>
../applib/svc.jar"/>
Then we need change server.xml to change our adf to new version like below
<shared-library name="adf.oracle.domain" version="10.1.3.1" library-compatible="true">
<code-source path="/u01/app/oracle/product/oas_1/BC4J/lib"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/commons-cli-1.0.jar"/>
<!-- <code-source path="/u01/app/oracle/product/oas_1/mds/lib/concurrent.jar"/> -->
<!-- <code-source path="/u01/app/oracle/product/oas_1/mds/lib/mdsrt.jar"/> -->
<code-source path="/u01/app/oracle/product/oas_1/jlib/share.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/regexp.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/xmlef.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adfmtl.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adfui.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adf-connections.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/dc-adapters.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/ord/jlib/ordim.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/ord/jlib/ordhttp.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/ojmisc.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/jdev-cm.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/lib/xsqlserializers.jar"/>
<code-source path="../applib/mdsrt.jar"/>
<code-source path="../applib/fwk.jar"/>
<code-source path="../applib/fwkcabo.jar"/>
<code-source path="../applib/fwkjbo.jar"/>
<code-source path="../applib/diagnostics.jar"/>
<code-source path="../applib/concurrent.jar"/>
<code-source path="../applib/collections.jar"/>
<code-source path="../applib/atg.jar"/>
<code-source path="../applib/lesson.jar"/>
<code-source path="../applib/nls_charset12.jar"/>
<code-source path="../applib/oamMaintMode.jar"/>
<code-source path="../applib/part.jar"/>
<code-source path="../applib/req.jar"/>
<code-source path="../applib/svc.jar"/>
<code-source path="../applib/uix2.jar"/>
<code-source path="../applib/uix2-install.jar"/>
<code-source path="../applib/wsp.jar"/>
<import-shared-library name="oracle.xml"/>
<import-shared-library name="oracle.jdbc"/>
<import-shared-library name="oracle.gdk"/>
<import-shared-library name="oracle.cache"/>
<import-shared-library name="oracle.dms"/>
<import-shared-library name="oracle.sqlj"/>
<import-shared-library name="oracle.toplink"/>
<import-shared-library name="oracle.ws.core"/>
<import-shared-library name="oracle.ws.client"/>
<import-shared-library name="oracle.xml.security"/>
<import-shared-library name="oracle.ws.security"/>
<import-shared-library name="oracle.ws.reliability"/>
<import-shared-library name="oracle.jwsdl"/>
<import-shared-library name="oracle.http.client"/>
<import-shared-library name="oracle.expression-evaluator"/>
</shared-library>
<shared-library name="adf.generic.domain" version="10.1.3.1" library-compatible="true">
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/bc4jdomgnrc.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/lib"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/commons-cli-1.0.jar"/>
<!-- <code-source path="/u01/app/oracle/product/oas_1/mds/lib/concurrent.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/mds/lib/mdsrt.jar"/> -->
<code-source path="/u01/app/oracle/product/oas_1/jlib/share.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/regexp.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/xmlef.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adfmtl.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adfui.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/adf-connections.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/BC4J/jlib/dc-adapters.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/ord/jlib/ordim.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/ord/jlib/ordhttp.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/ojmisc.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/jlib/jdev-cm.jar"/>
<code-source path="/u01/app/oracle/product/oas_1/lib/xsqlserializers.jar"/>
<code-source path="../applib/mdsrt.jar"/>
<code-source path="../applib/fwk.jar"/>
<code-source path="../applib/fwkcabo.jar"/>
<code-source path="../applib/fwkjbo.jar"/>
<code-source path="../applib/diagnostics.jar"/>
<code-source path="../applib/concurrent.jar"/>
<code-source path="../applib/collections.jar"/>
<code-source path="../applib/atg.jar"/>
<code-source path="../applib/lesson.jar"/>
<code-source path="../applib/nls_charset12.jar"/>
<code-source path="../applib/oamMaintMode.jar"/>
<code-source path="../applib/part.jar"/>
<code-source path="../applib/req.jar"/>
<code-source path="../applib/svc.jar"/>
<code-source path="../applib/uix2.jar"/>
<code-source path="../applib/uix2-install.jar"/>
<code-source path="../applib/wsp.jar"/>
<import-shared-library name="oracle.xml"/>
<import-shared-library name="oracle.jdbc"/>
<import-shared-library name="oracle.gdk"/>
<import-shared-library name="oracle.cache"/>
<import-shared-library name="oracle.dms"/>
<import-shared-library name="oracle.sqlj"/>
<import-shared-library name="oracle.toplink"/>
<import-shared-library name="oracle.ws.core"/>
<import-shared-library name="oracle.ws.client"/>
<import-shared-library name="oracle.xml.security"/>
<import-shared-library name="oracle.ws.security"/>
<import-shared-library name="oracle.ws.reliability"/>
<import-shared-library name="oracle.jwsdl"/>
<import-shared-library name="oracle.http.client"/>
<import-shared-library name="oracle.expression-evaluator"/>
</shared-library>
We need comment out the path for concurrent.jar and mdsrt.jar for existing setup and add new path.
Please reach out to me in case in help required on this.
Monday, 2 July 2012
How to get count the number of query results without returning them in Hibernate
You can count the number of query results without returning them in Hibernate:
( (Integer) session.createQuery("select count(*) from ....").iterate().next() ).intValue()
Location:
Bangalore, Karnataka, India
Friday, 15 June 2012
Html 5 LocalStorage
localStorage
is also called Web Storage or DOM storage. It is a database that can store only key-value pairs, and the value data-type should always be a string. At first, this might seem a serious limitation, but using along with JavaScript arrays and JSON we can achieve quite a bit. The good news is that this feature is supported in the latest versions of all browsers, both on desktop and mobile environments (Android and iOS). Also, the developer gets a huge 5 MB of storage per domain.
localStorage support on browsers/platforms
This table lists the minimum version of each browser required to support localStorage:
IE | Firefox | Safari | Chrome | Opera | iPhone | Android |
8.0+ | 3.5+ | 4.0+ | 4.0+ | 10.5+ | 2.0+ | 2.0+ |
Operations on localStorage
The methods of
localStorage
include setItem()
, getItem()
, removeItem()
and clear()
. Here is sample code to add a record to localStorage
using setItem()
:// max limit reached exception try { localStorage.setItem(itemId, "Sample Value" ); } catch (e) { if (e == QUOTA_EXCEEDED_ERR) { alert( 'Quota exceeded!' ); } } |
We will use
getItem()
and removeItem()
in the Web app that we will develop. Note thatlocalStorage.clear()
removes all entries from the database, so use it with caution!
Subscribe to:
Posts (Atom)