예제 #1
0
  /**
   * read in all the PerformanceArticles from the RDBMS that have been inserted by <code>
   * insertNewArticles()</code>. The lookup is done with a cursor fetch, that is: a between
   * Statement is used to select all inserted PerformanceArticles and Objects are read in by
   * fetching from the cursor (JDBC ResultSet).
   */
  protected void readArticlesByCursor() throws Exception {
    TransactionExt tx = (TransactionExt) odmg.newTransaction();
    // we don't want implicite locks when compare performance
    tx.setImplicitLocking(false);
    tx.begin();
    // clear cache to read from DB
    tx.getBroker().clearCache();

    long start = System.currentTimeMillis();
    OQLQuery query = odmg.newOQLQuery();
    String sql =
        "select allArticles from "
            + PerformanceArticle.class.getName()
            + " where articleId between "
            + new Integer(offsetId)
            + " and "
            + new Integer(offsetId + articleCount);
    query.create(sql);
    ManageableCollection collection = (ManageableCollection) query.execute();
    Iterator iter = collection.ojbIterator();
    int fetchCount = 0;
    while (iter.hasNext()) {
      fetchCount++;
      iter.next();
    }
    long stop = System.currentTimeMillis();
    logger.info("fetching " + fetchCount + " Objects: " + (stop - start) + " msec");
  }
예제 #2
0
  public void testTransactionFlush_2() throws Exception {
    String name = "testTransactionFlush_2_" + System.currentTimeMillis();
    TransactionExt tx = (TransactionExt) odmg.newTransaction();

    tx.begin();
    PersistenceBroker broker = tx.getBroker();

    ODMGZoo obj = new ODMGZoo();
    obj.setName(name);
    tx.lock(obj, Transaction.WRITE);
    tx.flush();
    // System.err.println("First flush call, insert new object");

    // PB to query
    Criteria crit = new Criteria();
    crit.addEqualTo("name", obj.getName());
    QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit);
    // we flushed all objects, thus we should found object in DB/cache
    Iterator it = broker.getIteratorByQuery(query);
    assertTrue(it.hasNext());
    ODMGZoo other = (ODMGZoo) it.next();
    assertNotNull(other);
    assertEquals(obj.getZooId(), other.getZooId());
    assertEquals(obj.getName(), other.getName());
    assertFalse(it.hasNext());

    /** * Charles : Start ** */
    // Let's flush, change the name and flush again
    tx.flush();
    // System.err.println("Second flush call, nothing to do");
    obj.setName("updated_" + name);
    tx.flush();
    // System.err.println("Third flush call, update");
    OQLQuery q = odmg.newOQLQuery();
    q.create("select zoos from " + ODMGZoo.class.getName() + " where name like $1");
    q.bind("updated_" + name);

    // Redo the query - we should find the object again
    it = ((Collection) q.execute()).iterator();
    assertTrue(it.hasNext());
    other = (ODMGZoo) it.next();
    assertNotNull(other);
    assertEquals(obj.getZooId(), other.getZooId());
    assertEquals(obj.getName(), other.getName());
    assertFalse(it.hasNext());
    /** * Charles : End ** */

    // now we abort tx, so all flushed objects shouldn't be found
    // in further queries
    tx.abort();

    tx = (TransactionExt) odmg.newTransaction();
    tx.begin();
    broker = tx.getBroker();
    QueryByIdentity query2 = new QueryByIdentity(obj);
    Object result = broker.getObjectByQuery(query2);
    tx.commit();

    assertNull("We should not find objects from aborted tx", result);
  }
예제 #3
0
 protected int getDBObjectCountViaOqlQueryUseNewTransaction(Implementation odmg, Class target)
     throws Exception {
   Transaction tx = odmg.newTransaction();
   tx.begin();
   OQLQuery query = odmg.newOQLQuery();
   query.create("select allODMGGourmets from " + target.getName());
   List list = (List) query.execute();
   tx.commit();
   return list.size();
 }
예제 #4
0
 protected void deleteAll(Implementation odmg, Class target) throws Exception {
   TransactionExt tx = (TransactionExt) odmg.newTransaction();
   tx.begin();
   tx.setCascadingDelete(target, true);
   OQLQuery query = odmg.newOQLQuery();
   query.create("select allObjects from " + target.getName());
   List list = (List) query.execute();
   for (int i = 0; i < list.size(); i++) {
     Object obj = list.get(i);
     database.deletePersistent(obj);
   }
   tx.commit();
 }
예제 #5
0
 /**
  * read in all the PerformanceArticles from the RDBMS that have been inserted by <code>
  * insertNewArticles()</code>. The lookup is done one by one, that is: a primary key based lookup
  * is used.
  */
 protected void readArticles() throws Exception {
   TransactionExt tx = (TransactionExt) odmg.newTransaction();
   // we don't want implicite locks when compare performance
   tx.setImplicitLocking(false);
   String sql =
       "select allArticles from " + PerformanceArticle.class.getName() + " where articleId=$1";
   long start = System.currentTimeMillis();
   tx.begin();
   for (int i = 0; i < articleCount; i++) {
     OQLQuery query = odmg.newOQLQuery();
     query.create(sql);
     query.bind(arr[i].getArticleId());
     query.execute();
   }
   tx.commit();
   long stop = System.currentTimeMillis();
   logger.info("querying " + articleCount + " Objects: " + (stop - start) + " msec");
 }
예제 #6
0
  public void testCheckCacheAfterRollback() throws Exception {
    RollbackObjectOne ro = null;
    RollbackObjectOne ro_2 = null;
    String name = "testCheckCacheAfterRollback_" + System.currentTimeMillis();

    Transaction tx = odmg.newTransaction();
    tx.begin();
    ro = new RollbackObjectOne();
    ro.setName(name);
    tx.lock(ro, Transaction.WRITE);

    ro_2 = new RollbackObjectOne();
    ro_2.setName(name);
    tx.lock(ro_2, Transaction.WRITE);
    tx.commit();

    tx = odmg.newTransaction();
    tx.begin();
    OQLQuery query = odmg.newOQLQuery();
    query.create("select all from " + RollbackObjectOne.class.getName() + " where name like $1");
    query.bind(name);
    List list = (List) query.execute();
    tx.commit();
    assertEquals(2, list.size());

    tx = odmg.newTransaction();
    tx.begin();
    tx.lock(ro, Transaction.WRITE);
    ro = new RollbackObjectOne();
    ro.setDescription(name);

    tx.lock(ro_2, Transaction.WRITE);
    ro_2 = new RollbackObjectOne();
    ro_2.setDescription(name);

    tx.abort();

    tx = odmg.newTransaction();
    tx.begin();
    query = odmg.newOQLQuery();
    query.create("select all from " + RollbackObjectOne.class.getName() + " where name like $1");
    query.bind(name);
    list = (List) query.execute();
    tx.commit();
    assertEquals(2, list.size());
    assertNull(((RollbackObjectOne) list.get(0)).getDescription());
    assertNull(((RollbackObjectOne) list.get(1)).getDescription());

    // after tx another tx should be able to lock these objects
    TransactionImpl tx2 = (TransactionImpl) odmg.newTransaction();
    tx2.begin();
    try {
      Iterator it = list.iterator();
      while (it.hasNext()) {
        Object o = it.next();
        tx2.lock(o, Transaction.WRITE);
      }
    } finally {
      tx2.abort();
    }
  }
예제 #7
0
 protected int getDBObjectCountViaOqlQuery(Implementation odmg, Class target) throws Exception {
   OQLQuery query = odmg.newOQLQuery();
   query.create("select allObjects from " + target.getName());
   List list = (List) query.execute();
   return list.size();
 }