/** * 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"); }
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(); }
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(); }
public void setUp() throws Exception { // madatory to call super class method super.setUp(); odmg = OJB.getInstance(); db = odmg.newDatabase(); db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE); }
/** * 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"); }
/** * create new PerformanceArticle objects and insert them into the RDBMS. * * <p>The number of objects to create is defined by <code>articleCount</code>. */ protected void insertNewArticles() throws Exception { Transaction tx = odmg.newTransaction(); long start = System.currentTimeMillis(); tx.begin(); for (int i = 0; i < articleCount; i++) { db.makePersistent(arr[i]); } tx.commit(); long stop = System.currentTimeMillis(); logger.info("inserting " + articleCount + " Objects: " + (stop - start) + " msec"); }
/** * updates all PerformanceArticles inserted by <code>insertNewArticles()</code>. All objects are * modified and changes are written to the RDBMS with an UPDATE. */ protected void updateExistingArticles() throws Exception { Transaction tx = odmg.newTransaction(); long start = System.currentTimeMillis(); tx.begin(); // update all objects for (int i = 0; i < articleCount; i++) { tx.lock(arr[i], Transaction.WRITE); arr[i].setPrice(arr[i].getPrice() * 1.95583); } tx.commit(); long stop = System.currentTimeMillis(); logger.info("updating " + articleCount + " Objects: " + (stop - start) + " msec"); }
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(); }