public void conc(ExtObjectContainer oc) { Query q = oc.query(); q.constrain(QueryForUnknownFieldTestCase.class); q.descend("_name").constrain("name"); Assert.areEqual(1, q.execute().size()); q = oc.query(); q.constrain(QueryForUnknownFieldTestCase.class); q.descend("name").constrain("name"); Assert.areEqual(0, q.execute().size()); }
public void conc(ExtObjectContainer oc) { oc.queryByExample((new QueryNonExistantTestCase(true))); assertOccurrences(oc, QueryNonExistantTestCase.class, 0); Query q = oc.query(); q.constrain(new QueryNonExistantTestCase(true)); Assert.areEqual(0, q.execute().size()); }
public void testQueryEvents() { EventRegistry registry = EventRegistryFactory.forObjectContainer(db()); EventRecorder recorder = new EventRecorder(fileSession().lock()); registry.queryStarted().addListener(recorder); registry.queryFinished().addListener(recorder); Assert.areEqual(0, recorder.size()); Query q = db().query(); q.execute(); Assert.areEqual(2, recorder.size()); EventRecord e1 = recorder.get(0); Assert.areSame(registry.queryStarted(), e1.e); Assert.areSame(q, ((QueryEventArgs) e1.args).query()); EventRecord e2 = recorder.get(1); Assert.areSame(registry.queryFinished(), e2.e); Assert.areSame(q, ((QueryEventArgs) e2.args).query()); recorder.clear(); registry.queryStarted().removeListener(recorder); registry.queryFinished().removeListener(recorder); db().query().execute(); Assert.areEqual(0, recorder.size()); }
public void handleRevisions( EClass eClass, CDOBranch branch, long timeStamp, boolean exactTime, CDORevisionHandler handler) { Query query = getObjectContainer().query(); query.constrain(DB4ORevision.class); if (eClass != null) { query .descend(DB4ORevision.ATTRIBUTE_PACKAGE_NS_URI) .constrain(eClass.getEPackage().getNsURI()); query.descend(DB4ORevision.ATTRIBUTE_CLASS_NAME).constrain(eClass.getName()); } ObjectSet<?> revisions = query.execute(); if (revisions.isEmpty()) { return; } for (Object revision : revisions.toArray()) { CDORevision cdoRevision = DB4ORevision.getCDORevision(getStore(), (DB4ORevision) revision); handler.handleRevision(cdoRevision); } }
private Item itemByName(String string) { Query q = db().query(); q.constrain(Item.class); q.descend("_name").constrain(string); Object object = q.execute().next(); return (Item) object; }
/** * Creates an {@link AttachedDevice} resource in the DataBase and validates the transaction * * @param resource - The {@link AttachedDevice} resource to create */ public void create(AttachedDevice resource) { // Store the created resource DB.store(resource); // MgmtObjs MgmtObjs mgmtObjs = new MgmtObjs(); mgmtObjs.setUri(resource.getMgmtObjsReference()); mgmtObjs.setCreationTime(resource.getCreationTime()); mgmtObjs.setLastModifiedTime(resource.getLastModifiedTime()); mgmtObjs.setAccessRightID(resource.getAccessRightID()); DAOFactory.getMgmtObjsDAO().create(mgmtObjs); // Subscriptions Subscriptions subscriptions = new Subscriptions(); subscriptions.setUri(resource.getSubscriptionsReference()); DAOFactory.getSubscriptionsDAO().create(subscriptions); // Create the query based on the uri constraint Query query = DB.query(); query.constrain(AttachedDevices.class); query.descend("uri").constrain(resource.getUri().split("/" + resource.getId())[0]); // Store all the founded resources ObjectSet<AttachedDevices> result = query.execute(); // Update the lastModifiedTime attribute of the parent AttachedDevices attachedDevices = result.get(0); // Update the lastModifiedTime attribute of the parent attachedDevices.setLastModifiedTime( DateConverter.toXMLGregorianCalendar(new Date()).toString()); DB.store(attachedDevices); // Validate the current transaction commit(); }
public void testLastOrderWins() { Query query = newQuery(Data.class); query.descend("_id").orderDescending(); query.descend("_id").orderAscending(); query.descend("_id").constrain(new Integer(0)).greater(); assertOrdered(query.execute()); }
private Item storedItem(String id) { Query query = newQuery(Item.class); query.descend("_id").constrain(id); ObjectSet<Item> result = query.execute(); Assert.isTrue(result.hasNext()); return result.next(); }
private void restoreMembers(Data data) { Query q = newQuery(Data.class); ObjectSet objectSet = q.execute(); Data rdata = (Data) objectSet.next(); data.i_map = rdata.i_map; data.i_helper = rdata.i_helper; }
@SuppressWarnings("unchecked") private void garbageCollectIdentities() { final MessageManager messageManager = mFreetalk.getMessageManager(); final PersistentTaskManager taskManager = mFreetalk.getTaskManager(); synchronized (this) { if (mIdentityFetchInProgress || mOwnIdentityFetchInProgress || mLastIdentityFetchTime == 0 || mLastOwnIdentityFetchTime == 0) return; /* Executing the thread loop once will always take longer than THREAD_PERIOD. Therefore, if we set the limit to 3*THREAD_PERIOD, * it will hit identities which were last received before more than 2*THREAD_LOOP, not exactly 3*THREAD_LOOP. */ long lastAcceptTime = Math.min(mLastIdentityFetchTime, mLastOwnIdentityFetchTime) - GARBAGE_COLLECT_DELAY; lastAcceptTime = Math.max( lastAcceptTime, 0); // This is not really needed but a time less than 0 does not make sense.; Query q = db.query(); q.constrain(WoTIdentity.class); q.descend("mLastReceivedFromWoT").constrain(lastAcceptTime).smaller(); ObjectSet<WoTIdentity> result = q.execute(); for (WoTIdentity identity : result) { identity.initializeTransient(mFreetalk); Logger.debug(this, "Garbage collecting identity " + identity); deleteIdentity(identity, messageManager, taskManager); } if (mShortestUniqueNicknameCacheNeedsUpdate) updateShortestUniqueNicknameCache(); } }
public long size(ObjectContainer container) { Query query = container.query(); query.constrain(PersistentCooldownQueueItem.class); query.descend("parent").constrain(this).identity(); ObjectSet<PersistentCooldownQueueItem> results = query.execute(); return results.size(); }
@SuppressWarnings("unchecked") private ObjectSet executeSODAQuery(final A a, Evaluation e) { Query q = db().query(); q.constrain(e); ObjectSet set = q.execute(); return set; }
public void _test() throws Exception { Query query = newQuery(); query.constrain(new TestEvaluation()); query.constrain(Item.class); query.descend("name").orderDescending(); ObjectSet set = query.execute(); Assert.areEqual(3, set.size()); }
public void concRead(ExtObjectContainer oc) { for (int i = 0; i < COUNT; i++) { Query q = oc.query(); q.constrain(Atom.class); q.descend("name").constrain("ibi" + i); ObjectSet objectSet = q.execute(); Assert.areEqual(1, objectSet.size()); Atom child = (Atom) objectSet.next(); q = oc.query(); q.constrain(IndexedByIdentityTestCase.class); q.descend("atom").constrain(child).identity(); objectSet = q.execute(); Assert.areEqual(1, objectSet.size()); IndexedByIdentityTestCase ibi = (IndexedByIdentityTestCase) objectSet.next(); Assert.areSame(child, ibi.atom); } }
public void concUpdateSameObject(ExtObjectContainer oc, int seq) throws Exception { Query query = oc.query(); query.descend("_s").constrain(testString + COUNT / 2); ObjectSet result = query.execute(); Assert.areEqual(1, result.size()); SimpleObject o = (SimpleObject) result.next(); o.setI(COUNT + seq); oc.store(o); }
public void testAllThere() throws Exception { for (int i = 0; i < FOOS.length; i++) { Query q = createQuery(FOOS[i]); ObjectSet objectSet = q.execute(); Assert.areEqual(1, objectSet.size()); FieldIndexItem fii = (FieldIndexItem) objectSet.next(); Assert.areEqual(FOOS[i], fii.foo); } }
public void checkUpdateSameObject(ExtObjectContainer oc) throws Exception { Query query = oc.query(); query.descend("_s").constrain(testString + COUNT / 2); ObjectSet result = query.execute(); Assert.areEqual(1, result.size()); SimpleObject o = (SimpleObject) result.next(); int i = o.getI(); Assert.isTrue(COUNT <= i && i < COUNT + threadCount()); }
private void assertQueryForTimestamp(Item expected, long timestamp) { Query query = db().query(); query.constrain(Item.class); query.descend(VirtualField.COMMIT_TIMESTAMP).constrain(timestamp); ObjectSet<Object> objectSet = query.execute(); Assert.areEqual(1, objectSet.size()); Item actual = (Item) objectSet.next(); Assert.areSame(expected, actual); }
// TODO: This function should be a feature of WoT. @SuppressWarnings("unchecked") private synchronized void updateShortestUniqueNicknameCache() { Logger.debug(this, "Updating shortest unique nickname cache..."); // We don't use getAllIdentities() because we do not need to have intializeTransient() called on // each identity, we only query strings anyway. final Query q = db.query(); q.constrain(WoTIdentity.class); ObjectSet<WoTIdentity> result = q.execute(); final WoTIdentity[] identities = result.toArray(new WoTIdentity[result.size()]); Arrays.sort( identities, new Comparator<WoTIdentity>() { public int compare(WoTIdentity i1, WoTIdentity i2) { return i1.getFreetalkAddress().compareToIgnoreCase(i2.getFreetalkAddress()); } }); final String[] nicknames = new String[identities.length]; for (int i = 0; i < identities.length; ++i) { nicknames[i] = identities[i].getNickname(); int minLength = nicknames[i].length(); int firstDuplicate; do { firstDuplicate = i; while ((firstDuplicate - 1) >= 0 && nicknames[firstDuplicate - 1].equalsIgnoreCase(nicknames[i])) { --firstDuplicate; } if (firstDuplicate < i) { ++minLength; for (int j = i; j >= firstDuplicate; --j) { nicknames[j] = identities[j].getFreetalkAddress(minLength); } } } while (firstDuplicate != i); } final HashMap<String, String> newCache = new HashMap<String, String>(identities.length * 2); for (int i = 0; i < identities.length; ++i) newCache.put(identities[i].getID(), nicknames[i]); mShortestUniqueNicknameCache = newCache; mShortestUniqueNicknameCacheNeedsUpdate = false; Logger.debug(this, "Finished updating shortest unique nickname cache."); }
private PersistentEntry retrieveEntry(String dbID, String key) { // Use SODA query over Native Query for better performance Query query = getObjectContainer(dbID).query(); query.constrain(PersistentEntry.class); query.descend("key").constrain(key); ObjectSet<PersistentEntry> result = query.execute(); if (result.size() > 0) { return result.get(0); } return null; }
public void testIdentity() { Query q = st.query(); q.constrain(new STInteger(1)); ObjectSet set = q.execute(); STInteger identityConstraint = (STInteger) set.next(); identityConstraint.i_int = 9999; q = st.query(); q.constrain(identityConstraint).identity(); identityConstraint.i_int = 1; st.expectOne(q, store()[1]); }
public void test() { Query q = st.query(); Object[] r = store(); q.constrain(new Helper("aaa")); ObjectSet os = q.execute(); Helper helperA = (Helper) os.next(); q = st.query(); q.constrain(STIdentityEvaluation.class); q.descend("helper").constrain(helperA).identity(); q.constrain(new IncludeAllEvaluation()); st.expect(q, new Object[] {r[1], r[2], r[3]}); }
public void concUpdate(ExtObjectContainer oc, int seq) throws Exception { Query q = oc.query(); q.constrain(IndexedByIdentityTestCase.class); ObjectSet os = q.execute(); Assert.areEqual(COUNT, os.size()); while (os.hasNext()) { IndexedByIdentityTestCase idi = (IndexedByIdentityTestCase) os.next(); idi.atom.name = "updated" + seq; oc.store(idi); Thread.sleep(100); } }
public void testQuery() { Query q = Test.query(); ObjectSet objectSet = q.execute(); Test.ensure(objectSet.size() >= 2); int i = 0; while (objectSet.hasNext()) { Object obj = objectSet.next(); Test.ensure(obj != null); i++; } Test.ensure(i >= 2); }
public void testDelete() { ExtObjectContainer oc = fixture().db(); initGenericObjects(); ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME); Assert.isNotNull(rc); Query q = oc.query(); q.constrain(rc); ObjectSet results = q.execute(); while (results.hasNext()) { Object o = results.next(); oc.delete(o); } oc.commit(); // now query to make sure there are none left q = oc.query(); q.constrain(rc); q.descend("surname").constrain("John"); results = q.execute(); Assert.isTrue(results.size() == 0); }
public void testUpdate() { ExtObjectContainer oc = fixture().db(); initGenericObjects(); // Db4oUtil.dump(oc); ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME); Assert.isNotNull(rc); Query q = oc.query(); q.constrain(rc); ObjectSet results = q.execute(); // Db4oUtil.dumpResults(oc, results); Assert.isTrue(results.size() == 1); }
public void testNotIdentity() { Query q = st.query(); q.constrain(new STInteger(1)); ObjectSet set = q.execute(); STInteger identityConstraint = (STInteger) set.next(); identityConstraint.i_int = 9080; q = st.query(); q.constrain(identityConstraint).identity().not(); identityConstraint.i_int = 1; Object[] r = store(); st.expect(q, new Object[] {r[0], r[2], r[3]}); }
public void concUpdateDifferentObject(ExtObjectContainer oc, int seq) throws Exception { Query query = oc.query(); query .descend("_s") .constrain(testString + seq) .and(query.descend("_i").constrain(new Integer(seq))); ObjectSet result = query.execute(); Assert.areEqual(1, result.size()); SimpleObject o = (SimpleObject) result.next(); o.setI(seq + COUNT); oc.store(o); }
public List filtrar(Class classe, Evaluation filtro, String campoOrdem, int ordem) { Query query = bd.query(); query.constrain(classe); query.constrain(filtro); if (ORDENACAO_CRESCENTE == ordem) { query.descend(campoOrdem).orderAscending(); } else { query.descend(campoOrdem).orderDescending(); } return query.execute(); }
public void testQueryForVersionNumber() { store(new Item(NEWER)); db().commit(); Item newer = itemByName(NEWER); long version = version(newer); Query query = db().query(); query.descend(VirtualField.COMMIT_TIMESTAMP).constrain(new Long(version)).smaller().not(); ObjectSet<Item> set = query.execute(); Assert.areEqual(1, set.size()); Assert.areSame(newer, set.next()); }