private void queryForPeople() { Extent<Person> persons = pm.getExtent(Person.class); System.out.println(">> Query for People instances returned results:"); for (Person person : persons) { System.out.println(">> - " + person.getName()); } }
public <T> Extent<T> getExtent(Class<T> pcClass, boolean subclasses) { return getPM().getExtent(pcClass, subclasses); }
public <T> Extent<T> getExtent(Class<T> pcClass) { return getPM().getExtent(pcClass); }
private void queryForPeople() { Extent<Person> persons = pm.getExtent(Person.class); System.out.println(">> Query for People instances returned results:"); for (Person person : persons) { System.out.println(">> - " + person.getName()); } }
@Programmatic @Override public void deleteAll(final Class<?>... pcClasses) { for (final Class<?> pcClass : pcClasses) { final Extent<?> extent = getJdoPersistenceManager().getExtent(pcClass); final List<Object> instances = Lists.newArrayList(extent.iterator()); // temporarily disable concurrency checking while this method is performed try { ConcurrencyChecking.executeWithConcurrencyCheckingDisabled(new Callable<Void>() { @Override public Void call() { getJdoPersistenceManager().deletePersistentAll(instances); return null; } }); } catch (final Exception ex) { throw new FatalException(ex); } } }
private void checkSchemaCount(PersistenceManager pm, int expected) { Extent<?> e = pm.getExtent(ZooClassDef.class); int n = 0; for (Object o: e) { assertNotNull(o); n++; } assertEquals(SCHEMA_COUNT + expected, n); }
private void deletePersistentAll(PersistenceManager pm, Class<?> clazz) { pm.newQuery(pm.getExtent(clazz,false)).deletePersistentAll(); }
private void count(PersistenceManager pm, Class<?> cls, int nExp) { int nExt = 0; for (Object o: pm.getExtent(cls, false)) { assertNotNull(o); nExt++; } int nQ = 0; Collection<?> c = (Collection<?>) pm.newQuery(pm.getExtent(cls, false)).execute(); for (Object o: c) { assertNotNull(o); nQ++; } assertEquals(nExp, nExt); assertEquals(nExp, nQ); }
@Override public void run() { Extent<TestSuper> ext = pm.getExtent(TestSuper.class); Iterator<TestSuper> iter = ext.iterator(); while (iter.hasNext() && n < N/2) { pm.deletePersistent(iter.next()); n++; if (n % COMMIT_INTERVAL == 0) { pm.currentTransaction().commit(); pm.currentTransaction().begin(); ext = pm.getExtent(TestSuper.class); iter = ext.iterator(); } } ext.closeAll(); } });
@Before public void beforeTest() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); pm.newQuery(pm.getExtent(TestClass.class)).deletePersistentAll(); pm.newQuery(pm.getExtent(TestClassTiny.class)).deletePersistentAll(); pm.newQuery(pm.getExtent(TestClassTiny2.class)).deletePersistentAll(); pm.currentTransaction().commit(); TestTools.closePM(); }
@Before public void beforeTest() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); pm.newQuery(pm.getExtent(TestClass.class)).deletePersistentAll(); pm.newQuery(pm.getExtent(TestClassTiny.class)).deletePersistentAll(); pm.newQuery(pm.getExtent(TestClassTiny2.class)).deletePersistentAll(); pm.currentTransaction().commit(); TestTools.closePM(); }
public List<BuildDefinition> getAllBuildDefinitions() throws ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( BuildDefinition.class, true ); Query query = pm.newQuery( extent ); List result = (List) query.execute(); return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); } finally { tx.commit(); rollback( tx ); } }
public List<ProjectScmRoot> getProjectScmRootByProjectGroup( int projectGroupId ) { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( ProjectScmRoot.class, true ); Query query = pm.newQuery( extent, "projectGroup.id == " + projectGroupId ); List result = (List) query.execute(); result = (List) pm.detachCopyAll( result ); tx.commit(); return result; } finally { rollback( tx ); } }
public List<BuildQueue> getAllBuildQueues() throws ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( BuildQueue.class, true ); Query query = pm.newQuery( extent ); List result = (List) query.execute(); return result == null ? Collections.EMPTY_LIST : (List<BuildQueue>) pm.detachCopyAll( result ); } finally { tx.commit(); rollback( tx ); } }
private void deleteAllBatched(PersistenceManager pm, Class<?> clazz) { int batchSize = 10000; int commitctr = 0; Extent<?> extent = pm.getExtent(clazz,false); Iterator<?> it = extent.iterator(); while(it.hasNext()){ pm.deletePersistent(it.next()); if ( batchSize > 0 && ++commitctr >= batchSize){ commitctr = 0; pm.currentTransaction().commit(); pm.currentTransaction().begin(); } } extent.closeAll(); }
@Test public void testNewQueryExtentFilter() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); Extent<?> ext = pm.getExtent(TestClass.class); Query q = pm.newQuery(ext, "_int >= 123"); List<?> c = (List<?>) q.execute(); assertEquals(3, c.size()); TestTools.closePM(pm); }
public List<RepositoryPurgeConfiguration> getRepositoryPurgeConfigurationsBySchedule( int scheduleId ) { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( RepositoryPurgeConfiguration.class, true ); Query query = pm.newQuery( extent ); query.declareParameters( "int scheduleId" ); query.setFilter( "this.schedule.id == scheduleId" ); List result = (List) query.execute( scheduleId ); return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); } finally { tx.commit(); rollback( tx ); } }
@Test public void testBarcelonaDelete(){ PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); Extent<TC4> extent = pm.getExtent(TC4.class, false); Iterator<TC4> it = extent.iterator(); while(it.hasNext()){ pm.deletePersistent(it.next()); //addToCheckSum(5); } extent.closeAll(); pm.currentTransaction().commit(); TestTools.closePM(); }
@Test public void testQueryOfExtent() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); Extent<?> ext = pm.getExtent(TestClass.class); Query q = pm.newQuery(ext); assertEquals(pm, q.getPersistenceManager()); assertFalse(q.isUnmodifiable()); testDeclarative(q); testString(q); TestTools.closePM(pm); }
@Test public void testQueryWhereSuperClassDoesNotContainAttribute() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); TestClassTiny t1 = new TestClassTiny(); pm.makePersistent(t1); TestClassTiny2 t2 = new TestClassTiny2(); pm.makePersistent(t2); pm.currentTransaction().commit(); pm.currentTransaction().begin(); //now query for i2. String filter = "this.i2 == param"; Query query = pm.newQuery(pm.getExtent(TestClassTiny2.class,true), filter); query.declareParameters("int param"); Collection<?> c = (Collection<?>) query.execute(0); assertEquals(1, c.size()); TestTools.closePM(); }