Thought about ideas

Have you ever had an idea about creating a web site and of course being pretty much excited about it so you start presenting it to some friends ?

But …

Well … yes your friends aren’t as much excited as you are !

It looks like they are trying to find what is wrong with your idea  !

And that’s pretty much anoying rights ? 😉

Here are some examples of what most of your friends start saying  :

“I think I’ve already seen that somewhere ”

“Did you look if that doesn’t exist yet ?”

“Are you sure someone didn’t already make it yet ?”

“But what is the business model anyway, … I don’t understand … ?”

“Be aware because it can be anoying if one of your user start [replace here with something that should not be done by a user with your web site]”

And you know what ? yes they’re right ! the idea already exists but not exactly the same way your are seeing and planning it to be, yes it’s true that someone could use your web site a misappropiate way !

For the misappropriate use there is nothing to do either way : there will always exist people trying to pervert your idea.

Now for the point about having a real original idea I think that’s impossible. Even if someone has never already make it on the web, the idea was already there : having an idea is not that difficult by the way and I think that even ordinary ideas can be successfull.

About the business model : I don’t think that’s the most important when starting building a web site ! What I mean here is that you should not anticipate how you’re going to win money with your site, but you should let your users take the control I bet that you have much to learn about how they are actually using it over the first place :  this is why even an ordinary idea could have a chance to succeed, letting the user taking control of an idea is the best way to transform an ordinary idea to a great one !

Categories: opinion Tags: ,

Using DAO with ORM

I’m using iBatis in the application I’m currently working on. And since we try to create a well designed code, we are using the DAO design pattern to call the iBatis’s api.

Recently I started using JPA and so I’ve quiclky start creating DAO to put my JPA code in it.

My service layer calls my DAOs and that’s great, but …

When you use JPA or any ORM tools there is many things that will be done out of the scope of your code.

Lets take the OneToMany association for example and say that you have set a transitive persistence.

@Entity
@Table(name="USER")
public class User implements Serializable {
private static final long serialVersionUID = 1L;

@OneToMany (cascade=CascadeType.PERSIST)
private List<span></span> storeCollection;

...

To persist a new user you call the persist method in the UserDAO :

public class UserDAO {

  @PersistenceContext
  private EntityManager em;

  public void save(User user{
    em.persist(user);
  }
}

public class CoreServiceImpl implements CoreService {

  @Autowired
  private UserDAO userDAO;

  public void saveUser() {
    User user = new User();
    user.getStoreCollection().add(new Store());
    userDAO.save(user);
  }
}

Since we have set cascade=CascadeType.PERSIST in our annotation, the new store object will be automatically inserted in database.

This is a great feature but when using it you must be aware that your are going to lose the control of a part of your application code : you should have created a StoreDAO with a save method to explicitly persist Store object.

The way I see DAO is that it’s allow you be loosely coupled with your data access api : you don’t need to know that it’s using iBatis, direct JDBC, etc … and another promise is to potentially allow you to switch from an implementation to another without having to change the code of your service layer.

This is this last promise which is not true any more if you start using the transitive persistence feature given by JPA and many others ORM framework.

Categories: java Tags: ,

Converting XML data to strongly typed AS3 Object

February 18, 2009 Leave a comment

Context / Problem :

The Use of the HttpService gives us the opportunity to retreive XML data from a server.
But … the problem starts when we receive these data : how could we manipulate these data from a strongly typed manner ?
Let’s take an example to illustrate the issue :

The following code retrieves xml data and registers a callback to parse the result :

var httpService:HTTPService = new HTTPService();
httpService.addEventListener(ResultEvent.RESULT, onLoadListResult);
httpService.url="TodoItems.xml";
httpService.resultFormat=HTTPService.RESULT_FORMAT_OBJECT;
httpService.send();

private function onLoadListResult(e:ResultEvent):void {
	var resultList:ArrayCollection = new ArrayCollection();
	for each (var o:ObjectProxy in  ArrayCollection(e.result.List.TodoItemVO)) {
		trace(o.title);
	}
}

The content of TodoItems.xml is the following :

<?xml version="1.0" encoding="utf-8"?>
<List>
	<TodoItemVO>
		<id>1</id>
		<title>Simple title</title>
		<detail>detail</detail>
	</TodoItemVO>
	<TodoItemVO>
		<id>2</id>
		<title>another Title</title>
		<detail>detail2</detail>
	</TodoItemVO>
</List>

So the output for this will be the following :

Simple title
another Title

It works … so where is the issue ?
Well what I would like is to cast the result in strongly type object.
The direct solution would be to create my typed object and copy each attribut in it.
My callback function would be something like this :

private function onLoadListResult(e:ResultEvent):void {
	var resultList:ArrayCollection = new ArrayCollection();
	for each (var o:ObjectProxy in  ArrayCollection(e.result.List.TodoItemVO)) {
		var todoItemVO:TodoItemVO = new TodoItemVO();
		todoItemVO.id = o.valueOf().id;
		todoItemVO.title = o.valueOf().title;
		todoItemVO.detail = o.valueOf().detail;
		resultList.addItem(todoItemVO);
	}
}

But what if I have more than 3 attributes to copy ?

Solution :

I’ve found this solution from the Darron Schall blog’s in this blog entry :

He has developped an utility object (ObjectTranslator) that will copy your data in the strongly typed object with only one line of code :

ObjectTranslator : converts a plain vanilla object to be an instance of the class passed as the second variable.  This is not a recursive funtion and will only work for the first level of nesting.  When you have deeply nested objects, you first need to convert the nested objects to class instances, and then convert the top level object.

My code will then look like this :

private function onLoadListResult(e:ResultEvent):void {
	var resultList:ArrayCollection = new ArrayCollection();
	for each (var o:ObjectProxy in  ArrayCollection(e.result.List.TodoItemVO)) {           
		resultList.addItem(ObjectTranslator.objectToInstance(o.valueOf(), TodoItemVO) as TodoItemVO);
	}
}

Categories: Actionscript Tags: ,

Yoxos eclipse distrib

February 14, 2009 Leave a comment

Just a quick entry to tell how exited I’am with the Yoxos “Eclipse on demand”
Creating your initial Eclipse distrib install has never been so easy with this tool :

First step : in their web application you just select all the plugins you need then click on “Start Download” and that’s it ! you are downloading your own eclipse distrib in a minute !
When I think how painfull it is without this great tools to get each plugin separatly, having to check that you have the needed dependencies …

yoxos_screenshot_02

But wait there’s more ! Once you are using the yoxos distrib their is a yoxos plugin embeded in eclipse which add a new perspective. From this perspective you can choose to add new plugins and yoxos will check for you all the needed dependencies and download them !

Yoxos eclipse perspective

Adding new plugins has never been so easy!

🙂

Yoxos finding dependenciesYoxos dependencies found

Yoxos features that will be installedYoxos installing features

Categories: Uncategorized Tags:

Two way binding with Flex

January 28, 2009 1 comment

Having a good api for binding ui components to the data model has became a must have feature. Since I’m playing with Flex lately I’ve quickly test how to use its binding feature.

Let say you have a VO object like this one :


package org.test.vo {

    [Bindable]
    public class PersonVO  {

        public var age:int;
        public var firstName:String;
        public var lastName:String;
    }
}

Notice the [Bindable] annotation added before the class definition, this is telling the compiler that all the public attribut inside the class should be able to dispatch an event when their value are changed so that they can be used as the source of data binding.

Solution 1 :

The following Flex code can be used to display the PersonVO data :


    <mx:Form>
        <mx:FormItem label="First Name">
            <mx:TextInput id="firstNameId"/>
        </mx:FormItem>       
        <mx:FormItem label="Last Name">
            <mx:TextInput id="lastNameId"/>
        </mx:FormItem>
        <mx:FormItem label="Age">
            <mx:TextInput id="ageId"/>
        </mx:FormItem>
    </mx:Form>

If you want a “two way” binding between the UI and the model you need to write the following


    <mx:Binding source="personVO.firstName" destination="firstNameId.text" />
    <mx:Binding source="firstNameId.text" destination="personVO.firstName" />

    <mx:Binding source="personVO.lastName" destination="lastNameId.text" />
    <mx:Binding source="lastNameId.text" destination="personVO.lastName" />

    <mx:Binding source="personVO.age.toString()" destination="ageId.text" />
    <mx:Binding source="int(ageId.text)" destination="personVO.age" />

Note : since age is an int type we need to write some extra code to tell flex how to cast from String to int and vice versa.

Solution 2 :

The binding can also be described the following way :


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*">

    <mx:Script>
        <!&#91;CDATA&#91;
            import mx.controls.Alert;
            private function showPersonValue():void {
                Alert.show(    "firstName = " + aPerson.firstName + "\n" +
                             "lastName = " + aPerson.lastName + "\n"+
                             "age = " + aPerson.age , "Info");
            }
        &#93;&#93;>
    </mx:Script>

    <local:PersonVO id="aPerson">
        <local:firstName>{firstNameId.text}</local:firstName>
        <local:lastName>{lastNameId.text}</local:lastName>
        <local:age>{int(ageId.text)}</local:age>
    </local:PersonVO>

    <mx:Form>
        <mx:FormItem label="First Name">
            <mx:TextInput id="firstNameId" text="{aPerson.firstName}"/>
        </mx:FormItem>
        <mx:FormItem label="Last Name">
            <mx:TextInput id="lastNameId" text="{aPerson.lastName}"/>
        </mx:FormItem>
        <mx:FormItem label="Age">
            <mx:TextInput id="ageId" text="{aPerson.age}"/>
        </mx:FormItem>
    </mx:Form>

    <mx:Button label="Show Person Value" click="showPersonValue()"/>

</mx:Application>

twowaysmappingsolution2

Another solution for creating a two way binding using a “in-house utility api” found here

This solution gives the following to describe the two way binding :

...
<mx:Script>
	<!&#91;CDATA&#91;
		public var userModel : UserModel;
	&#93;&#93;>
</mx:Script>
<mx:Form>
	<mx:FormItem label="First Name">
		<mx:TextInput id="txtFirstName"/>
	</mx:FormItem>
</mx:Form>
<ModelBinding model="{userModel}" field="firstName" target="{txtFirstName}"/>
...

In my opinion the main drawback for this solution is that we are losing the error warning during compilation time : if you change field name from “firstname” to “fname” for example you won’t be informed of this error.
Finally
I would like to point out this feature request posted at adobe asking for indicating two way binding in mx:binding tag and the following solution :  Two-way Data Binding – Functional and Design Specification.

Categories: Uncategorized Tags:

Ponzi scheme

December 17, 2008 Leave a comment

Following the Bernard Madoff case I’ve been told that what he has done is called a Ponzi scheme.

A Ponzi scheme is a fraudulent investment operation that involves paying abnormally high returns to investors out of the money paid in by subsequent investors, rather than from the profit from any real business.

Categories: Uncategorized

Testing JPA, Hibernate, JoSQL and Lucene

December 17, 2008 1 comment

(download the project file : change to .zip before opening)

This a just for showing some different way of making a simple query.

By the way I know that these simple tests can’t be seen seen as serious bencharking but at least it shows that using JoSQL on in memory data can enhance performance, if this make sens in your app to keep the data in memory. These are the results from the JoSQL test :

items count : 1680
JoSQL query run total time = 15 ms
JPA query run total time = 609 ms

Queries with Hibernate :

    /**
     * Simple Hibernate examples with queries
     *
     * Output :
     *
     * Hibernate: select fund0_.FUND_ID as FUND1_0_, fund0_.ADMINISTRATOR_ID as ADMINIST2_0_, fund0_.ADVISORY_NAME as ADVISORY3_0_, fund0_.ANNUAL_AUDIT as ANNUAL4_0_, fund0_.AUDIT_FIRM as AUDIT5_0_, fund0_.auditor as auditor0_, fund0_.banker as banker0_, fund0_.CLASSIFICATION_ID as CLASSIFI8_0_, fund0_.codification as codifica9_0_, fund0_.COMM_STATUS as COMM10_0_, fund0_.COUNTRY_OF_DOMICILE_ID as COUNTRY11_0_, fund0_.DATA_VENDOR_FUND_ID as DATA12_0_, fund0_.DATA_VENDOR_ID as DATA13_0_, fund0_.deleted as deleted0_, fund0_.DISCLOSURE_ID as DISCLOSURE15_0_, fund0_.EXTCOM_AGREEMENT as EXTCOM16_0_, fund0_.FINANCIAL_AUTHORITY_ID1 as FINANCIAL17_0_, fund0_.FINANCIAL_AUTHORITY_ID2 as FINANCIAL18_0_, fund0_.FINANCIAL_AUTHORITY_ID3 as FINANCIAL19_0_, fund0_.FISCAL_YEAR_END as FISCAL20_0_, fund0_.FUND_CAPACITY as FUND21_0_, fund0_.FUND_DESCRIPTION as FUND22_0_, fund0_.FUND_NAME as FUND23_0_, fund0_.FUND_REDEMPTION_GATE_FUND_LVL as FUND24_0_, fund0_.FUND_REDEMPTION_GATE_IND_LVL as FUND25_0_, fund0_.GEOGRAPHICAL_FOCUS_ID as GEOGRAP26_0_, fund0_.inception as inception0_, fund0_.instruments as instrum28_0_, fund0_.internal as internal0_, fund0_.INVESTMENT_RESTRICTIONS as INVESTMENT30_0_, fund0_.INVESTMENT_STATUS_ID as INVESTMENT31_0_, fund0_.INVESTMENT_STRATEGY as INVESTMENT32_0_, fund0_.INVESTMENT_SUB_STATUS_ID as INVESTMENT33_0_, fund0_.ISO_CODE as ISO34_0_, fund0_.IVT_MANAGEMENT_FIRM_ID as IVT35_0_, fund0_.LAST_AUDIT as LAST36_0_, fund0_.LAST_DUE_DILIGENCE as LAST37_0_, fund0_.LEGAL_ADVISOR_ID1 as LEGAL38_0_, fund0_.LEGAL_ADVISOR_ID2 as LEGAL39_0_, fund0_.LEGAL_ADVISOR_ID3 as LEGAL40_0_, fund0_.LEGAL_ADVISOR_OFFSHORE as LEGAL41_0_, fund0_.LEGAL_COUNSEL as LEGAL42_0_, fund0_.LEGAL_DESCRIPTION as LEGAL43_0_, fund0_.LEGAL_DESCRIPTION_ID as LEGAL44_0_, fund0_.LISTED_ON_A_STOCK_EXCHANGE as LISTED45_0_, fund0_.MANAGED_ACCOUNT as MANAGED46_0_, fund0_.MANAGEMENT_FIRM_ID as MANAGEMENT47_0_, fund0_.MARKETING_NAME as MARKETING48_0_, fund0_.MASTER_FUND_ID as MASTER49_0_, fund0_.MASTER_FUND_NAME as MASTER50_0_, fund0_.OFFSHORE_NAME as OFFSHORE51_0_, fund0_.OFFSHORE_VEHICLE as OFFSHORE52_0_, fund0_.PLACEMENT_AGENT as PLACEMENT53_0_, fund0_.PRIMARY_SHARE as PRIMARY71_0_, fund0_.PTF_MANAGEMENT_FIRM_ID as PTF54_0_, fund0_.ranking as ranking0_, fund0_.REPORTING_FREQUENCY_ID as REPORTING56_0_, fund0_.REPORTING_FREQUENCY_OTHER as REPORTING57_0_, fund0_.RISK_POLICY as RISK58_0_, fund0_.SECTOR_FOCUS_ID as SECTOR59_0_, fund0_.SIDE_POCKET_ALLOWABLE as SIDE60_0_, fund0_.source as source0_, fund0_.SS_CLASSIFICATION_ID as SS62_0_, fund0_.SS_FOF_CLASSIFICATION_ID as SS63_0_, fund0_.SS_MS_CLASSIFICATION_ID as SS64_0_, fund0_.stage as stage0_, fund0_.status as status0_, fund0_.STATUS_ID as STATUS67_0_, fund0_.SUB_STRATEGY as SUB68_0_, fund0_.updated as updated0_, fund0_.updater as updater0_ from Fund fund0_
     * fund list size = 1680
     * Hibernate: select count(fund0_.FUND_ID) as col_0_0_ from Fund fund0_
     * fund list size = 1680
     * Hibernate: select fundshare0_.SHARE_ID as SHARE1_1_, fundshare0_.ACCESS_RIGHT as ACCESS2_1_, fundshare0_.active as active1_, fundshare0_.CODE_BB as CODE4_1_, fundshare0_.deleted as deleted1_, fundshare0_.FUND_ID as FUND35_1_, fundshare0_.inception as inception1_, fundshare0_.INTERNAL_CODE as INTERNAL7_1_, fundshare0_.INTERNAL_SHARE as INTERNAL8_1_, fundshare0_.isin as isin1_, fundshare0_.ISO_CODE as ISO10_1_, fundshare0_.isprimary as isprimary1_, fundshare0_.LAST_PERF_AUDIT as LAST12_1_, fundshare0_.LIMIT_PERF_AUDIT as LIMIT13_1_, fundshare0_.LIQUIDITY_ID as LIQUIDITY14_1_, fundshare0_.MINIMUM_ADDITIONAL_INVEST as MINIMUM15_1_, fundshare0_.MINIMUM_INVESTMENT as MINIMUM16_1_, fundshare0_.NAV_MONITORING as NAV17_1_, fundshare0_.nominal as nominal1_, fundshare0_.OPEN_CLOSE_NAV as OPEN19_1_, fundshare0_.REFERENCE_SHARE as REFERENCE20_1_, fundshare0_.REPORTING_FREQUENCY_ID as REPORTING21_1_, fundshare0_.REPORTING_FREQUENCY_OTHER as REPORTING22_1_, fundshare0_.SERIE_ID as SERIE36_1_, fundshare0_.SHARE_CAPACITY as SHARE23_1_, fundshare0_.SHARE_CLASS as SHARE24_1_, fundshare0_.SHARE_NAME as SHARE25_1_, fundshare0_.SHARE_TYPE_ID as SHARE26_1_, fundshare0_.SHARE_TYPE_OTHER as SHARE27_1_, fundshare0_.SIDE_LETTER as SIDE28_1_, fundshare0_.STATS_START_DATE as STATS29_1_, fundshare0_.TRACK_START_DATE as TRACK30_1_, fundshare0_.updated as updated1_, fundshare0_.updater as updater1_, fundshare0_.whendeleted as whendel33_1_, fundshare0_.whodeleted as whodeleted1_ from FUND_SHARE fundshare0_
     * share list size = 21698
     * fund name = TOTO Fund
     *
     */
    public static void main(String[] args) {
        Session session = HibernateUtil.getSession();

        List lf = session.createQuery("from Fund").list();
        System.out.println("fund list size = " + lf.size());

        Long fundCount = (Long)session.createQuery("select count(fund) from Fund fund").uniqueResult();
        System.out.println("fund list size = " + fundCount);

        List ls = session.createQuery("from FundShare").list();
        System.out.println("share list size = " + ls.size());

        Fund fund = (Fund)session.get(Fund.class, new Long(1));
        System.out.println("fund name = " + fund.getFundName());
    }</pre>

Queries with JPA :

<pre>
    /**
     * JPA sample with queries
     *
     *    Output :
     *
     * Hibernate: select fund0_.FUND_ID as FUND1_1_, fund0_.ADMINISTRATOR_ID as ADMINIST2_1_, fund0_.ADVISORY_NAME as ADVISORY3_1_, fund0_.ANNUAL_AUDIT as ANNUAL4_1_, fund0_.AUDIT_FIRM as AUDIT5_1_, fund0_.auditor as auditor1_, fund0_.banker as banker1_, fund0_.CLASSIFICATION_ID as CLASSIFI8_1_, fund0_.codification as codifica9_1_, fund0_.COMM_STATUS as COMM10_1_, fund0_.COUNTRY_OF_DOMICILE_ID as COUNTRY11_1_, fund0_.DATA_VENDOR_FUND_ID as DATA12_1_, fund0_.DATA_VENDOR_ID as DATA13_1_, fund0_.deleted as deleted1_, fund0_.DISCLOSURE_ID as DISCLOSURE15_1_, fund0_.EXTCOM_AGREEMENT as EXTCOM16_1_, fund0_.FINANCIAL_AUTHORITY_ID1 as FINANCIAL17_1_, fund0_.FINANCIAL_AUTHORITY_ID2 as FINANCIAL18_1_, fund0_.FINANCIAL_AUTHORITY_ID3 as FINANCIAL19_1_, fund0_.FISCAL_YEAR_END as FISCAL20_1_, fund0_.FUND_CAPACITY as FUND21_1_, fund0_.FUND_DESCRIPTION as FUND22_1_, fund0_.FUND_NAME as FUND23_1_, fund0_.FUND_REDEMPTION_GATE_FUND_LVL as FUND24_1_, fund0_.FUND_REDEMPTION_GATE_IND_LVL as FUND25_1_, fund0_.GEOGRAPHICAL_FOCUS_ID as GEOGRAP26_1_, fund0_.inception as inception1_, fund0_.instruments as instrum28_1_, fund0_.internal as internal1_, fund0_.INVESTMENT_RESTRICTIONS as INVESTMENT30_1_, fund0_.INVESTMENT_STATUS_ID as INVESTMENT31_1_, fund0_.INVESTMENT_STRATEGY as INVESTMENT32_1_, fund0_.INVESTMENT_SUB_STATUS_ID as INVESTMENT33_1_, fund0_.ISO_CODE as ISO34_1_, fund0_.IVT_MANAGEMENT_FIRM_ID as IVT35_1_, fund0_.LAST_AUDIT as LAST36_1_, fund0_.LAST_DUE_DILIGENCE as LAST37_1_, fund0_.LEGAL_ADVISOR_ID1 as LEGAL38_1_, fund0_.LEGAL_ADVISOR_ID2 as LEGAL39_1_, fund0_.LEGAL_ADVISOR_ID3 as LEGAL40_1_, fund0_.LEGAL_ADVISOR_OFFSHORE as LEGAL41_1_, fund0_.LEGAL_COUNSEL as LEGAL42_1_, fund0_.LEGAL_DESCRIPTION as LEGAL43_1_, fund0_.LEGAL_DESCRIPTION_ID as LEGAL44_1_, fund0_.LISTED_ON_A_STOCK_EXCHANGE as LISTED45_1_, fund0_.MANAGED_ACCOUNT as MANAGED46_1_, fund0_.MANAGEMENT_FIRM_ID as MANAGEMENT47_1_, fund0_.MARKETING_NAME as MARKETING48_1_, fund0_.MASTER_FUND_ID as MASTER49_1_, fund0_.MASTER_FUND_NAME as MASTER50_1_, fund0_.OFFSHORE_NAME as OFFSHORE51_1_, fund0_.OFFSHORE_VEHICLE as OFFSHORE52_1_, fund0_.PLACEMENT_AGENT as PLACEMENT53_1_, fund0_.PRIMARY_SHARE as PRIMARY71_1_, fund0_.PTF_MANAGEMENT_FIRM_ID as PTF54_1_, fund0_.ranking as ranking1_, fund0_.REPORTING_FREQUENCY_ID as REPORTING56_1_, fund0_.REPORTING_FREQUENCY_OTHER as REPORTING57_1_, fund0_.RISK_POLICY as RISK58_1_, fund0_.SECTOR_FOCUS_ID as SECTOR59_1_, fund0_.SIDE_POCKET_ALLOWABLE as SIDE60_1_, fund0_.source as source1_, fund0_.SS_CLASSIFICATION_ID as SS62_1_, fund0_.SS_FOF_CLASSIFICATION_ID as SS63_1_, fund0_.SS_MS_CLASSIFICATION_ID as SS64_1_, fund0_.stage as stage1_, fund0_.status as status1_, fund0_.STATUS_ID as STATUS67_1_, fund0_.SUB_STRATEGY as SUB68_1_, fund0_.updated as updated1_, fund0_.updater as updater1_ from Fund fund0_
     * 1680
     * Hibernate: select * from ( select count(fund0_.FUND_ID) as col_0_0_ from Fund fund0_ ) where rownum <= ?
     * 1680
     * Hibernate: select fundview0_.FUND_ID as FUND1_2_, fundview0_.FUND_NAME as FUND2_2_ from TANIS.V_TNS_FUND fundview0_
     * FundView size = 1680
     * Hibernate: select * from ( select count(*) from FUND ) where rownum <= ?
     * 1680
     * Hibernate: select fund0_.FUND_ID as FUND1_1_, fund0_.ADMINISTRATOR_ID as ADMINIST2_1_, fund0_.ADVISORY_NAME as ADVISORY3_1_, fund0_.ANNUAL_AUDIT as ANNUAL4_1_, fund0_.AUDIT_FIRM as AUDIT5_1_, fund0_.auditor as auditor1_, fund0_.banker as banker1_, fund0_.CLASSIFICATION_ID as CLASSIFI8_1_, fund0_.codification as codifica9_1_, fund0_.COMM_STATUS as COMM10_1_, fund0_.COUNTRY_OF_DOMICILE_ID as COUNTRY11_1_, fund0_.DATA_VENDOR_FUND_ID as DATA12_1_, fund0_.DATA_VENDOR_ID as DATA13_1_, fund0_.deleted as deleted1_, fund0_.DISCLOSURE_ID as DISCLOSURE15_1_, fund0_.EXTCOM_AGREEMENT as EXTCOM16_1_, fund0_.FINANCIAL_AUTHORITY_ID1 as FINANCIAL17_1_, fund0_.FINANCIAL_AUTHORITY_ID2 as FINANCIAL18_1_, fund0_.FINANCIAL_AUTHORITY_ID3 as FINANCIAL19_1_, fund0_.FISCAL_YEAR_END as FISCAL20_1_, fund0_.FUND_CAPACITY as FUND21_1_, fund0_.FUND_DESCRIPTION as FUND22_1_, fund0_.FUND_NAME as FUND23_1_, fund0_.FUND_REDEMPTION_GATE_FUND_LVL as FUND24_1_, fund0_.FUND_REDEMPTION_GATE_IND_LVL as FUND25_1_, fund0_.GEOGRAPHICAL_FOCUS_ID as GEOGRAP26_1_, fund0_.inception as inception1_, fund0_.instruments as instrum28_1_, fund0_.internal as internal1_, fund0_.INVESTMENT_RESTRICTIONS as INVESTMENT30_1_, fund0_.INVESTMENT_STATUS_ID as INVESTMENT31_1_, fund0_.INVESTMENT_STRATEGY as INVESTMENT32_1_, fund0_.INVESTMENT_SUB_STATUS_ID as INVESTMENT33_1_, fund0_.ISO_CODE as ISO34_1_, fund0_.IVT_MANAGEMENT_FIRM_ID as IVT35_1_, fund0_.LAST_AUDIT as LAST36_1_, fund0_.LAST_DUE_DILIGENCE as LAST37_1_, fund0_.LEGAL_ADVISOR_ID1 as LEGAL38_1_, fund0_.LEGAL_ADVISOR_ID2 as LEGAL39_1_, fund0_.LEGAL_ADVISOR_ID3 as LEGAL40_1_, fund0_.LEGAL_ADVISOR_OFFSHORE as LEGAL41_1_, fund0_.LEGAL_COUNSEL as LEGAL42_1_, fund0_.LEGAL_DESCRIPTION as LEGAL43_1_, fund0_.LEGAL_DESCRIPTION_ID as LEGAL44_1_, fund0_.LISTED_ON_A_STOCK_EXCHANGE as LISTED45_1_, fund0_.MANAGED_ACCOUNT as MANAGED46_1_, fund0_.MANAGEMENT_FIRM_ID as MANAGEMENT47_1_, fund0_.MARKETING_NAME as MARKETING48_1_, fund0_.MASTER_FUND_ID as MASTER49_1_, fund0_.MASTER_FUND_NAME as MASTER50_1_, fund0_.OFFSHORE_NAME as OFFSHORE51_1_, fund0_.OFFSHORE_VEHICLE as OFFSHORE52_1_, fund0_.PLACEMENT_AGENT as PLACEMENT53_1_, fund0_.PRIMARY_SHARE as PRIMARY71_1_, fund0_.PTF_MANAGEMENT_FIRM_ID as PTF54_1_, fund0_.ranking as ranking1_, fund0_.REPORTING_FREQUENCY_ID as REPORTING56_1_, fund0_.REPORTING_FREQUENCY_OTHER as REPORTING57_1_, fund0_.RISK_POLICY as RISK58_1_, fund0_.SECTOR_FOCUS_ID as SECTOR59_1_, fund0_.SIDE_POCKET_ALLOWABLE as SIDE60_1_, fund0_.source as source1_, fund0_.SS_CLASSIFICATION_ID as SS62_1_, fund0_.SS_FOF_CLASSIFICATION_ID as SS63_1_, fund0_.SS_MS_CLASSIFICATION_ID as SS64_1_, fund0_.stage as stage1_, fund0_.status as status1_, fund0_.STATUS_ID as STATUS67_1_, fund0_.SUB_STRATEGY as SUB68_1_, fund0_.updated as updated1_, fund0_.updater as updater1_ from Fund fund0_ inner join FUND_SHARE fundsharec1_ on fund0_.FUND_ID=fundsharec1_.FUND_ID
     * 4396
     * Hibernate: select fund0_.FUND_ID as FUND1_1_, fund0_.ADMINISTRATOR_ID as ADMINIST2_1_, fund0_.ADVISORY_NAME as ADVISORY3_1_, fund0_.ANNUAL_AUDIT as ANNUAL4_1_, fund0_.AUDIT_FIRM as AUDIT5_1_, fund0_.auditor as auditor1_, fund0_.banker as banker1_, fund0_.CLASSIFICATION_ID as CLASSIFI8_1_, fund0_.codification as codifica9_1_, fund0_.COMM_STATUS as COMM10_1_, fund0_.COUNTRY_OF_DOMICILE_ID as COUNTRY11_1_, fund0_.DATA_VENDOR_FUND_ID as DATA12_1_, fund0_.DATA_VENDOR_ID as DATA13_1_, fund0_.deleted as deleted1_, fund0_.DISCLOSURE_ID as DISCLOSURE15_1_, fund0_.EXTCOM_AGREEMENT as EXTCOM16_1_, fund0_.FINANCIAL_AUTHORITY_ID1 as FINANCIAL17_1_, fund0_.FINANCIAL_AUTHORITY_ID2 as FINANCIAL18_1_, fund0_.FINANCIAL_AUTHORITY_ID3 as FINANCIAL19_1_, fund0_.FISCAL_YEAR_END as FISCAL20_1_, fund0_.FUND_CAPACITY as FUND21_1_, fund0_.FUND_DESCRIPTION as FUND22_1_, fund0_.FUND_NAME as FUND23_1_, fund0_.FUND_REDEMPTION_GATE_FUND_LVL as FUND24_1_, fund0_.FUND_REDEMPTION_GATE_IND_LVL as FUND25_1_, fund0_.GEOGRAPHICAL_FOCUS_ID as GEOGRAP26_1_, fund0_.inception as inception1_, fund0_.instruments as instrum28_1_, fund0_.internal as internal1_, fund0_.INVESTMENT_RESTRICTIONS as INVESTMENT30_1_, fund0_.INVESTMENT_STATUS_ID as INVESTMENT31_1_, fund0_.INVESTMENT_STRATEGY as INVESTMENT32_1_, fund0_.INVESTMENT_SUB_STATUS_ID as INVESTMENT33_1_, fund0_.ISO_CODE as ISO34_1_, fund0_.IVT_MANAGEMENT_FIRM_ID as IVT35_1_, fund0_.LAST_AUDIT as LAST36_1_, fund0_.LAST_DUE_DILIGENCE as LAST37_1_, fund0_.LEGAL_ADVISOR_ID1 as LEGAL38_1_, fund0_.LEGAL_ADVISOR_ID2 as LEGAL39_1_, fund0_.LEGAL_ADVISOR_ID3 as LEGAL40_1_, fund0_.LEGAL_ADVISOR_OFFSHORE as LEGAL41_1_, fund0_.LEGAL_COUNSEL as LEGAL42_1_, fund0_.LEGAL_DESCRIPTION as LEGAL43_1_, fund0_.LEGAL_DESCRIPTION_ID as LEGAL44_1_, fund0_.LISTED_ON_A_STOCK_EXCHANGE as LISTED45_1_, fund0_.MANAGED_ACCOUNT as MANAGED46_1_, fund0_.MANAGEMENT_FIRM_ID as MANAGEMENT47_1_, fund0_.MARKETING_NAME as MARKETING48_1_, fund0_.MASTER_FUND_ID as MASTER49_1_, fund0_.MASTER_FUND_NAME as MASTER50_1_, fund0_.OFFSHORE_NAME as OFFSHORE51_1_, fund0_.OFFSHORE_VEHICLE as OFFSHORE52_1_, fund0_.PLACEMENT_AGENT as PLACEMENT53_1_, fund0_.PRIMARY_SHARE as PRIMARY71_1_, fund0_.PTF_MANAGEMENT_FIRM_ID as PTF54_1_, fund0_.ranking as ranking1_, fund0_.REPORTING_FREQUENCY_ID as REPORTING56_1_, fund0_.REPORTING_FREQUENCY_OTHER as REPORTING57_1_, fund0_.RISK_POLICY as RISK58_1_, fund0_.SECTOR_FOCUS_ID as SECTOR59_1_, fund0_.SIDE_POCKET_ALLOWABLE as SIDE60_1_, fund0_.source as source1_, fund0_.SS_CLASSIFICATION_ID as SS62_1_, fund0_.SS_FOF_CLASSIFICATION_ID as SS63_1_, fund0_.SS_MS_CLASSIFICATION_ID as SS64_1_, fund0_.stage as stage1_, fund0_.status as status1_, fund0_.STATUS_ID as STATUS67_1_, fund0_.SUB_STRATEGY as SUB68_1_, fund0_.updated as updated1_, fund0_.updater as updater1_ from Fund fund0_ left outer join FUND_SHARE fundsharec1_ on fund0_.FUND_ID=fundsharec1_.FUND_ID
     * 4526
     */
    public static void main(String&#91;&#93; args) {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory(null);
        EntityManager em = factory.createEntityManager();
        em.getTransaction().begin();

        try {
            //
            List funds = em.createQuery("from Fund").getResultList();
            System.out.println(funds.size());

            Object result = em.createQuery("select count(fund) from Fund fund").getSingleResult();
            System.out.println(result);

            List fundsView = em.createQuery("from FundView").getResultList();
            System.out.println("FundView size = " + fundsView.size());            

            Object o = em.createNativeQuery("select count(*) from FUND").getSingleResult();
            System.out.println(o);

            List fundsInnerJoin = em.createQuery("select fund from Fund as fund inner join fund.fundShareCollection as share").getResultList();
            System.out.println(fundsInnerJoin.size());

            List fundsOuterJoin = em.createQuery("select fund from Fund as fund left join fund.fundShareCollection as share").getResultList();
            System.out.println(fundsOuterJoin.size());

        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            em.getTransaction().commit();
            em.close();
        }

&#91;/sourcecode&#93;

In memory query with JoSQL :

&#91;sourcecode language='java'&#93;
    /**
     * JPA example with a JoSQL query on in memory data retrived with JPA
     *
     * Output :
     *
     * Hibernate: select fund0_.FUND_ID as FUND1_1_, fund0_.ADMINISTRATOR_ID as ADMINIST2_1_, fund0_.ADVISORY_NAME as ADVISORY3_1_, fund0_.ANNUAL_AUDIT as ANNUAL4_1_, fund0_.AUDIT_FIRM as AUDIT5_1_, fund0_.auditor as auditor1_, fund0_.banker as banker1_, fund0_.CLASSIFICATION_ID as CLASSIFI8_1_, fund0_.codification as codifica9_1_, fund0_.COMM_STATUS as COMM10_1_, fund0_.COUNTRY_OF_DOMICILE_ID as COUNTRY11_1_, fund0_.DATA_VENDOR_FUND_ID as DATA12_1_, fund0_.DATA_VENDOR_ID as DATA13_1_, fund0_.deleted as deleted1_, fund0_.DISCLOSURE_ID as DISCLOSURE15_1_, fund0_.EXTCOM_AGREEMENT as EXTCOM16_1_, fund0_.FINANCIAL_AUTHORITY_ID1 as FINANCIAL17_1_, fund0_.FINANCIAL_AUTHORITY_ID2 as FINANCIAL18_1_, fund0_.FINANCIAL_AUTHORITY_ID3 as FINANCIAL19_1_, fund0_.FISCAL_YEAR_END as FISCAL20_1_, fund0_.FUND_CAPACITY as FUND21_1_, fund0_.FUND_DESCRIPTION as FUND22_1_, fund0_.FUND_NAME as FUND23_1_, fund0_.FUND_REDEMPTION_GATE_FUND_LVL as FUND24_1_, fund0_.FUND_REDEMPTION_GATE_IND_LVL as FUND25_1_, fund0_.GEOGRAPHICAL_FOCUS_ID as GEOGRAP26_1_, fund0_.inception as inception1_, fund0_.instruments as instrum28_1_, fund0_.internal as internal1_, fund0_.INVESTMENT_RESTRICTIONS as INVESTMENT30_1_, fund0_.INVESTMENT_STATUS_ID as INVESTMENT31_1_, fund0_.INVESTMENT_STRATEGY as INVESTMENT32_1_, fund0_.INVESTMENT_SUB_STATUS_ID as INVESTMENT33_1_, fund0_.ISO_CODE as ISO34_1_, fund0_.IVT_MANAGEMENT_FIRM_ID as IVT35_1_, fund0_.LAST_AUDIT as LAST36_1_, fund0_.LAST_DUE_DILIGENCE as LAST37_1_, fund0_.LEGAL_ADVISOR_ID1 as LEGAL38_1_, fund0_.LEGAL_ADVISOR_ID2 as LEGAL39_1_, fund0_.LEGAL_ADVISOR_ID3 as LEGAL40_1_, fund0_.LEGAL_ADVISOR_OFFSHORE as LEGAL41_1_, fund0_.LEGAL_COUNSEL as LEGAL42_1_, fund0_.LEGAL_DESCRIPTION as LEGAL43_1_, fund0_.LEGAL_DESCRIPTION_ID as LEGAL44_1_, fund0_.LISTED_ON_A_STOCK_EXCHANGE as LISTED45_1_, fund0_.MANAGED_ACCOUNT as MANAGED46_1_, fund0_.MANAGEMENT_FIRM_ID as MANAGEMENT47_1_, fund0_.MARKETING_NAME as MARKETING48_1_, fund0_.MASTER_FUND_ID as MASTER49_1_, fund0_.MASTER_FUND_NAME as MASTER50_1_, fund0_.OFFSHORE_NAME as OFFSHORE51_1_, fund0_.OFFSHORE_VEHICLE as OFFSHORE52_1_, fund0_.PLACEMENT_AGENT as PLACEMENT53_1_, fund0_.PRIMARY_SHARE as PRIMARY71_1_, fund0_.PTF_MANAGEMENT_FIRM_ID as PTF54_1_, fund0_.ranking as ranking1_, fund0_.REPORTING_FREQUENCY_ID as REPORTING56_1_, fund0_.REPORTING_FREQUENCY_OTHER as REPORTING57_1_, fund0_.RISK_POLICY as RISK58_1_, fund0_.SECTOR_FOCUS_ID as SECTOR59_1_, fund0_.SIDE_POCKET_ALLOWABLE as SIDE60_1_, fund0_.source as source1_, fund0_.SS_CLASSIFICATION_ID as SS62_1_, fund0_.SS_FOF_CLASSIFICATION_ID as SS63_1_, fund0_.SS_MS_CLASSIFICATION_ID as SS64_1_, fund0_.stage as stage1_, fund0_.status as status1_, fund0_.STATUS_ID as STATUS67_1_, fund0_.SUB_STRATEGY as SUB68_1_, fund0_.updated as updated1_, fund0_.updater as updater1_ from Fund fund0_
     * 1680
     * JoSQL query run total time = 15
     * JoSQL result count = 233
     * Hibernate: select fund0_.FUND_ID as FUND1_1_, fund0_.ADMINISTRATOR_ID as ADMINIST2_1_, fund0_.ADVISORY_NAME as ADVISORY3_1_, fund0_.ANNUAL_AUDIT as ANNUAL4_1_, fund0_.AUDIT_FIRM as AUDIT5_1_, fund0_.auditor as auditor1_, fund0_.banker as banker1_, fund0_.CLASSIFICATION_ID as CLASSIFI8_1_, fund0_.codification as codifica9_1_, fund0_.COMM_STATUS as COMM10_1_, fund0_.COUNTRY_OF_DOMICILE_ID as COUNTRY11_1_, fund0_.DATA_VENDOR_FUND_ID as DATA12_1_, fund0_.DATA_VENDOR_ID as DATA13_1_, fund0_.deleted as deleted1_, fund0_.DISCLOSURE_ID as DISCLOSURE15_1_, fund0_.EXTCOM_AGREEMENT as EXTCOM16_1_, fund0_.FINANCIAL_AUTHORITY_ID1 as FINANCIAL17_1_, fund0_.FINANCIAL_AUTHORITY_ID2 as FINANCIAL18_1_, fund0_.FINANCIAL_AUTHORITY_ID3 as FINANCIAL19_1_, fund0_.FISCAL_YEAR_END as FISCAL20_1_, fund0_.FUND_CAPACITY as FUND21_1_, fund0_.FUND_DESCRIPTION as FUND22_1_, fund0_.FUND_NAME as FUND23_1_, fund0_.FUND_REDEMPTION_GATE_FUND_LVL as FUND24_1_, fund0_.FUND_REDEMPTION_GATE_IND_LVL as FUND25_1_, fund0_.GEOGRAPHICAL_FOCUS_ID as GEOGRAP26_1_, fund0_.inception as inception1_, fund0_.instruments as instrum28_1_, fund0_.internal as internal1_, fund0_.INVESTMENT_RESTRICTIONS as INVESTMENT30_1_, fund0_.INVESTMENT_STATUS_ID as INVESTMENT31_1_, fund0_.INVESTMENT_STRATEGY as INVESTMENT32_1_, fund0_.INVESTMENT_SUB_STATUS_ID as INVESTMENT33_1_, fund0_.ISO_CODE as ISO34_1_, fund0_.IVT_MANAGEMENT_FIRM_ID as IVT35_1_, fund0_.LAST_AUDIT as LAST36_1_, fund0_.LAST_DUE_DILIGENCE as LAST37_1_, fund0_.LEGAL_ADVISOR_ID1 as LEGAL38_1_, fund0_.LEGAL_ADVISOR_ID2 as LEGAL39_1_, fund0_.LEGAL_ADVISOR_ID3 as LEGAL40_1_, fund0_.LEGAL_ADVISOR_OFFSHORE as LEGAL41_1_, fund0_.LEGAL_COUNSEL as LEGAL42_1_, fund0_.LEGAL_DESCRIPTION as LEGAL43_1_, fund0_.LEGAL_DESCRIPTION_ID as LEGAL44_1_, fund0_.LISTED_ON_A_STOCK_EXCHANGE as LISTED45_1_, fund0_.MANAGED_ACCOUNT as MANAGED46_1_, fund0_.MANAGEMENT_FIRM_ID as MANAGEMENT47_1_, fund0_.MARKETING_NAME as MARKETING48_1_, fund0_.MASTER_FUND_ID as MASTER49_1_, fund0_.MASTER_FUND_NAME as MASTER50_1_, fund0_.OFFSHORE_NAME as OFFSHORE51_1_, fund0_.OFFSHORE_VEHICLE as OFFSHORE52_1_, fund0_.PLACEMENT_AGENT as PLACEMENT53_1_, fund0_.PRIMARY_SHARE as PRIMARY71_1_, fund0_.PTF_MANAGEMENT_FIRM_ID as PTF54_1_, fund0_.ranking as ranking1_, fund0_.REPORTING_FREQUENCY_ID as REPORTING56_1_, fund0_.REPORTING_FREQUENCY_OTHER as REPORTING57_1_, fund0_.RISK_POLICY as RISK58_1_, fund0_.SECTOR_FOCUS_ID as SECTOR59_1_, fund0_.SIDE_POCKET_ALLOWABLE as SIDE60_1_, fund0_.source as source1_, fund0_.SS_CLASSIFICATION_ID as SS62_1_, fund0_.SS_FOF_CLASSIFICATION_ID as SS63_1_, fund0_.SS_MS_CLASSIFICATION_ID as SS64_1_, fund0_.stage as stage1_, fund0_.status as status1_, fund0_.STATUS_ID as STATUS67_1_, fund0_.SUB_STRATEGY as SUB68_1_, fund0_.updated as updated1_, fund0_.updater as updater1_ from Fund fund0_ where fund0_.FUND_NAME like '%SGAM%'
     * JPA query run total time = 609
     * JPA result count = 233
     */
    public static void main(String&#91;&#93; args) {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory(null);
        EntityManager em = factory.createEntityManager();
        em.getTransaction().begin();

        try {
            Query query = em.createQuery("from Fund");
            List funds = query.getResultList();
            System.out.println(funds.size());

            // prepare and run the JoSQL Query :
            org.josql.Query josqlQuery = new org.josql.Query();
            josqlQuery.parse("select * from models.generated.Fund where fundName like '%SGAM%'");
            long start = System.currentTimeMillis();
            QueryResults qr = josqlQuery.execute(funds);
            List<Fund> fundsResult = qr.getResults();
            System.out.println("JoSQL query run total time = " + (System.currentTimeMillis() - start));
            System.out.println( "JoSQL result count = " + fundsResult.size() );

            // query to check that the result size found with JoSQL is ok :
            Query query2 = em.createQuery("select fund from Fund fund where fund.fundName like '%SGAM%'");
            start = System.currentTimeMillis();
            List count = query2.getResultList();
            System.out.println("JPA query run total time = " + (System.currentTimeMillis() - start));
            System.out.println("JPA result count = " + count.size());            

            // Display result
            int i=0;
            for (Fund f:fundsResult)
                System.out.println(i++ + " = " + f.getFundName());

        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            em.getTransaction().commit();
            em.close();
        }

    }

In memory query with Lucene :

<pre>    /**
     * Simple example with Lucene indexing and querying
     *
     * Output :
     *
     * Hibernate: select fund0_.FUND_ID as FUND1_1_, fund0_.ADMINISTRATOR_ID as ADMINIST2_1_, fund0_.ADVISORY_NAME as ADVISORY3_1_, fund0_.ANNUAL_AUDIT as ANNUAL4_1_, fund0_.AUDIT_FIRM as AUDIT5_1_, fund0_.auditor as auditor1_, fund0_.banker as banker1_, fund0_.CLASSIFICATION_ID as CLASSIFI8_1_, fund0_.codification as codifica9_1_, fund0_.COMM_STATUS as COMM10_1_, fund0_.COUNTRY_OF_DOMICILE_ID as COUNTRY11_1_, fund0_.DATA_VENDOR_FUND_ID as DATA12_1_, fund0_.DATA_VENDOR_ID as DATA13_1_, fund0_.deleted as deleted1_, fund0_.DISCLOSURE_ID as DISCLOSURE15_1_, fund0_.EXTCOM_AGREEMENT as EXTCOM16_1_, fund0_.FINANCIAL_AUTHORITY_ID1 as FINANCIAL17_1_, fund0_.FINANCIAL_AUTHORITY_ID2 as FINANCIAL18_1_, fund0_.FINANCIAL_AUTHORITY_ID3 as FINANCIAL19_1_, fund0_.FISCAL_YEAR_END as FISCAL20_1_, fund0_.FUND_CAPACITY as FUND21_1_, fund0_.FUND_DESCRIPTION as FUND22_1_, fund0_.FUND_NAME as FUND23_1_, fund0_.FUND_REDEMPTION_GATE_FUND_LVL as FUND24_1_, fund0_.FUND_REDEMPTION_GATE_IND_LVL as FUND25_1_, fund0_.GEOGRAPHICAL_FOCUS_ID as GEOGRAP26_1_, fund0_.inception as inception1_, fund0_.instruments as instrum28_1_, fund0_.internal as internal1_, fund0_.INVESTMENT_RESTRICTIONS as INVESTMENT30_1_, fund0_.INVESTMENT_STATUS_ID as INVESTMENT31_1_, fund0_.INVESTMENT_STRATEGY as INVESTMENT32_1_, fund0_.INVESTMENT_SUB_STATUS_ID as INVESTMENT33_1_, fund0_.ISO_CODE as ISO34_1_, fund0_.IVT_MANAGEMENT_FIRM_ID as IVT35_1_, fund0_.LAST_AUDIT as LAST36_1_, fund0_.LAST_DUE_DILIGENCE as LAST37_1_, fund0_.LEGAL_ADVISOR_ID1 as LEGAL38_1_, fund0_.LEGAL_ADVISOR_ID2 as LEGAL39_1_, fund0_.LEGAL_ADVISOR_ID3 as LEGAL40_1_, fund0_.LEGAL_ADVISOR_OFFSHORE as LEGAL41_1_, fund0_.LEGAL_COUNSEL as LEGAL42_1_, fund0_.LEGAL_DESCRIPTION as LEGAL43_1_, fund0_.LEGAL_DESCRIPTION_ID as LEGAL44_1_, fund0_.LISTED_ON_A_STOCK_EXCHANGE as LISTED45_1_, fund0_.MANAGED_ACCOUNT as MANAGED46_1_, fund0_.MANAGEMENT_FIRM_ID as MANAGEMENT47_1_, fund0_.MARKETING_NAME as MARKETING48_1_, fund0_.MASTER_FUND_ID as MASTER49_1_, fund0_.MASTER_FUND_NAME as MASTER50_1_, fund0_.OFFSHORE_NAME as OFFSHORE51_1_, fund0_.OFFSHORE_VEHICLE as OFFSHORE52_1_, fund0_.PLACEMENT_AGENT as PLACEMENT53_1_, fund0_.PRIMARY_SHARE as PRIMARY71_1_, fund0_.PTF_MANAGEMENT_FIRM_ID as PTF54_1_, fund0_.ranking as ranking1_, fund0_.REPORTING_FREQUENCY_ID as REPORTING56_1_, fund0_.REPORTING_FREQUENCY_OTHER as REPORTING57_1_, fund0_.RISK_POLICY as RISK58_1_, fund0_.SECTOR_FOCUS_ID as SECTOR59_1_, fund0_.SIDE_POCKET_ALLOWABLE as SIDE60_1_, fund0_.source as source1_, fund0_.SS_CLASSIFICATION_ID as SS62_1_, fund0_.SS_FOF_CLASSIFICATION_ID as SS63_1_, fund0_.SS_MS_CLASSIFICATION_ID as SS64_1_, fund0_.stage as stage1_, fund0_.status as status1_, fund0_.STATUS_ID as STATUS67_1_, fund0_.SUB_STRATEGY as SUB68_1_, fund0_.updated as updated1_, fund0_.updater as updater1_ from Fund fund0_
     * Collection size = 1680
     * Hibernate: select this_.FUND_ID as FUND1_1_0_, this_.ADMINISTRATOR_ID as ADMINIST2_1_0_, this_.ADVISORY_NAME as ADVISORY3_1_0_, this_.ANNUAL_AUDIT as ANNUAL4_1_0_, this_.AUDIT_FIRM as AUDIT5_1_0_, this_.auditor as auditor1_0_, this_.banker as banker1_0_, this_.CLASSIFICATION_ID as CLASSIFI8_1_0_, this_.codification as codifica9_1_0_, this_.COMM_STATUS as COMM10_1_0_, this_.COUNTRY_OF_DOMICILE_ID as COUNTRY11_1_0_, this_.DATA_VENDOR_FUND_ID as DATA12_1_0_, this_.DATA_VENDOR_ID as DATA13_1_0_, this_.deleted as deleted1_0_, this_.DISCLOSURE_ID as DISCLOSURE15_1_0_, this_.EXTCOM_AGREEMENT as EXTCOM16_1_0_, this_.FINANCIAL_AUTHORITY_ID1 as FINANCIAL17_1_0_, this_.FINANCIAL_AUTHORITY_ID2 as FINANCIAL18_1_0_, this_.FINANCIAL_AUTHORITY_ID3 as FINANCIAL19_1_0_, this_.FISCAL_YEAR_END as FISCAL20_1_0_, this_.FUND_CAPACITY as FUND21_1_0_, this_.FUND_DESCRIPTION as FUND22_1_0_, this_.FUND_NAME as FUND23_1_0_, this_.FUND_REDEMPTION_GATE_FUND_LVL as FUND24_1_0_, this_.FUND_REDEMPTION_GATE_IND_LVL as FUND25_1_0_, this_.GEOGRAPHICAL_FOCUS_ID as GEOGRAP26_1_0_, this_.inception as inception1_0_, this_.instruments as instrum28_1_0_, this_.internal as internal1_0_, this_.INVESTMENT_RESTRICTIONS as INVESTMENT30_1_0_, this_.INVESTMENT_STATUS_ID as INVESTMENT31_1_0_, this_.INVESTMENT_STRATEGY as INVESTMENT32_1_0_, this_.INVESTMENT_SUB_STATUS_ID as INVESTMENT33_1_0_, this_.ISO_CODE as ISO34_1_0_, this_.IVT_MANAGEMENT_FIRM_ID as IVT35_1_0_, this_.LAST_AUDIT as LAST36_1_0_, this_.LAST_DUE_DILIGENCE as LAST37_1_0_, this_.LEGAL_ADVISOR_ID1 as LEGAL38_1_0_, this_.LEGAL_ADVISOR_ID2 as LEGAL39_1_0_, this_.LEGAL_ADVISOR_ID3 as LEGAL40_1_0_, this_.LEGAL_ADVISOR_OFFSHORE as LEGAL41_1_0_, this_.LEGAL_COUNSEL as LEGAL42_1_0_, this_.LEGAL_DESCRIPTION as LEGAL43_1_0_, this_.LEGAL_DESCRIPTION_ID as LEGAL44_1_0_, this_.LISTED_ON_A_STOCK_EXCHANGE as LISTED45_1_0_, this_.MANAGED_ACCOUNT as MANAGED46_1_0_, this_.MANAGEMENT_FIRM_ID as MANAGEMENT47_1_0_, this_.MARKETING_NAME as MARKETING48_1_0_, this_.MASTER_FUND_ID as MASTER49_1_0_, this_.MASTER_FUND_NAME as MASTER50_1_0_, this_.OFFSHORE_NAME as OFFSHORE51_1_0_, this_.OFFSHORE_VEHICLE as OFFSHORE52_1_0_, this_.PLACEMENT_AGENT as PLACEMENT53_1_0_, this_.PRIMARY_SHARE as PRIMARY71_1_0_, this_.PTF_MANAGEMENT_FIRM_ID as PTF54_1_0_, this_.ranking as ranking1_0_, this_.REPORTING_FREQUENCY_ID as REPORTING56_1_0_, this_.REPORTING_FREQUENCY_OTHER as REPORTING57_1_0_, this_.RISK_POLICY as RISK58_1_0_, this_.SECTOR_FOCUS_ID as SECTOR59_1_0_, this_.SIDE_POCKET_ALLOWABLE as SIDE60_1_0_, this_.source as source1_0_, this_.SS_CLASSIFICATION_ID as SS62_1_0_, this_.SS_FOF_CLASSIFICATION_ID as SS63_1_0_, this_.SS_MS_CLASSIFICATION_ID as SS64_1_0_, this_.stage as stage1_0_, this_.status as status1_0_, this_.STATUS_ID as STATUS67_1_0_, this_.SUB_STRATEGY as SUB68_1_0_, this_.updated as updated1_0_, this_.updater as updater1_0_ from Fund this_ where (this_.FUND_ID in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?))
     * Lucene query time = 703
     * Lucene query result size = 234
     *
     */
    public static void main(String[] args) {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory(null);

        EntityManager em = factory.createEntityManager();

        em.getTransaction().begin();

        try {
            // Get all the data
            List<Fund> funds = em.createQuery("from Fund").getResultList();
            System.out.println("Collection size = " + funds.size());

            // index fields for each fund (in our case we are just indexing the fundName field)
            FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
            for(Fund fund : funds)
                fullTextEntityManager.index(fund);

            // Create a Lucene request to get all the funds with SGAM in its name
            MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[]{"fundName"}, new StandardAnalyzer());
            org.apache.lucene.search.Query luceneQuery = parser.parse("SGAM");
            FullTextQuery query = fullTextEntityManager.createFullTextQuery(luceneQuery, Fund.class);

            long start = System.currentTimeMillis();
            List<Fund> list = query.getResultList();
            System.out.println("Lucene query time = " + (System.currentTimeMillis() - start));
            System.out.println("Lucene query result size = " + list.size());

            // Display result
            int i=0;
            for (Fund f:list) {
                System.out.println(i++ + " = " + f.getFundName());
            }

        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            em.getTransaction().commit();
            em.close();
        }

    }
Categories: java Tags: , , , ,