This content has been marked as final.
Show 3 replies
-
1. Re: Selecting Versions greater than the original
plaky Nov 11, 2008 6:04 AM (in response to scottr0829)Hi,
have you tried to use the RevisionTypeProperty-Projection?
Look at this: :)Map<String, String> configurationOverrides = new HashMap<String, String>(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ConsolePU", configurationOverrides); entityManager = emf.createEntityManager(); versionsReader = VersionsReaderFactory.get(entityManager); Address addy = new Address(); addy.setFlatNumber(1); addy.setHouseNumber(1); addy.setStreetName("initial"); entityManager.getTransaction().begin(); entityManager.persist(addy); entityManager.getTransaction().commit(); for (int j = 0; j < 5; j++) { addy.setStreetName("change " + j); entityManager.getTransaction().begin(); entityManager.merge(addy); entityManager.getTransaction().commit(); } int id = addy.getId(); System.out.println("reading all versions:"); List<Address> resultsAll = versionsReader.createQuery().forRevisionsOfEntity(Address.class, true).add( VersionsRestrictions.idEq(id)).getResultList(); for (Address a : resultsAll) { System.out.println(a.getStreetName()); } System.out.println("reading only modificiations"); List<Address> resultsMod = versionsReader.createQuery().forRevisionsOfEntity(Address.class, true).add( VersionsRestrictions.idEq(id)).add(VersionsRestrictions.eq("_revision_type", RevisionType.MOD)) .getResultList(); for (Address a : resultsMod) { System.out.println(a.getStreetName()); } System.out.println("another way to read modificiations"); int initialRevision = (Integer) versionsReader.createQuery().forRevisionsOfEntity(Address.class, false).add(VersionsRestrictions.idEq(id)).setProjection(RevisionProperty.min()).getSingleResult(); List<Address> resultsAlternate = versionsReader.createQuery().forRevisionsOfEntity(Address.class, true).add(VersionsRestrictions.idEq(id)).add(RevisionProperty.gt(initialRevision)).getResultList(); for (Address a : resultsAlternate) { System.out.println(a.getStreetName()); } emf.close();
And the output:
reading all versions:
initial
change 0
change 1
change 2
change 3
change 4
reading only modificiations
change 0
change 1
change 2
change 3
change 4
another way to read modificiations
change 0
change 1
change 2
change 3
change 4 -
2. Re: Selecting Versions greater than the original
plaky Nov 11, 2008 6:06 AM (in response to scottr0829)Ooops, I forget:
With the first posibility "reading all modifications" there are really _only_ modifications, no deletes would be reported. The alternate way would show you all changes except the initial create. -
3. Re: Selecting Versions greater than the original
adamw Nov 12, 2008 3:07 AM (in response to scottr0829)Hello,
I guess plaky gave you the full answer.
The one point in which this may be made better, is to be able to use RevisionTypeProperty as a restriction. I'll add it in future versions.
--
Adam