[CDO] query on a view other than latest [message #1708399] |
Wed, 16 September 2015 09:22 |
Stefan Scheiber Messages: 18 Registered: February 2015 |
Junior Member |
|
|
Hi,
I need to execute a CDO Query (CDO OCL) on a view with a timestamp (not latest).
However, I get ObjectNotFoundExceptions for Objects that are present in latest but missing in my view. My question is, if this is a bug or am I doing something wrong?
Below is my code:
CDONet4jSession session = ...
CDOCommitHistory history = session.getCommitInfoManager().getHistory();
CDOCommitInfo commitInfo = history.getElement(1); // getting the previous commit
CDOView view = session.openView(commit.getBranch(), commit.getTimeStamp());
CDOQuery query = view.createQuery("ocl", "Book.allInstances()", null);
List<Book> books = query.getResult(Book.class);
after the first commit i have the books with OID 4 and OID 5 (the result I'm expecting)
after the second commit i have the books with OID 9 and OID 10 (the books 4 and 5 were removed)
I get the error that Object with OID 9 cannot be found in view. That is correct, however, the query should not fail but deliver the correct answer OID4 and OID5.
The same code works if I make the query on the latest snapshot, i.e. if I fetch the latest commit
CDOCommitInfo commitInfo = history.getFirstElement(); // getting the latest commit
Of course, in this case the result is OID9 and OID10.
Thanks,
Stefan
|
|
|
Re: [CDO] query on a view other than latest [message #1710707 is a reply to message #1708399] |
Thu, 08 October 2015 14:45 |
|
Hi Stefan,
I've added the following test case to OCLQueryTest:
@Requires(IRepositoryConfig.CAPABILITY_AUDITING)
public void testAuditWithDetachedObject() throws Exception
{
assertEquals(NUM_OF_PRODUCTS, products.size());
Product1 p1 = getModel1Factory().createProduct1();
p1.setName("p1");
resource.getContents().add(0, p1);
CDOCommitInfo commitInfo = transaction.commit();
resource.getContents().remove(0);
transaction.commit();
CDOView audit = transaction.getSession().openView(commitInfo);
CDOQuery query = audit.createQuery("ocl", "Product1.allInstances()", getModel1Package().getProduct1());
query.setParameter("cdoLazyExtents", useLazyExtents());
List<Product1> result = query.getResult();
assertEquals(NUM_OF_PRODUCTS + 1, result.size());
}
And it passes successfully.
In your code, is it just an email typo that you use "commit" instead of the "commitInfo" you've obtained from the
history, or are you accidentally referring to a wrong time stamp?
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Am 16.09.2015 um 11:22 schrieb Stefan Scheiber:
> Hi,
>
> I need to execute a CDO Query (CDO OCL) on a view with a timestamp (not latest).
> However, I get ObjectNotFoundExceptions for Objects that are present in latest but missing in my view. My question is,
> if this is a bug or am I doing something wrong?
>
> Below is my code:
>
> CDONet4jSession session = ...
> CDOCommitHistory history = session.getCommitInfoManager().getHistory();
> CDOCommitInfo commitInfo = history.getElement(1); // getting the previous commit
> CDOView view = session.openView(commit.getBranch(), commit.getTimeStamp());
> CDOQuery query = view.createQuery("ocl", "Book.allInstances()", null);
> List<Book> books = query.getResult(Book.class);
>
>
> after the first commit i have the books with OID 4 and OID 5 (the result I'm expecting)
> after the second commit i have the books with OID 9 and OID 10 (the books 4 and 5 were removed)
> I get the error that Object with OID 9 cannot be found in view. That is correct, however, the query should not fail
> but deliver the correct answer OID4 and OID5.
>
> The same code works if I make the query on the latest snapshot, i.e. if I fetch the latest commit
>
> CDOCommitInfo commitInfo = history.getFirstElement(); // getting the latest commit
>
> Of course, in this case the result is OID9 and OID10.
>
> Thanks,
> Stefan
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04939 seconds