Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [CDO] JPA
[CDO] JPA [message #609574] Wed, 29 August 2007 02:29
Simon Mc Duff is currently offline Simon Mc DuffFriend
Messages: 596
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.

------=_NextPart_000_0289_01C7E9C2.E0D0B550
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I started to put JPA interface in front of CDO.=20

I added a QueryRequest as well. Right now it does only support native =
Query.. but still. (Delegate the QueryString to the back end...)

We added QueryRequest and a QueryIndication...


Right now the query is only a string :-(... It is far to have all the =
feature that JPA gives.. but we need to start somewhere.

What do you think Eike ? It is worth it.. the complete the query =
mechanism ? and to add XA transaction ?


HERE some code:

HashMap map =3D new HashMap();

map.put("packages", new EPackage[] { Model1Package.eINSTANCE } );
map.put("repositoryName", "repo1");

EntityManagerFactory factory =3D =
Persistence.createEntityManagerFactory("localhost:2036",map);

EntityManager manager =3D factory.createEntityManager(map);
manager.getTransaction().begin();

Resource resource =3D manager.find(Resource.class, "/test1");

long timeStart =3D System.currentTimeMillis();
Iterator<EObject> itr =3D resource.getAllContents();
int count =3D0;
while ( itr.hasNext() )
{
Vehicle vehicle =3D (Vehicle) itr.next();
if (count % 1000 =3D=3D 0 && count !=3D 0)
{
long millis =3D (System.currentTimeMillis() - timeStart);
if (millis !=3D 0)
System.out.println("TIME TO TAKE " + count + " "+ millis + " "+ (count =
*1000 / millis )+ " objects / sec" );
}
count++;
}
System.out.println("TIME TO TAKE " + count + " "+ =
(System.currentTimeMillis() - timeStart));

Query query =3D manager.createNativeQuery("<native QUERY>");
List returnResult =3D query.getResultList();
manager.getTransaction().commit();

manager.close();

factory.close();

Simon
------=_NextPart_000_0289_01C7E9C2.E0D0B550
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16525" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I started to put JPA interface in front =
of CDO.=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I added a QueryRequest as well. Right =
now it does=20
only support native Query.. but still.&nbsp; (Delegate the QueryString =
to the=20
back end...)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>We added QueryRequest and a=20
QueryIndication...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Right now the query is only a string =
:-(... It is=20
far to have all the feature that JPA gives.. but we need to start=20
somewhere.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV>
<DIV align=3Dleft><FONT face=3DArial><FONT size=3D2><FONT face=3DArial =
size=3D2>What do=20
you think Eike ? It is worth it..&nbsp; the complete the query mechanism =
? and=20
to add XA transaction ?</FONT></FONT></FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>HERE some =
code:</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>HashMap map =3D new=20
HashMap();</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial><FONT size=3D2><FONT face=3DArial=20
size=3D2></FONT></FONT></FONT>&nbsp;</DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>map.put("packages", new =
EPackage[] {=20
Model1Package.eINSTANCE } );</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>map.put("repositoryName",=20
"repo1");</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>EntityManagerFactory =
factory =3D=20
Persistence.createEntityManagerFactory("localhost:2036",map); </FONT></DIV=
>
<DIV align=3Dleft><FONT face=3DArial><FONT size=3D2><FONT face=3DArial=20
size=3D2></FONT></FONT></FONT>&nbsp;</DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>EntityManager manager =3D=20
factory.createEntityManager(map);</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial><FONT size=3D2><FONT face=3DArial =
size=3D2><FONT=20
size=3D2>
<P>manager.getTransaction().begin();</P></FONT></FONT></FONT ></FONT></DIV=
>
<DIV align=3Dleft><FONT face=3DArial size=3D2>Resource resource =3D=20
manager.find(Resource.class, "/test1");</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>long timeStart =3D=20
System.currentTimeMillis();</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>Iterator&lt;EObject&gt; =
itr =3D=20
resource.getAllContents();</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>int count =
=3D0;</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>while ( itr.hasNext() =
)</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>Vehicle vehicle =3D =
(Vehicle)=20
itr.next();</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>if (count % 1000 =3D=3D 0 =
&amp;&amp; count=20
!=3D 0)</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>long millis =3D=20
(System.currentTimeMillis() - timeStart);</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>if (millis !=3D =
0)</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>System.out.println("TIME =
TO TAKE " +=20
count + " "+ millis + " "+ (count *1000 / millis )+ " objects / sec"=20
);</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>count++;</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial size=3D2>System.out.println("TIME =
TO TAKE " +=20
count + " "+ (System.currentTimeMillis() - timeStart));</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial><FONT size=3D2><FONT face=3DArial=20
size=3D2></FONT></FONT></FONT>&nbsp;</DIV><FONT size=3D2>
<DIV align=3Dleft><FONT face=3DArial>Query query =3D=20
manager.createNativeQuery(</FONT></FONT><FONT face=3DArial =
color=3D#2a00ff=20
size=3D2>"&lt;native QUERY&gt;"</FONT><FONT size=3D2><FONT=20
face=3DArial>);</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial>List returnResult =3D=20
query.getResultList();</FONT></DIV>
<DIV align=3Dleft><FONT size=3D2>
<P>manager.getTransaction().commit();</P></FONT></DIV></FONT >
<DIV align=3Dleft><FONT face=3DArial =
size=3D2>manager.close();</FONT></DIV>
<DIV align=3Dleft><FONT face=3DArial><FONT size=3D2><FONT face=3DArial=20
size=3D2></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>factory.close();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Simon</FONT></DIV></BODY></HTML>

------=_NextPart_000_0289_01C7E9C2.E0D0B550--
Previous Topic:[CDO] [0.8.0]
Next Topic:[CDO/NET4J][0.8.0] Failover mechanism
Goto Forum:
  


Current Time: Sun Sep 25 21:03:10 GMT 2022

Powered by FUDForum. Page generated in 0.01943 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top