Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO/Hibernate] Query withing one resource(How to query within one resource stored in CDO/Hibernate repository )
[CDO/Hibernate] Query withing one resource [message #1370111] Tue, 20 May 2014 18:02 Go to next message
Evgeny Karataev is currently offline Evgeny Karataev
Messages: 18
Registered: May 2014
Junior Member
Hello,

CDOQuery allows to query, for example, for all instances of an object in the whole repository. For example:

CDOQuery cdoQuery = transaction.createQuery("hql", "from Product");


The code above will search for all products in all resources.

Is it possible to perform a CDOQuery which will search only within a given (by resource id) resource?

I have two ideas but I am not sure if that is possible or there is other way:
1) Somehow provide resource id in the query, e.g.:

CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where reseource_id = test1");


2) Or create CDOQuery on resource object.

Thank you.

Re: [CDO/Hibernate] Query withing one resource [message #1383952 is a reply to message #1370111] Tue, 27 May 2014 07:54 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
Hey,
Later reply... Teneo automatically adds a resourceId property to each object. So you can query using it. I never tried
it though, so there could be obstacles:
CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where resourceId=:id");
cdoQuery.setParameter("id", resourceCDOId);

gr. Martin

On 21-05-14 00:02, Evgeny Karataev wrote:


> Hello,
>
> CDOQuery allows to query, for example, for all instances of an object in the whole repository. For example:
>
> CDOQuery cdoQuery = transaction.createQuery("hql", "from Product");
>
> The code above will search for all products in all resources.
>
> Is it possible to perform a CDOQuery which will search only within a given (by resource id) resource?
> I have two ideas but I am not sure if that is possible or there is other way:
> 1) Somehow provide resource id in the query, e.g.:
>
> CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where reseource_id = test1");
>
> 2) Or create CDOQuery on resource object.
>
> Thank you.
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [CDO/Hibernate] Query withing one resource [message #1383967 is a reply to message #1383952] Tue, 27 May 2014 09:57 Go to previous messageGo to next message
Evgeny Karataev is currently offline Evgeny Karataev
Messages: 18
Registered: May 2014
Junior Member
Hello Martin,

Thank you for your reply.

I will try what you've suggested and will write back here if I am successful or not.
Re: [CDO/Hibernate] Query withing one resource [message #1386209 is a reply to message #1383967] Sat, 14 June 2014 17:48 Go to previous messageGo to next message
Evgeny Karataev is currently offline Evgeny Karataev
Messages: 18
Registered: May 2014
Junior Member
Hello Martin,

I just tried the approach that you've suggested. And it seems that it works. I was able to query withing one resource by using query like this one:
CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where resourceId=:id");
cdoQuery.setParameter("id", resourceCDOId);


However, what I've noticed is that for some EClasses from my ecore model corresponding tables in my MySQL database have null value in the resource_id column, but has some value in the container_id column, while for other EClasses, in the corresponding tables resource_id value is set correctly.
This happens for following situation.
For example, I have Class1 in the ecore model having an attribute A that is 0 or more references of Class2. Then in my MySQL database I have corresponding table for Class1 with resource_id values set correctly and nulls in container_id, and corresponding table for Class2 will nulls in the resource_id column and some values in the container_id

Using the query above, I can successfully query for the instances of Class1 for a given resource_id, but not for Class2. I assume I can probably use the container_id columns and perform a join to get all instances of Class2.

Is the join the only way?

Thank you.
Re: [CDO/Hibernate] Query withing one resource [message #1386238 is a reply to message #1386209] Sun, 15 June 2014 16:21 Go to previous message
Erdal Karaca is currently offline Erdal Karaca
Messages: 736
Registered: July 2009
Senior Member
This is due to EMF's nature of modeling associations: an object is either contained in a resource (resource_id is set) OR it is part of another object which is its container (container_id is set), but not both.

Evgeny Karataev wrote on Sat, 14 June 2014 23:48
Hello Martin,

I just tried the approach that you've suggested. And it seems that it works. I was able to query withing one resource by using query like this one:
CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where resourceId=:id");
cdoQuery.setParameter("id", resourceCDOId);


However, what I've noticed is that for some EClasses from my ecore model corresponding tables in my MySQL database have null value in the resource_id column, but has some value in the container_id column, while for other EClasses, in the corresponding tables resource_id value is set correctly.
This happens for following situation.
For example, I have Class1 in the ecore model having an attribute A that is 0 or more references of Class2. Then in my MySQL database I have corresponding table for Class1 with resource_id values set correctly and nulls in container_id, and corresponding table for Class2 will nulls in the resource_id column and some values in the container_id

Using the query above, I can successfully query for the instances of Class1 for a given resource_id, but not for Class2. I assume I can probably use the container_id columns and perform a join to get all instances of Class2.

Is the join the only way?

Thank you.

Previous Topic:Acceleo generator in standalone mode
Next Topic:[EMF] Consuming org.eclipse.emf.ecore.generated_package
Goto Forum:
  


Current Time: Fri Aug 22 21:38:33 EDT 2014

Powered by FUDForum. Page generated in 0.01702 seconds