<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Free practice test , mock test, driving test, interview questions &#187; java</title>
	<atom:link href="http://www.skill-guru.com/blog/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.skill-guru.com/blog</link>
	<description>Find free mock and practice test, create and sell tests</description>
	<lastBuildDate>Thu, 29 Jul 2010 14:16:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Prototype scope in Spring beans</title>
		<link>http://www.skill-guru.com/blog/2010/07/29/prototype-scope-in-spring-beans/</link>
		<comments>http://www.skill-guru.com/blog/2010/07/29/prototype-scope-in-spring-beans/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 14:16:30 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2494</guid>
		<description><![CDATA[When you specify a bean as prototype in xml file or through annotation
&#60;bean
id=&#8221;myBeanInstance&#8221;
class=&#8221;com.xyx.PrototypeBeanExample&#8221;
scope=&#8221;prototype&#8221;
autowire=&#8221;byName&#8221;&#62;
&#60;/bean&#62;
it means that every time a request for this bean is made, a new instance is created. If you want to see the illustration
Prototype bean in Spring
Prototype is meant for beans which hold some state.
The  bean lifecycle also changes in prototype bean. From [...]]]></description>
			<content:encoded><![CDATA[<p>When you specify a bean as <strong>prototype</strong> in xml file or through annotation</p>
<p>&lt;bean<br />
id=&#8221;myBeanInstance&#8221;<br />
class=&#8221;com.xyx.PrototypeBeanExample&#8221;<br />
<strong>scope=&#8221;prototype&#8221;</strong><br />
autowire=&#8221;byName&#8221;&gt;</p>
<p>&lt;/bean&gt;</p>
<p>it means that every time a request for this bean is made, <strong>a new instance</strong> is created. If you want to see the illustration</p>
<p><a href="http://static.springsource.org/spring/docs/2.0.x/reference/beans.html#beans-factory-scopes-prototype">Prototype bean in Spring</a></p>
<p>Prototype is meant for beans which hold some state.</p>
<p>The  bean lifecycle also changes in prototype bean. From Spring&#8217;s doc</p>
<blockquote><p>Spring does not manage the complete lifecycle of a prototype bean: the 			container instantiates, configures, decorates and otherwise assembles a 			prototype object, hands it to the client and then has no further knowledge 			of that prototype instance</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/07/29/prototype-scope-in-spring-beans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JDBC performance tuning with fetch size</title>
		<link>http://www.skill-guru.com/blog/2010/07/25/jdbc-performance-tuning-with-fetch-size/</link>
		<comments>http://www.skill-guru.com/blog/2010/07/25/jdbc-performance-tuning-with-fetch-size/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 14:46:33 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[oracle 11g]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2485</guid>
		<description><![CDATA[Problem: For a Oracle (backend) – Java (frontend) system, a query  returning about 500 K rows was running very slow and is taking about 45 mins.  Oracle database is hosted on server (A), has a separate application server (B), and client can access database from client machine (C), using SQLPLUS.  Query is running slow from [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem: </strong>For a Oracle (backend) – Java (frontend) system, a query  returning about 500 K rows was running very slow and is taking about 45 mins.  Oracle database is hosted on server (A), has a separate application server (B), and client can access database from client machine (C), using SQLPLUS.  Query is running slow from the clients machine (C) and from the java front end (B).</p>
<p><strong>Basic Checks on dbase: </strong></p>
<p>Make sure to check following with respects to the tables / database in question:</p>
<ul>
<li>Latest Database statistics exists for the tables in question.</li>
<li>Indexes</li>
<li>Degree of Parallelism at Table Level:</li>
<li>Optimizer mode</li>
</ul>
<p>Database configuration parameters  &#8211; sga_max_size,  pga_aggregate_target , memory_target, processes<span id="more-2485"></span></p>
<p><strong>Solutions tried</strong></p>
<ul>
<li>Multiple tests were performed, taken explain plan and auto trace, which showed that query is taking time in SQL Net and it has higher waits on this layer.</li>
<li>When we run query on the server hosting oracle (A) it is much faster as compare to running from the clients machine(C).</li>
<li>Use of optimizer hints and parallelism is not helping any speed-up in the query.</li>
<li>Changes in the database configuration parameters and tuning SQL Net does not help.</li>
</ul>
<p><strong>Resolution</strong></p>
<ul>
<li>From the clients machine, using SQLPLUS – Changed the “ARRAYSIZE” parameter to 5000 (from default 15) – This reduces the query time to about 1 min from 45 min.</li>
<li>For Java based front end – changed the “setdefaultrowfetch” to 5000 and query time is reduced to ~35s.</li>
</ul>
<p><strong>Understanding the issue</strong></p>
<p>JDBC drivers’ default fetch size is 10. In normal JDBC programming if you want to retrieve 100 rows, it requires 10 network round trips between your application and database server to transfer all data. Definitely this will impact your application response time. The reason is JDBC drivers are designed to fetch small number of rows from database to avoid any out of memory issues.</p>
<p><strong>Important</strong> : Do not make fetch size too big. The fetch size should be based on your JVM heap memory setting. Too large a fetch size will lead to out of memory issues on application server, esp if you are on hosted environment.</p>
<p>Here is <a href="http://www.idevelopment.info/data/Programming/java/jdbc/FetchSize.java">sample code</a> to explain fetch size implication</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/07/25/jdbc-performance-tuning-with-fetch-size/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Integrating hibernate search with a Spring and JPA Application</title>
		<link>http://www.skill-guru.com/blog/2010/07/19/integrting-hibernate-search-with-a-spring-and-jpa-application/</link>
		<comments>http://www.skill-guru.com/blog/2010/07/19/integrting-hibernate-search-with-a-spring-and-jpa-application/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 15:51:41 +0000</pubDate>
		<dc:creator>smitha</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[hibernate search]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2421</guid>
		<description><![CDATA[In this post we will talk about how to integrate hibernate Search into your existing Spring, JPA and Hibernate application and some of the challenges we faced.
We  have a web application using Hibernate (with JPA ) and Spring. This application relies on Spring for transaction, bean initialization / injection etc. EntityManager, transaction are configured in [...]]]></description>
			<content:encoded><![CDATA[<p>In this post we will talk about how to integrate hibernate Search into your existing Spring, JPA and Hibernate application and some of the challenges we faced.</p>
<p>We  have a web application using Hibernate (with JPA ) and Spring. This application relies on Spring for transaction, bean initialization / injection etc. EntityManager, transaction are configured in application.xml file. When integrating Hibernate search in such an application one might face problems. In this post I am sharing some problems I faced during integration and the solution I found.</p>
<p>entitymanager configuration in my application.xml</p>
<p>Spring configuration:<br />
&lt;bean id=&#8221;propertyConfigurer&#8221;&gt;<br />
&lt;property name=&#8221;location&#8221; value=&#8221;classpath:myproperties.properties&#8221;/&gt;<br />
&lt;/bean&gt;</p>
<p><span id="more-2421"></span><br />
&lt;bean id=&#8221;dataSource&#8221; destroy-method=&#8221;close&#8221;&gt;<br />
&lt;property name=&#8221;driverClass&#8221; value=&#8221;${db.driverClass}&#8221;/&gt;<br />
&lt;property name=&#8221;jdbcUrl&#8221; value=&#8221;${db.url}&#8221;/&gt;<br />
&lt;property name=&#8221;user&#8221; value=&#8221;${db.username}&#8221;/&gt;<br />
&lt;property name=&#8221;password&#8221; value=&#8221;${db.password}&#8221;/&gt;<br />
&lt;property name=&#8221;minPoolSize&#8221; value=&#8221;2&#8243;/&gt;<br />
&lt;property name=&#8221;maxPoolSize&#8221; value=&#8221;8&#8243;/&gt;<br />
&lt;property name=&#8221;breakAfterAcquireFailure&#8221; value=&#8221;false&#8221;/&gt;<br />
&lt;property name=&#8221;acquireRetryAttempts&#8221; value=&#8221;3&#8243;/&gt;<br />
&lt;!&#8211; property name=&#8221;idleConnectionTestPeriod&#8221; value=&#8221;300&#8243; &#8211;&gt;<br />
&lt;property name=&#8221;testConnectionOnCheckout&#8221; value=&#8221;true&#8221;/&gt;<br />
&lt;/bean&gt;</p>
<p>&lt;bean id=&#8221;entityManager&#8221;<br />
p:dataSource-ref=&#8221;dataSource&#8221;&gt;<br />
&lt;property name=&#8221;persistenceUnitName&#8221; value=&#8221;defaultManager&#8221; /&gt;<br />
&lt;property name=&#8221;jpaVendorAdapter&#8221;&gt;<br />
&lt;bean&gt;<br />
&lt;property name=&#8221;database&#8221; value=&#8221;${jpa.database}&#8221;/&gt;<br />
&lt;property name=&#8221;showSql&#8221; value=&#8221;${jpa.showSql}&#8221;/&gt;<br />
&lt;/bean&gt;<br />
&lt;/property&gt;<br />
&lt;/bean&gt;</p>
<p>&lt;bean id=&#8221;transactionManager&#8221;<br />
p:entityManagerFactory-ref=&#8221;entityManager&#8221;/&gt;</p>
<p>In the base DAO, I have  entityManager  as class level variable, value to which will be injected by spring:</p>
<p>@PersistenceContext(unitName = &#8220;defaultManager&#8221;)<br />
private EntityManager entityManager;<br />
For Hibernate search we need FullTextEntityManager. This instance of FullTextEntityManager  will be created using entityManager as below:<br />
fullTextEntityManager = Search.getFullTextEntityManager(entityManager);</p>
<p>To make fullTextEntityManager available for search in the DAO class , I creates a class level variable fullTextEntityManager and  initialized this in @postConstruct method (after entityManager injection) as below.<br />
@PersistenceContext(unitName = &#8220;defaultManager&#8221;)<br />
private EntityManager entityManager;</p>
<p>FullTextEntityManager fullTextEntityManager;</p>
<p>public abstractDAO(){<br />
super();</p>
<p>@PostConstruct<br />
public void setPersistenceUnit(){<br />
super.setUnit(entityManager);<br />
fullTextEntityManager = Search.getFullTextEntityManager(entityManager);</p>
<p>}</p>
<p>public FullTextEntityManager getFullTextEntityManager(){<br />
return fullTextEntityManager;<br />
}<br />
But this approach gave me<br />
org.hibernate.SessionException: Session is closed!<br />
Exception whenever I tried to search.</p>
<p>My initial action was to look into index directory to see if they are being created. It looked perfectly ok there.</p>
<p><em>The problem was, search operation was not getting transaction while searching. The spring was not injecting transaction into a fullTextEntityManager created from entityManager</em>.</p>
<p>For a try I introduced EXTENDED persistence context as below:<br />
@PersistenceContext(unitName = &#8220;defaultManager&#8221;,type=PersistenceContextType.EXTENDED)<br />
private EntityManager entityManager;</p>
<p>and search started working!! But this gave me other problems. Any changes to the entity bean got saved into DB without even committing!!!! I had to revert this change.</p>
<p>My second approach to solve this was to configure fullTextEntirtyManager as Spring bean (as entityManager was configured) so that it can get the transaction.<br />
I couldn’t do it properly as I found no spring’s implementation for fullTextEntirtyManager bean configuration.</p>
<p>After a lot of tries and searching, just changing my DAO code solved this. Instead of making FullTextEntityManager a class level variable, I instatiated it from entityManager whenever I wanted to search. Something like below:</p>
<p>@PersistenceContext(unitName = &#8220;defaultManager&#8221;)<br />
private EntityManager entityManager;</p>
<p>public abstractDAO(){<br />
super();<br />
}</p>
<p>@PostConstruct<br />
public void setPersistenceUnit(){<br />
super.setUnit(entityManager);</p>
<p>}</p>
<p>public FullTextEntityManager getFullTextEntityManager(){<br />
FullTextEntityManager fullTextEntityManager;<br />
fullTextEntityManager = Search.getFullTextEntityManager(entityManager);<br />
return fullTextEntityManager;<br />
}<br />
This solved my problem and the search is working perfectly now.</p>
<p>Going for an interview or want to test your hibernate skills , check out our <a href="../../tag/hibernate">hibernate interview questions</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/07/19/integrting-hibernate-search-with-a-spring-and-jpa-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Want to learn programming in Scala ?</title>
		<link>http://www.skill-guru.com/blog/2010/07/13/want-to-learn-programming-in-scala/</link>
		<comments>http://www.skill-guru.com/blog/2010/07/13/want-to-learn-programming-in-scala/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 20:03:02 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Tech news]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2467</guid>
		<description><![CDATA[Java programmers, interested in learning about Scala ? If you have missed our earlier posts on scala
Twitter has been written in which programming language
Why did twitter dumped Ruby on Rails
For new England residents a chance to learn Scala with Venkat Subramaniam who will be presenting on Programming Scala on Aug 12 2010  at  NEJUG.
Venue : [...]]]></description>
			<content:encoded><![CDATA[<p>Java programmers, interested in learning about Scala ? If you have missed our earlier posts on scala</p>
<p><a href="http://www.skill-guru.com/blog/2009/07/14/twitter-has-been-written-in-which-programming-language/">Twitter has been written in which programming language</a></p>
<p><a href="http://www.skill-guru.com/blog/2010/04/16/why-did-twitter-dumped-ruby-on-rails/">Why did twitter dumped Ruby on Rails</a></p>
<p>For new England residents a chance to learn Scala with <strong>Venkat Subramaniam</strong> who will be presenting on <strong>Programming Scala on </strong>Aug 12 2010  at  NEJUG<strong>.</strong></p>
<p><strong><strong>Venue </strong>:<a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=45+Network+Dr,+Burlington,+Middlesex,+Massachusetts+01803,+United+States&amp;sll=42.499472,-71.230352&amp;sspn=0.007578,0.014355&amp;ie=UTF8&amp;ll=42.499045,-71.231339&amp;spn=0.007578,0.014355&amp;t=h&amp;z=16&amp;iwloc=addr"> Sun Microsystems, Burlington , MA</a><br />
</strong></p>
<p>Dr. Venkat Subramaniam, founder of Agile Developer, Inc., has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia. Venkat helps his clients effectively apply and succeed with agile practices on their software projects, and speaks frequently at international conferences and user groups. He is author of &#8220;.NET Gotchas,&#8221; coauthor of 2007 Jolt Productivity Award winning &#8220;Practices of an Agile Developer,&#8221; author of &#8220;Programming Groovy: Dynamic Productivity for the Java Developer&#8221; and &#8220;Programming Scala: Tackle Multi-Core Complexity on the Java Virtual Machine&#8221; (Pragmatic Bookshelf).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/07/13/want-to-learn-programming-in-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How good are Spring certification practice tests at Skill-Guru ?</title>
		<link>http://www.skill-guru.com/blog/2010/07/07/how-good-are-spring-certification-practice-tests-at-skill-guru/</link>
		<comments>http://www.skill-guru.com/blog/2010/07/07/how-good-are-spring-certification-practice-tests-at-skill-guru/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 02:57:53 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Mock  Exam / Certifications]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2455</guid>
		<description><![CDATA[In our previous posts we had mentioned that Ikoko has added 2 mock test of 50 questions each at Skill-Guru
Spring certification mock test 1
Spring certification mock test 2
These tests are priced at $0.99 each . So how good are the tests ?
Follow this discussion on javaranch to see what real users who have been through [...]]]></description>
			<content:encoded><![CDATA[<p>In our previous posts we had mentioned that Ikoko has added 2 mock test of 50 questions each at <a href="http://www.skill-guru.com">Skill-Guru</a></p>
<p><a href="http://skill-guru.com/test/81/core-spring-3.0-certification-mock">Spring certification mock test 1</a></p>
<p><a href="http://skill-guru.com/test/86/core-spring-3.0-certification-mock-test-2">Spring certification mock test 2</a></p>
<p>These tests are priced at $0.99 each . So how good are the tests ?</p>
<p>Follow this discussion on javaranch to see what real users who have been through Spring certification are saying about the test</p>
<p><a href="http://www.coderanch.com/t/497889/Spring/Failed-Core-Spring-Certification">Failed Core Spring certification</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/07/07/how-good-are-spring-certification-practice-tests-at-skill-guru/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Practice test for Spring Certification</title>
		<link>http://www.skill-guru.com/blog/2010/06/24/practice-test-for-spring-certification/</link>
		<comments>http://www.skill-guru.com/blog/2010/06/24/practice-test-for-spring-certification/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 03:11:30 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Mock  Exam / Certifications]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[practice-test]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2425</guid>
		<description><![CDATA[ikoko had added 2nd mock practice test for Spring Certification . He had added first test Core Spring 3.0 Certification Mock and has received very good response from users. The users have found value in the $0.99 test .
We hope that you like his Core Spring 3.0 Certification Mock Test 2 . This test covers [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.skill-guru.com/guru/ikoko">ikoko</a> had added 2nd<a href="http://www.skill-guru.com/test/86/core-spring-3.0-certification-mock-test-2"> mock practice test for Spring Certification </a>. He had added first test <a href="http://www.skill-guru.com/test/81/core-spring-3.0-certification-mock">Core Spring 3.0 Certification Mock</a> and has received very good response from users. The users have found value in the $0.99 test .</p>
<p>We hope that you like his <a href="http://www.skill-guru.com/test/86/core-spring-3.0-certification-mock-test-2">Core Spring 3.0 Certification Mock Test 2</a> . This test covers topics on container, Test, AOP, SpEL, Database, JMS, JMX, Web, MVC, Remoting etc</p>
<p>Looking for your feedback and inputs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/06/24/practice-test-for-spring-certification/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Read Write into excel through Java by JExcel</title>
		<link>http://www.skill-guru.com/blog/2010/06/23/read-write-into-excel-through-java-by-jexcel/</link>
		<comments>http://www.skill-guru.com/blog/2010/06/23/read-write-into-excel-through-java-by-jexcel/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 17:55:36 +0000</pubDate>
		<dc:creator>fanand</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jexcel]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2407</guid>
		<description><![CDATA[JExcelApi allows Java developers to read Excel spreadsheets and to generate Excel spreadsheets dynamically. In addition, it contains a mechanism which allows java applications to read in a spreadsheet, modify some cells and write out the new spreadsheet.
This API allows non Windows operating systems to run pure Java applications which can both process and deliver [...]]]></description>
			<content:encoded><![CDATA[<p>JExcelApi allows Java developers to read Excel spreadsheets and to generate Excel spreadsheets dynamically. In addition, it contains a mechanism which allows java applications to read in a spreadsheet, modify some cells and write out the new spreadsheet.</p>
<p>This API allows non Windows operating systems to run pure Java applications which can both process and deliver Excel spreadsheets. Because it is Java, this API may be invoked from within a servlet, thus giving access to Excel functionality over internet and intranet web applications.</p>
<p>Download JExcelApi JAR files from</p>
<p>http://jexcelapi.sourceforge.net/</p>
<p>Reading Spreadsheets</p>
<p>Here is the sample program which uses the javaexcel <span id="more-2407"></span></p>
<p>Program to read the Excel.</p>
<p><strong>package</strong> com;</p>
<p><strong>import</strong> java.io.File;</p>
<p><strong>import</strong> java.io.IOException;</p>
<p><strong>import</strong> jxl.*;</p>
<p><strong>import</strong> jxl.read.biff.BiffException;</p>
<p><strong>public</strong> <strong>class</strong> JavaExcel {</p>
<p><strong>public</strong> <strong>static</strong> <strong>void</strong> main(String args[]) {</p>
<p>readExcel();</p>
<p>}</p>
<p><strong>public</strong> <strong>static</strong> <strong>void</strong> readExcel() {</p>
<p><strong>try</strong> {</p>
<p>Workbook workbook = Workbook.<em>getWorkbook</em>(<strong>new</strong> File(&#8220;Res.xls&#8221;));</p>
<p>Sheet sheet = workbook.getSheet(0);</p>
<p>Cell a1 = sheet.getCell(1, 13);</p>
<p>String stringa1 = a1.getContents();</p>
<p>System.<em>out</em>.println(stringa1);</p>
<p>workbook.close();</p>
<p>} <strong>catch</strong> (BiffException e) {</p>
<p>e.printStackTrace();</p>
<p>} <strong>catch</strong> (IOException e) {</p>
<p>e.printStackTrace();</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>Input excel file (place it in the classpath):</p>
<p> <a href='http://www.skill-guru.com/blog/wp-content/uploads/2010/06/Res.xls'><img class="size-full wp-image-2408 alignnone" src="http://www.skill-guru.com/blog/wp-content/uploads/2010/06/11.jpg" alt="" width="82" height="80" /></a></p>
<p>Following is the Output of the program.</p>
<p>Deepak</p>
<p>Dinesh</p>
<p>Fundamentals</p>
<p>JExcelApi can read an Excel spreadsheet from a file stored on the local file system or from some input stream. The first step when reading a spreadsheet from a file or input stream is to create a Workbook. The code fragment below illustrates creating a workbook from a file on the local file system.</p>
<p>Workbook workbook = Workbook.getWorkbook(new File(&#8220;myfile.xls&#8221;));</p>
<p>(NOTE: when creating a spreadsheet from a ServletInputStream you must remove the HTTP header information before creating the Workbook object.)</p>
<p>Once you have accessed the workbook, you can use this to access the individual sheets. These are zero indexed &#8211; the first sheet being 0, the second sheet being 1, and so on. (You can also use the API to retrieve a sheet by name).</p>
<p>Sheet sheet = workbook.getSheet(0);</p>
<p>Once you have a sheet, you can then start accessing the cells. You can retrieve the cell&#8217;s contents as a string by using the convenience method getContents(). In the example code below, A1 is a text cell, B2 is numerical value and C2 is a date. The contents of these cells may be accessed as follows</p>
<p>Cell a1 = sheet.getCell(0,0);<br />
Cell b2 = sheet.getCell(1,1);<br />
Cell c2 = sheet.getCell(2,1);</p>
<p>String stringa1 = a1.getContents();<br />
String stringb2 = b2.getContents();<br />
String stringc2 = c2.getContents();</p>
<p>// Finished &#8211; close the workbook and free up memory<br />
workbook.close();</p>
<p>Writing Spreadsheets</p>
<p>Sample program to write contents in the Excel.</p>
<p><strong> </strong></p>
<p><strong>package</strong> com;</p>
<p><strong>import</strong> java.io.File;</p>
<p><strong>import</strong> java.io.IOException;</p>
<p><strong>import</strong> jxl.*;</p>
<p><strong>import</strong> jxl.write.Label;</p>
<p><strong>import</strong> jxl.write.Number;</p>
<p><strong>import</strong> jxl.write.WritableSheet;</p>
<p><strong>import</strong> jxl.write.WritableWorkbook;</p>
<p><strong>import</strong> jxl.write.WriteException;</p>
<p><strong>import</strong> jxl.write.biff.RowsExceededException;</p>
<p><strong>public</strong> <strong>class</strong> JavaExcelWr {</p>
<p><strong>public</strong> <strong>static</strong> <strong>void</strong> main(String args[]) {</p>
<p><em>writeExcel</em>();</p>
<p>}</p>
<p><strong>public</strong> <strong>static</strong> <strong>void</strong> writeExcel() {</p>
<p><strong>try</strong> {</p>
<p>WritableWorkbook wrworkbook = Workbook.<em>createWorkbook</em>(<strong>new</strong> File(</p>
<p>&#8220;output.xls&#8221;));</p>
<p>WritableSheet wrsheet = wrworkbook.createSheet(&#8220;First Sheet&#8221;, 0);</p>
<p>Label label = <strong>new</strong> Label(0, 0, &#8220;label record 1&#8243;);</p>
<p>wrsheet.addCell(label);</p>
<p>label = <strong>new</strong> Label(0, 1, &#8220;label record 2&#8243;);</p>
<p>wrsheet.addCell(label);</p>
<p>label = <strong>new</strong> Label(0, 2, &#8220;label record 3&#8243;);</p>
<p>wrsheet.addCell(label);</p>
<p>label = <strong>new</strong> Label(0, 3, &#8220;label record 4&#8243;);</p>
<p>wrsheet.addCell(label);</p>
<p>Number number = <strong>new</strong> Number(3, 4, 3.1459);</p>
<p>wrsheet.addCell(number);</p>
<p>wrworkbook.write();</p>
<p>wrworkbook.close();</p>
<p>} <strong>catch</strong> (IOException e) {</p>
<p>e.printStackTrace();</p>
<p>} <strong>catch</strong> (RowsExceededException e) {</p>
<p>e.printStackTrace();</p>
<p>} <strong>catch</strong> (WriteException e) {</p>
<p>e.printStackTrace();</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>Following is the Output of the program.</p>
<p> <a href='http://www.skill-guru.com/blog/wp-content/uploads/2010/06/Output.xls'><img class="size-full wp-image-2409 alignnone" src="http://www.skill-guru.com/blog/wp-content/uploads/2010/06/13.jpg" alt="" width="114" height="78" /></a></p>
<p>Fundamentals</p>
<p>Similarly to reading a spreadsheet, the first step is to create a writable workbook using the factory method on the Workbook class.</p>
<p>WritableWorkbook workbook = Workbook.createWorkbook(new File(&#8220;output.xls&#8221;));</p>
<p>This creates the workbook object. The generated file will be located in the current working directory and will be called &#8220;output.xls&#8221;. The API can also be used to send the workbook directly to an output stream eg. from a web server to the user&#8217;s browser. If the HTTP header is set correctly, then this will launch Excel and display the generated spreadsheet.</p>
<p>The next stage is to create sheets for the workbook. Again, this is a factory method, which takes the name of the sheet and the position it will occupy in the workbook. The code fragment below creates a sheet called &#8220;First Sheet&#8221; at the first position.</p>
<p>WritableSheet sheet = workbook.createSheet(&#8220;First Sheet&#8221;, 0);</p>
<p>Now all that remains is to add the cells into the worksheet. This is simply a matter of instantiating cell objects and adding them to the sheet. The following code fragment puts a label in cell A3, and the number 3.14159 in cell D5.</p>
<p>Label label = new Label(0, 2, &#8220;A label record&#8221;);<br />
sheet.addCell(label);</p>
<p>Number number = new Number(3, 4, 3.1459);<br />
sheet.addCell(number);</p>
<p>There are a couple of points to note here. Firstly, the cell&#8217;s location in the sheet is specified as part of the constructor information. Once created, it is not possible to change a cell&#8217;s location, although the cell&#8217;s contents may be altered.</p>
<p>The other point to note is that the cell&#8217;s location is specified as (column, row). Both are zero indexed integer values &#8211; A1 being represented by (0,0), B1 by (1,0), A2 by (0,1) and so on.</p>
<p>Once you have finished adding sheets and cells to the workbook, you call write() on the workbook, and then close the file. This final step generates the output file (output.xls in this case) which may be read by Excel. If you call close() without calling write() first, a completely empty file will be generated.</p>
<p>// All sheets and cells added. Now write out the workbook<br />
workbook.write();<br />
workbook.close();</p>
<p>Download JAR files from</p>
<p><a href="http://jexcelapi.sourceforge.net/">http://jexcelapi.sourceforge.net/</a></p>
<p>FAQ has details on how to read an Excel File uploaded through a Web browser to a Servlet and also about how to Output an Excel file from a Servlet.</p>
<p>FAQ link is <a href="http://jexcelapi.sourceforge.net/resources/faq/">http://jexcelapi.sourceforge.net/resources/faq/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/06/23/read-write-into-excel-through-java-by-jexcel/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Use of environment variable in Java</title>
		<link>http://www.skill-guru.com/blog/2010/06/20/use-of-environment-variable-in-java/</link>
		<comments>http://www.skill-guru.com/blog/2010/06/20/use-of-environment-variable-in-java/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 14:24:02 +0000</pubDate>
		<dc:creator>fanand</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[environment variables]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2402</guid>
		<description><![CDATA[In this post we will talk about environment variables in java , their role and how to use them in windows and Unix environment.
Reading environment Variables in Java
System environment variable can be used in the java application to set the system related values for ex: application path, database environment etc..,
In standalone application, start the JVM [...]]]></description>
			<content:encoded><![CDATA[<p>In this post we will talk about environment variables in java , their role and how to use them in windows and Unix environment.</p>
<p><strong>Reading environment Variables in Java</strong></p>
<p>System environment variable can be used in the java application to set the system related values for ex: application path, database environment etc..,</p>
<p>In standalone application, start the JVM with the &#8220;-D&#8221; switch to pass properties to the application and read them with the System.getProperty() method.</p>
<p>SET myvar=Hello world</p>
<p>SET myothervar=nothing</p>
<p>java -Dmyvar=&#8221;%myvar%&#8221; -Dmyothervar=&#8221;%myothervar%&#8221; myClass</p>
<p>Then in myClass do the following</p>
<p>String myvar = System.getProperty(&#8220;myvar&#8221;);</p>
<p>String myothervar = System.getProperty(&#8220;myothervar&#8221;);</p>
<p><span id="more-2402"></span></p>
<p><strong>Reading UNIX environment Variables in Java</strong></p>
<p>How the code works:</p>
<p>Create an instance of a java.util.Properties class.</p>
<p>Every Java application has a single Runtime instance, which is an interface with the environment in which the application is running. The current Runtime is obtained using the static method getRuntime() of Runtime class.</p>
<p>Call the exec method of the Runtime object, to execute the given command in a separate process.</p>
<p>After executing, the method returns the handle to a Process class. Get the input stream for the sub process using getInputStream() method.</p>
<p>Load the Properties object with this InputStream.</p>
<p>Now we can read any environment variable form the Properties Object, by using get method.</p>
<p>Lines of Code:</p>
<p>java.util.Properties env = new java.util.Properties();</p>
<p>env.load(Runtime.getRuntime().exec(&#8220;env&#8221;).getInputStream());</p>
<p>String myEnvVar =(String) env.get(&#8220;MY_VAR&#8221;);</p>
<p><strong> </strong></p>
<p><strong>Configuring / Reading the JVM environment variable in IBM WAS Server.</strong></p>
<p>JVM environment variables can be set in the WAS server, and that environment variable can be read from the java program using System.getProperty().</p>
<p>In a real time scenario, database environment variable can be set in the JVM custom properties, and that can be changed depending on which environment the application is deployed.</p>
<p>For ex: for production database environment, value can be set to PROD so that production database related properties file can be read by the application.</p>
<p>Following is the path in the WAS server where we need to set the JVM custom variable and value.</p>
<p><a href="http://www.skill-guru.com/blog/wp-content/uploads/2010/06/1231.jpg"><img class="aligncenter size-full wp-image-2405" src="http://www.skill-guru.com/blog/wp-content/uploads/2010/06/1231.jpg" alt="" width="449" height="34" /></a></p>
<p>Below is the sample snapshot which shows the DB_ENVIRONMENT property name and value settings.</p>
<p><a href="http://www.skill-guru.com/blog/wp-content/uploads/2010/06/12.jpg"><img class="aligncenter size-full wp-image-2404" src="http://www.skill-guru.com/blog/wp-content/uploads/2010/06/12.jpg" alt="" width="468" height="320" /></a></p>
<p>After adding a new value or updating the value, restart the WAS server, so that changes will get reflected in the application.</p>
<p>Code to read the environment setup:</p>
<p>String env = System.getProperty(“DB_ENVIRONMENT”)</p>
<p>So depending on the value of env variable, we can read the properties file for different environment</p>
<p>For ex:</p>
<p>If(“DEVELOPMENT”.equals(env)) {</p>
<p>//Load the development environment related property files.</p>
<p>//Connect to development database.</p>
<p>} else If(“PROD”.equals(env)) {</p>
<p>//Load the production environment related property files.</p>
<p>//Connect to production database.</p>
<p>} If(“UAT”.equals(env)) {</p>
<p>//Load the uat environment related property files.</p>
<p>//Connect to uat database.</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/06/20/use-of-environment-variable-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate Search – Getting Started</title>
		<link>http://www.skill-guru.com/blog/2010/06/15/hibernate-search-%e2%80%93-getting-started/</link>
		<comments>http://www.skill-guru.com/blog/2010/06/15/hibernate-search-%e2%80%93-getting-started/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 18:34:12 +0000</pubDate>
		<dc:creator>smitha</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[hibernate search]]></category>
		<category><![CDATA[Hibernate Tutorials]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2383</guid>
		<description><![CDATA[Once your dynamic site has gone bigger, data in relational database has grown, there is always a need for searching the contents. SQL queries with like &#8216;%&#8230;%&#8217; are useful. But to do multiple columns / table searching, we&#8217;ll need to have big SQL queries with different conditions, ANDed and ORed. Such searching is not realistic [...]]]></description>
			<content:encoded><![CDATA[<p>Once your dynamic site has gone bigger, data in relational database has grown, there is always a need for searching the contents. SQL queries with like &#8216;%&#8230;%&#8217; are useful. But to do multiple columns / table searching, we&#8217;ll need to have big SQL queries with different conditions, ANDed and ORed. Such searching is not realistic and can not be maintained and extended easily.<br />
For Hibernate users, Hibernate search helps searching rows from database. Without writing any complex SQL queries, you can search multiple columns and get related objects from db.</p>
<p>In our site <a href="http://www.skill-guru.com">Skill-Guru</a> , you will notice a search box on the right hand side.  We have enabled the search on few tables and columns initially. Currently it will search for the tests , description and keywords for the input keyword.</p>
<p><span id="more-2383"></span></p>
<p>Hibernate search searches objects from text queries. It uses<strong> Apache Lucene </strong>Indexing technique. It indexes the tables with the help of annotations. Also it does the synchronization of database and index. Following tutorial demonstrates a simple searching example using hibernate search. The application uses JPA way.</p>
<p>Consider any site selling some products. You want to search products by title, description etc. Consider following products table.</p>
<p>create table product(<br />
id int(5) not null auto_increment,<br />
title varchar(100) not null,<br />
description varchar(250) not null,<br />
manufacture_date datetime,<br />
primary key(id));<br />
To start with Hibernate Search , you must have hibernate search downloaded. Download Hibernate search 3.1.1 and Hibernate 3.<br />
Create a java application and add required jars to your build path. <a href="http://www.skill-guru.com/blog/wp-content/uploads/2010/06/jarsUsed.txt" target="_blank">Click here </a>to know exact jars used in this project.</p>
<p>Crate a src/META-INF directory and create a persistence.xml file with following contents (edit it according to your database parameters)</p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;persistence xmlns=&#8221;<a href="http://java.sun.com/xml/ns/persistence">http://java.sun.com/xml/ns/persistence</a>&#8221;<br />
xmlns:xsi=&#8221;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&#8221;<br />
xsi:schemaLocation=&#8221;<a href="http://java.sun.com/xml/ns/persistence">http://java.sun.com/xml/ns/persistence</a><br />
<a href="http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd</a>&#8221; version=&#8221;1.0&#8243;&gt;</p>
<p>&lt;persistence-unit name=&#8221;defaultManager&#8221;<br />
transaction-type=&#8221;RESOURCE_LOCAL&#8221;&gt;<br />
&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;<br />
&lt;properties&gt;<br />
&lt;property name=&#8221;hibernate.connection.driver_class&#8221;<br />
value=&#8221;com.mysql.jdbc.Driver&#8221; /&gt;<br />
&lt;property name=&#8221;hibernate.connection.url&#8221;<br />
value=&#8221;jdbc:mysql://localhost:3306/hibernatetest&#8221; &gt;&lt;/property&gt;<br />
&lt;property name=&#8221;hibernate.connection.username&#8221; value=&#8221;root&#8221; /&gt;<br />
&lt;property name=&#8221;hibernate.connection.password&#8221;<br />
value=&#8221;root&#8221; /&gt;<br />
&lt;property name=&#8221;hibernate.show_sql&#8221; value=&#8221;false&#8221; /&gt;</p>
<p>&lt;property name=&#8221;hibernate.search.default.directory_provider&#8221;<br />
value=&#8221;org.hibernate.search.store.FSDirectoryProvider&#8221; /&gt;<br />
&lt;property name=&#8221;hibernate.search.indexing_strategy&#8221; value=&#8221;manual&#8221; /&gt;<br />
&lt;property name=&#8221;hibernate.search.default.indexBase&#8221; value=&#8221;e:\indexes&#8221; /&gt;<br />
&lt;/properties&gt;<br />
&lt;/persistence-unit&gt;<br />
&lt;/persistence&gt;</p></blockquote>
<p>Make sure you have database url, username and password entered properly. Another important factor is the indexBase directory. Hibernate search creates indexes for each table it need to search and those indexes will be saved in this directory.</p>
<p>The properties:<br />
&lt;property name=&#8221;hibernate.search.default.directory_provider&#8221;<br />
value=&#8221;org.hibernate.search.store.FSDirectoryProvider&#8221; /&gt;<br />
&lt;property name=&#8221;hibernate.search.indexing_strategy&#8221; value=&#8221;manual&#8221; /&gt;<br />
&lt;property name=&#8221;hibernate.search.default.indexBase&#8221; value=&#8221;e:\indexes&#8221; /&gt;<br />
are used by Hibernate Search.</p>
<p>Create test.eo package and create a ProductEO class. The ProductEO entity class for products table might look like below:</p>
<p>Create test.eo package and create a ProductEO class. The ProductEO entity class for products table might look like below:</p>
<blockquote><p>package test.eo;</p>
<p>import java.util.Date;</p>
<p>import javax.persistence.Column;<br />
import javax.persistence.GeneratedValue;<br />
import javax.persistence.GenerationType;<br />
import javax.persistence.Id;<br />
import javax.persistence.Entity;<br />
import javax.persistence.Table;</p>
<p>@Entity<br />
@Table(name=”product”)<br />
public class ProductEO {</p>
<p>@Id<br />
@GeneratedValue(strategy = GenerationType.IDENTITY)<br />
@Column(name=”id”)<br />
private Integer id;</p>
<p>@Column(name=”title”)<br />
private String title;</p>
<p>@Column(name=”description”)<br />
private String description;</p>
<p>@Column(name=”manufacture_date”)<br />
private Date manifactureDate;</p>
<p>public Integer getId() {<br />
return id;<br />
}<br />
public void setId(Integer id) {<br />
this.id = id;<br />
}<br />
public String getTitle() {<br />
return title;<br />
}<br />
public void setTitle(String title) {<br />
this.title = title;<br />
}<br />
public String getDescription() {<br />
return description;<br />
}<br />
public void setDescription(String description) {<br />
this.description = description;<br />
}<br />
public Date getManifactureDate() {<br />
return manifactureDate;<br />
}<br />
public void setManifactureDate(Date manifactureDate) {<br />
this.manifactureDate = manifactureDate;<br />
}<br />
}</p></blockquote>
<p>To make this entity to be able to be searched, we need to add some more annotations. Altered Entity class is shown below:</p>
<blockquote><p>package test.eo;</p>
<p>import java.util.Date;</p>
<p>import javax.persistence.Column;<br />
import javax.persistence.Entity;<br />
import javax.persistence.GeneratedValue;<br />
import javax.persistence.GenerationType;<br />
import javax.persistence.Id;<br />
import javax.persistence.Table;</p>
<p>import org.hibernate.search.annotations.DocumentId;<br />
import org.hibernate.search.annotations.Field;<br />
import org.hibernate.search.annotations.Index;<br />
import org.hibernate.search.annotations.Indexed;<br />
import org.hibernate.search.annotations.Store;</p>
<p>@Entity<br />
@Table(name=”product”)<br />
@Indexed<br />
public class ProductEO {</p>
<p>@DocumentId<br />
@Id<br />
@GeneratedValue(strategy = GenerationType.IDENTITY)<br />
@Column(name=”id”)<br />
private Integer id;</p>
<p>@Field(index=Index.TOKENIZED, store=Store.NO)<br />
@Column(name=”title”)<br />
private String title;</p>
<p>@Field(index=Index.TOKENIZED, store=Store.NO)<br />
@Column(name=”description”)<br />
private String description;</p>
<p>@Column(name=”manufacture_date”)<br />
private Date manifactureDate;</p>
<p>public Integer getId() {<br />
return id;<br />
}<br />
public void setId(Integer id) {<br />
this.id = id;<br />
}<br />
public String getTitle() {<br />
return title;<br />
}<br />
public void setTitle(String title) {<br />
this.title = title;<br />
}<br />
public String getDescription() {<br />
return description;<br />
}<br />
public void setDescription(String description) {<br />
this.description = description;<br />
}<br />
public Date getManifactureDate() {<br />
return manifactureDate;<br />
}<br />
public void setManifactureDate(Date manifactureDate) {<br />
this.manifactureDate = manifactureDate;<br />
}<br />
}</p></blockquote>
<p>We added following:</p>
<p>1. @Indexed annotation to Class<br />
2. @DocumentId annotation on the primary key. Hibernate Search needs to store an id in the index to ensure index uniqueness for a given entity. This annotation marks that unique property. In most of the cases this will be the primary key.<br />
3. @Field(index=Index.TOKENIZED, store=Store.NO) annotation on the fields, which need to be matched while searching. The parameter<br />
index=Index.TOKENIZED will ensure that the text will be tokenized (in short words will be identified) using the default Lucene analyzer. store=Store.NO is to  ensures that the actual data will not be stored in the index.</p>
<p>Now define a HibernateEntitymanagerHelper class in package test.services to initialize persistence context as below:</p>
<blockquote><p>package test.services;<br />
import javax.persistence.*;<br />
public class HibernateEntitymanagerHelper {<br />
private static EntityManagerFactory emf;<br />
static{<br />
try{<br />
emf = Persistence.createEntityManagerFactory(“defaultManager”);<br />
}catch(Throwable tw){<br />
throw new ExceptionInInitializerError(tw);<br />
}<br />
}<br />
public static EntityManagerFactory getEntityManagerFactory() {<br />
return emf;<br />
}<br />
public static void shutdown() {<br />
emf.close();<br />
}<br />
}</p></blockquote>
<p>Create following AddProducts  class in test.services package and add some data into the table:</p>
<blockquote><p>package test.services;</p>
<p>import javax.persistence.EntityManager;<br />
import test.eo.*;<br />
import java.util.Date;</p>
<p>public class AddProducts {<br />
public static void main(String[] args) {<br />
try{<br />
EntityManager em = HibernateEntitymanagerHelper.getEntityManagerFactory().createEntityManager();<br />
em.getTransaction().begin();<br />
ProductEO prodEO = new ProductEO();<br />
prodEO.setTitle(“Mike”);<br />
prodEO.setDescription(“XXX company Mike”);<br />
prodEO.setManifactureDate(new Date());<br />
em.persist(prodEO);</p>
<p>prodEO = new ProductEO();<br />
prodEO.setTitle(“Phone”);<br />
prodEO.setDescription(“YYY company Phone”);<br />
prodEO.setManifactureDate(new Date());<br />
em.persist(prodEO);</p>
<p>prodEO = new ProductEO();<br />
prodEO.setTitle(“Microphone”);<br />
prodEO.setDescription(“YYY company Microphone”);<br />
prodEO.setManifactureDate(new Date());</p>
<p>em.persist(prodEO);<br />
em.getTransaction().commit();</p>
<p>}catch(Exception e){<br />
e.printStackTrace();<br />
}<br />
}<br />
}</p></blockquote>
<p>Now, this is time to test. For Hibernate search to work you have to trigger an initial Indexing to populate the Lucene index with the data already present in your database.  Following code creates indexes and then does searching.</p>
<blockquote><p>package test.services;</p>
<p>import java.util.List;</p>
<p>import javax.persistence.EntityManager;<br />
import test.eo.*;<br />
import java.util.Date;<br />
import org.apache.lucene.analysis.standard.StandardAnalyzer;<br />
import org.apache.lucene.queryParser.MultiFieldQueryParser;<br />
import org.hibernate.search.jpa.FullTextEntityManager;<br />
import org.hibernate.search.jpa.Search;</p>
<p>public class ProductService {</p>
<p>/**<br />
* @param args<br />
*/<br />
public static void main(String[] args) {</p>
<p>try{<br />
EntityManager em = HibernateEntitymanagerHelper.getEntityManagerFactory().createEntityManager();<br />
FullTextEntityManager fullTextEntityManager =  Search.getFullTextEntityManager(em);</p>
<p>fullTextEntityManager.getTransaction().begin();</p>
<p>List&lt;ProductEO&gt; products = em.createQuery(“select product  from ProductEO as  product”).getResultList();<br />
for (ProductEO product : products) {<br />
fullTextEntityManager.index(product);<br />
System.out.println(“Product”+product.getTitle());<br />
}</p>
<p>String[] fields = new String[]{“title”, “description”};<br />
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());<br />
// parser.setDefaultOperator(QueryParser.AND_OPERATOR);</p>
<p>/*<br />
* Search only by lowercase<br />
*/<br />
org.apache.lucene.search.Query query = parser.parse( “phone” );<br />
// wrap Lucene query in a javax.persistence.Query<br />
javax.persistence.Query persistenceQuery =  fullTextEntityManager.createFullTextQuery(query, ProductEO.class);<br />
// execute search<br />
List&lt;ProductEO&gt; result = persistenceQuery.getResultList();<br />
System.out.println(“result ::”+result);<br />
for (ProductEO product : result) {<br />
System.out.println(“product ::”+product.getTitle());<br />
}</p>
<p>fullTextEntityManager.getTransaction().commit();<br />
em.close();<br />
HibernateEntitymanagerHelper.shutdown();<br />
}catch(Exception e){<br />
e.printStackTrace();<br />
}</p>
<p>}</p>
<p>}</p>
<p>Going for an interview or want to test your hibernate skills , check out our <a href="http://www.skill-guru.com/tag/hibernate">hibernate interview questions</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/06/15/hibernate-search-%e2%80%93-getting-started/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Spring certification practice test</title>
		<link>http://www.skill-guru.com/blog/2010/06/08/spring-certification-practice-test/</link>
		<comments>http://www.skill-guru.com/blog/2010/06/08/spring-certification-practice-test/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 01:12:01 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Mock  Exam / Certifications]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[practice-test]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2356</guid>
		<description><![CDATA[DanielButcher is a Sun J2EE architect who has sat 5 Sun certifications, Core Spring and PRINCE2. He has  over ten years enterprise level Java experience and over 5 years Spring experience.
He has created Core Spring Certification practice test at Skill-Guru.  It is a 50 questions test priced at $0.99 and 10 questions are free. An [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.skill-guru.com/guru/danielbutcher">DanielButcher </a>is a Sun J2EE architect who has sat 5 Sun certifications, Core Spring and PRINCE2. He has  over ten years enterprise level Java experience and over 5 years Spring experience.</p>
<p>He has created <a href="http://www.skill-guru.com/test/81/core-spring-certification">Core Spring Certification practice test </a>at <a href="http://www.skill-guru.com">Skill-Guru</a>.  It is a 50 questions test priced at $0.99 and 10 questions are free. An absolute bargain !!</p>
<p>Take the <a href="http://www.skill-guru.com/test/81/core-spring-certification">Spring certification practice test</a> before you take that Spring certification.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/06/08/spring-certification-practice-test/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
