KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > compare > OJBPerfTest


1 package org.apache.ojb.compare;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.PreparedStatement JavaDoc;
5 import java.sql.ResultSet JavaDoc;
6 import java.sql.Statement JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.util.Collection JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.apache.ojb.broker.Identity;
13 import org.apache.ojb.broker.PersistenceBroker;
14 import org.apache.ojb.broker.PersistenceBrokerFactory;
15 import org.apache.ojb.broker.TestHelper;
16 import org.apache.ojb.broker.accesslayer.LookupException;
17 import org.apache.ojb.broker.query.Criteria;
18 import org.apache.ojb.broker.query.Query;
19 import org.apache.ojb.broker.query.QueryByCriteria;
20 import org.apache.ojb.broker.util.ObjectModification;
21 import org.apache.ojb.odmg.OJB;
22 import org.apache.ojb.odmg.TransactionExt;
23 import org.apache.ojb.otm.OTMConnection;
24 import org.apache.ojb.otm.OTMKit;
25 import org.apache.ojb.otm.kit.SimpleKit;
26 import org.apache.ojb.otm.lock.LockType;
27 import org.apache.ojb.performance.PerfArticle;
28 import org.apache.ojb.performance.PerfArticleImpl;
29 import org.apache.ojb.performance.PerfTest;
30 import org.odmg.Database;
31 import org.odmg.Implementation;
32 import org.odmg.ODMGException;
33 import org.odmg.OQLQuery;
34 import org.odmg.Transaction;
35
36 /**
37  * Multi-threaded performance test implementation classes for testing
38  * the PB-api, ODMG-api of OJB against native JDBC using
39  * the performance-package test classes.
40  *
41  * @version $Id: OJBPerfTest.java,v 1.1.2.5 2005/12/30 00:01:41 arminw Exp $
42  */

43 public class OJBPerfTest
44 {
45     // =====================================================================================
46
// Inner class, test handle using native JDBC
47
// =====================================================================================
48
public static class JdbcPerfTest extends PerfTest
49     {
50         private static final String JavaDoc TABLE_NAME = "PERF_ARTICLE";
51         // cast to int to avoid problems with DB field length
52
public static volatile int counter = (int) System.currentTimeMillis();
53         private PersistenceBroker broker;
54
55         public synchronized static Long JavaDoc nextKey()
56         {
57             return new Long JavaDoc(++counter);
58         }
59
60         public void init() throws Exception JavaDoc
61         {
62             if (broker == null)
63             {
64                 broker = PersistenceBrokerFactory.defaultPersistenceBroker();
65             }
66         }
67
68         public void tearDown() throws Exception JavaDoc
69         {
70             if (broker != null)
71             {
72                 broker.close();
73                 broker = null;
74             }
75         }
76
77         public String JavaDoc testName()
78         {
79             return "JDBC";
80         }
81
82         public int articleCount()
83         {
84             int result = 0;
85             try
86             {
87                 String JavaDoc sql = "SELECT COUNT(*) FROM " + TABLE_NAME;
88                 Connection JavaDoc con = getConnection();
89                 Statement JavaDoc stmt = con.createStatement();
90                 ResultSet JavaDoc rs = stmt.executeQuery(sql);
91                 rs.next();
92                 result = rs.getInt(1);
93                 rs.close();
94                 stmt.close();
95                 releaseConnection();
96             }
97             catch (Exception JavaDoc e)
98             {
99                 e.printStackTrace();
100             }
101             return result;
102         }
103
104         public void insertNewArticles(PerfArticle[] arr) throws Exception JavaDoc
105         {
106             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
107             buf.append("INSERT INTO ").append(TABLE_NAME);
108             buf.append(" (ARTICLE_ID, ARTICLE_NAME, MINIMUM_STOCK, PRICE, UNIT, STOCK, SUPPLIER_ID)");
109             buf.append(" VALUES (?,?,?,?,?,?,?)");
110             // lookup the connection (using OJB's con pooling support to make the test more fair)
111
Connection JavaDoc con = getConnection();
112             con.setAutoCommit(false);
113             for (int i = 0; i < arr.length; i++)
114             {
115                 // OJB doesn't use a PS-pool (normally the JDBC driver supports statement pooling)
116
// thus to make this test more fair lookup a new PS for each object
117
PreparedStatement JavaDoc stmt = con.prepareStatement(buf.toString());
118                 PerfArticle article = arr[i];
119                 // generate PK value
120
article.setArticleId(nextKey());
121                 stmt.setLong(1, article.getArticleId().longValue());
122                 stmt.setString(2, article.getArticleName());
123                 stmt.setInt(3, article.getMinimumStock());
124                 stmt.setDouble(4, article.getPrice());
125                 stmt.setString(5, article.getUnit());
126                 stmt.setInt(6, article.getStock());
127                 stmt.setInt(7, article.getSupplierId());
128                 stmt.executeUpdate();
129                 stmt.close();
130             }
131             con.commit();
132             con.setAutoCommit(true);
133             releaseConnection();
134         }
135
136         public void insertNewArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
137         {
138             System.out.println("Stress-Mode is NOT supported");
139         }
140
141         public Collection JavaDoc readArticlesByCursor(String JavaDoc articleName) throws Exception JavaDoc
142         {
143             String JavaDoc sql = "SELECT * FROM " + TABLE_NAME + " WHERE ARTICLE_NAME LIKE '" + articleName + "'";
144             Connection JavaDoc con = getConnection();
145             Statement JavaDoc stmt = con.createStatement();
146             ResultSet JavaDoc rs = stmt.executeQuery(sql);
147             ArrayList JavaDoc list = new ArrayList JavaDoc();
148             while (rs.next())
149             {
150                 PerfArticle article = new PerfArticleImpl();
151                 article.setArticleId(new Long JavaDoc(rs.getLong("ARTICLE_ID")));
152                 article.setArticleName(rs.getString("ARTICLE_NAME"));
153                 article.setMinimumStock(rs.getInt("MINIMUM_STOCK"));
154                 article.setPrice(rs.getDouble("PRICE"));
155                 article.setUnit(rs.getString("UNIT"));
156                 article.setStock(rs.getInt("STOCK"));
157                 article.setSupplierId(rs.getInt("SUPPLIER_ID"));
158                 list.add(article);
159             }
160             rs.close();
161             stmt.close();
162             releaseConnection();
163             return list;
164         }
165
166         public PerfArticle getArticleByIdentity(Long JavaDoc articleId) throws Exception JavaDoc
167         {
168             String JavaDoc sql = "SELECT * FROM " + TABLE_NAME + " WHERE ARTICLE_ID=" + articleId.longValue() + "";
169             Connection JavaDoc con = getConnection();
170             Statement JavaDoc stmt = con.createStatement();
171             ResultSet JavaDoc rs = stmt.executeQuery(sql);
172             PerfArticle result = null;
173             while (rs.next())
174             {
175                 result = new PerfArticleImpl();
176                 result.setArticleId(new Long JavaDoc(rs.getLong("ARTICLE_ID")));
177                 result.setArticleName(rs.getString("ARTICLE_NAME"));
178                 result.setMinimumStock(rs.getInt("MINIMUM_STOCK"));
179                 result.setPrice(rs.getDouble("PRICE"));
180                 result.setUnit(rs.getString("UNIT"));
181                 result.setStock(rs.getInt("STOCK"));
182                 result.setSupplierId(rs.getInt("SUPPLIER_ID"));
183             }
184             rs.close();
185             stmt.close();
186             releaseConnection();
187             return result;
188         }
189
190         public void updateArticles(PerfArticle[] arr) throws Exception JavaDoc
191         {
192             // we don't know which field is to update, thus do do all
193
StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
194             buf.append("UPDATE ").append(TABLE_NAME);
195             buf.append(" SET ARTICLE_NAME = ?, MINIMUM_STOCK = ?, PRICE = ?, UNIT = ?, STOCK = ?, SUPPLIER_ID = ?");
196             buf.append(" WHERE ARTICLE_ID = ?");
197             Connection JavaDoc con = getConnection();
198             con.setAutoCommit(false);
199             for (int i = 0; i < arr.length; i++)
200             {
201                 // OJB doesn't use a PS-pool (normally the JDBC driver supports statement pooling)
202
// thus to make this test more fair lookup a new PS for each object
203
PreparedStatement JavaDoc stmt = con.prepareStatement(buf.toString());
204                 PerfArticle article = arr[i];
205                 stmt.setString(1, article.getArticleName());
206                 stmt.setInt(2, article.getMinimumStock());
207                 stmt.setDouble(3, article.getPrice());
208                 stmt.setString(4, article.getUnit());
209                 stmt.setInt(5, article.getStock());
210                 stmt.setInt(6, article.getSupplierId());
211                 stmt.setLong(7, article.getArticleId().longValue());
212                 stmt.executeUpdate();
213                 stmt.close();
214             }
215             con.commit();
216             con.setAutoCommit(true);
217             releaseConnection();
218         }
219
220         public void updateArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
221         {
222             System.out.println("Stress-Mode is NOT supported");
223         }
224
225         public void deleteArticles(PerfArticle[] arr) throws Exception JavaDoc
226         {
227             String JavaDoc sql = "DELETE FROM " + TABLE_NAME + " WHERE ARTICLE_ID = ?";
228             Connection JavaDoc con = getConnection();
229             con.setAutoCommit(false);
230             for (int i = 0; i < arr.length; i++)
231             {
232                 // OJB doesn't use a PS-pool (normally the JDBC driver supports statement pooling)
233
// thus to make this test more fair lookup a new PS for each object
234
PreparedStatement JavaDoc stmt = con.prepareStatement(sql);
235                 PerfArticle article = arr[i];
236                 stmt.setLong(1, article.getArticleId().longValue());
237                 stmt.execute();
238                 stmt.close();
239             }
240             con.commit();
241             con.setAutoCommit(true);
242             releaseConnection();
243         }
244
245         public void deleteArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
246         {
247             System.out.println("Stress-Mode is NOT supported");
248         }
249
250         private Connection JavaDoc getConnection() throws LookupException
251         {
252             // don't let OJB handle batching
253
broker.serviceConnectionManager().setBatchMode(false);
254             return broker.serviceConnectionManager().getConnection();
255         }
256
257         private void releaseConnection()
258         {
259             broker.serviceConnectionManager().releaseConnection();
260         }
261     }
262
263
264
265     // =====================================================================================
266
// Inner class, test handle using PB-api
267
// =====================================================================================
268
public static class PBPerfTest extends PerfTest
269     {
270         public void init() throws Exception JavaDoc
271         {
272         }
273
274         public void tearDown() throws Exception JavaDoc
275         {
276         }
277
278         public String JavaDoc testName()
279         {
280             return "PB";
281         }
282
283         public int articleCount()
284         {
285             Criteria c = new Criteria();
286             Query q = new QueryByCriteria(PerfArticleImpl.class, c);
287             int count = 0;
288             try
289             {
290                 PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
291                 count = broker.getCount(q);
292                 broker.close();
293             }
294             catch (Exception JavaDoc e)
295             {
296                 e.printStackTrace();
297             }
298             return count;
299         }
300
301         /**
302          * A resource cumbering insert-method implementation,
303          * this was used to test implementation.
304          */

305         public void insertNewArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
306         {
307             for (int i = 0; i < arr.length; i++)
308             {
309                 PersistenceBroker broker = null;
310                 try
311                 {
312                     broker = PersistenceBrokerFactory.defaultPersistenceBroker();
313                     broker.beginTransaction();
314                     broker.store(arr[i]);
315                     broker.commitTransaction();
316                 }
317                 finally
318                 {
319                     if (broker != null) broker.close();
320                 }
321             }
322         }
323
324         /**
325          * A performance optimized insert-method implementation,
326          * used to test performance.
327          */

328         public void insertNewArticles(PerfArticle[] arr) throws Exception JavaDoc
329         {
330             PersistenceBroker broker = null;
331             try
332             {
333                 broker = PersistenceBrokerFactory.defaultPersistenceBroker();
334                 broker.serviceConnectionManager().setBatchMode(true);
335                 broker.beginTransaction();
336                 for (int i = 0; i < arr.length; i++)
337                 {
338                     broker.store(arr[i], ObjectModification.INSERT);
339                 }
340                 broker.commitTransaction();
341             }
342             finally
343             {
344                 if (broker != null) broker.close();
345             }
346         }
347
348         public Collection JavaDoc readArticlesByCursor(String JavaDoc articleName) throws Exception JavaDoc
349         {
350             Criteria c = new Criteria();
351             c.addLike("articleName", articleName);
352             Query q = new QueryByCriteria(PerfArticleImpl.class, c);
353
354             Collection JavaDoc col = null;
355             PersistenceBroker broker = null;
356             try
357             {
358                 broker = PersistenceBrokerFactory.defaultPersistenceBroker();
359                 col = broker.getCollectionByQuery(q);
360             }
361             finally
362             {
363                 if (broker != null) broker.close();
364             }
365             return col;
366         }
367
368         public PerfArticle getArticleByIdentity(Long JavaDoc articleId) throws Exception JavaDoc
369         {
370             PersistenceBroker broker = null;
371             try
372             {
373                 broker = PersistenceBrokerFactory.defaultPersistenceBroker();
374                 return (PerfArticle) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(PerfArticleImpl.class, articleId));
375             }
376             finally
377             {
378                 if (broker != null) broker.close();
379             }
380         }
381
382         public void updateArticles(PerfArticle[] arr) throws Exception JavaDoc
383         {
384             PersistenceBroker broker = null;
385             try
386             {
387                 broker = PersistenceBrokerFactory.defaultPersistenceBroker();
388                 broker.serviceConnectionManager().setBatchMode(true);
389                 broker.beginTransaction();
390                 for (int i = 0; i < arr.length; i++)
391                 {
392                     broker.store(arr[i], ObjectModification.UPDATE);
393                     // broker.store(arr[i]);
394
}
395                 broker.commitTransaction();
396             }
397             finally
398             {
399                 if (broker != null) broker.close();
400             }
401         }
402
403         public void updateArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
404         {
405             for (int i = 0; i < arr.length; i++)
406             {
407                 PersistenceBroker broker = null;
408                 try
409                 {
410                     broker = PersistenceBrokerFactory.defaultPersistenceBroker();
411                     broker.beginTransaction();
412                     broker.store(arr[i]);
413                     broker.commitTransaction();
414                 }
415                 finally
416                 {
417                     if (broker != null) broker.close();
418                 }
419             }
420         }
421
422         /**
423          * A resource cumbering delete-method implementation,
424          * used to test implementation
425          */

426         public void deleteArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
427         {
428             for (int i = 0; i < arr.length; i++)
429             {
430                 PersistenceBroker broker = null;
431                 try
432                 {
433                     broker = PersistenceBrokerFactory.defaultPersistenceBroker();
434                     broker.beginTransaction();
435                     broker.delete(arr[i]);
436                     broker.commitTransaction();
437                 }
438                 finally
439                 {
440                     if (broker != null) broker.close();
441                 }
442             }
443         }
444
445         /**
446          * A performance optimized delete-method implementation,
447          * used to test performance
448          */

449         public void deleteArticles(PerfArticle[] arr) throws Exception JavaDoc
450         {
451             PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
452             try
453             {
454                 broker.serviceConnectionManager().setBatchMode(true);
455                 broker.beginTransaction();
456                 for (int i = 0; i < arr.length; i++)
457                 {
458                     broker.delete(arr[i]);
459                 }
460                 broker.commitTransaction();
461             }
462             finally
463             {
464                 if (broker != null) broker.close();
465             }
466         }
467     }
468
469
470     // =====================================================================================
471
// Inner class, test handle using ODMG-api
472
// =====================================================================================
473
public static class ODMGPerfTest extends PerfTest
474     {
475         private Implementation odmg;
476         private Database db;
477         private TransactionExt m_tx;
478
479         public void init()
480         {
481             try
482             {
483                 odmg = OJB.getInstance();
484                 db = odmg.newDatabase();
485                 db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
486                 m_tx = (TransactionExt) odmg.newTransaction();
487             }
488             catch (ODMGException e)
489             {
490                 e.printStackTrace();
491             }
492         }
493
494         public void tearDown() throws Exception JavaDoc
495         {
496             if (m_tx.isOpen()) m_tx.abort();
497             //db.close();
498
}
499
500         public String JavaDoc testName()
501         {
502             return "ODMG";
503         }
504
505         public int articleCount()
506         {
507             Criteria c = new Criteria();
508             Query q = new QueryByCriteria(PerfArticleImpl.class, c);
509             int count = 0;
510             try
511             {
512                 PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
513                 count = broker.getCount(q);
514                 broker.close();
515             }
516             catch (Exception JavaDoc e)
517             {
518                 e.printStackTrace();
519             }
520             return count;
521         }
522
523         /**
524          * A performance optimized insert-method implementation,
525          * used to test performance
526          */

527         public void insertNewArticles(PerfArticle[] arr) throws Exception JavaDoc
528         {
529             m_tx.begin();
530             for (int i = 0; i < arr.length; i++)
531             {
532                 db.makePersistent(arr[i]);
533             }
534             m_tx.commit();
535         }
536
537         /**
538          * A resource cumbering insert-method implementation,
539          * used to test implementation
540          */

541         public void insertNewArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
542         {
543             for (int i = 0; i < arr.length; i++)
544             {
545                 Transaction tx = odmg.newTransaction();
546                 tx.begin();
547                 db.makePersistent(arr[i]);
548                 tx.commit();
549             }
550         }
551
552         public Collection JavaDoc readArticlesByCursor(String JavaDoc articleName) throws Exception JavaDoc
553         {
554             m_tx.setImplicitLocking(false);
555             m_tx.begin();
556             OQLQuery query = odmg.newOQLQuery();
557             String JavaDoc sql = "select allArticles from " + PerfArticleImpl.class.getName() +
558                     " where articleName like $1";
559             query.create(sql);
560             query.bind(articleName);
561             List JavaDoc allProducts = (List JavaDoc) query.execute();
562             m_tx.commit();
563             return allProducts;
564         }
565
566         public PerfArticle getArticleByIdentity(Long JavaDoc articleId) throws Exception JavaDoc
567         {
568 // m_tx.setImplicitLocking(false);
569
// m_tx.begin();
570
// OQLQuery query = odmg.newOQLQuery();
571
// String sql = "select allArticles from " + PerfArticleImpl.class.getName() +
572
// " where articleId=$";
573
// query.create(sql);
574
// query.bind(articleId);
575
// List result = (List) query.execute();
576
// m_tx.commit();
577
// return (PerfArticle) result.get(0);
578
// use OJB's extension for faster Identity lookup
579
PerfArticle result;
580             m_tx.setImplicitLocking(false);
581             m_tx.begin();
582             PersistenceBroker pb = m_tx.getBroker();
583             result = (PerfArticle) pb.getObjectByIdentity(pb.serviceIdentity().buildIdentity(PerfArticleImpl.class, articleId));
584             m_tx.commit();
585             return result;
586         }
587
588         public void updateArticles(PerfArticle[] arr) throws Exception JavaDoc
589         {
590             m_tx.begin();
591             for (int i = 0; i < arr.length; i++)
592             {
593                 m_tx.lock(arr[i], Transaction.WRITE);
594                 m_tx.markDirty(arr[i]);
595             }
596             m_tx.commit();
597         }
598
599         public void updateArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
600         {
601             for (int i = 0; i < arr.length; i++)
602             {
603                 Transaction tx = odmg.newTransaction();
604                 tx.begin();
605                 tx.lock(arr[i], Transaction.WRITE);
606                 m_tx.markDirty(arr[i]);
607                 tx.commit();
608             }
609         }
610
611         /**
612          * A performance optimized delete-method implementation,
613          * use to test performance
614          */

615         public void deleteArticles(PerfArticle[] arr) throws Exception JavaDoc
616         {
617             m_tx.begin();
618             for (int i = 0; i < arr.length; i++)
619             {
620                 db.deletePersistent(arr[i]);
621             }
622             m_tx.commit();
623         }
624
625         /**
626          * A resource cumbering insert-method implementation,
627          * use to test implementation
628          */

629         public void deleteArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
630         {
631             for (int i = 0; i < arr.length; i++)
632             {
633                 Transaction tx = odmg.newTransaction();
634                 tx.begin();
635                 db.deletePersistent(arr[i]);
636                 tx.commit();
637             }
638         }
639     }
640
641     // =====================================================================================
642
// Inner class, test handle using OTM-api
643
// =====================================================================================
644
public static class OTMPerfTest extends PerfTest
645     {
646         private OTMKit _kit;
647
648         private OTMConnection _conn;
649
650         private org.apache.ojb.otm.core.Transaction _tx;
651
652         public void init()
653         {
654             _kit = SimpleKit.getInstance();
655             _conn = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
656         }
657
658         public void tearDown() throws Exception JavaDoc
659         {
660             if ((_tx != null) && _tx.isInProgress())
661             {
662                 _tx.rollback();
663             }
664             _conn.close();
665         }
666
667         public String JavaDoc testName()
668         {
669             return "OTM";
670         }
671
672         public int articleCount()
673         {
674             Criteria c = new Criteria();
675             Query q = new QueryByCriteria(PerfArticleImpl.class, c);
676             int count = 0;
677             try
678             {
679                 PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
680                 count = broker.getCount(q);
681                 broker.close();
682             }
683             catch (Exception JavaDoc e)
684             {
685                 e.printStackTrace();
686             }
687             return count;
688         }
689
690         /**
691          * A resource cumbering insert-method implementation,
692          * this was used to test implementation.
693          */

694         public void insertNewArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
695         {
696             for (int i = 0; i < arr.length; i++)
697             {
698                 _tx = _kit.getTransaction(_conn);
699                 _tx.begin();
700                 _conn.makePersistent(arr[i]);
701                 _tx.commit();
702             }
703         }
704
705         /**
706          * A performance optimized insert-method implementation,
707          * used to test performance.
708          */

709         public void insertNewArticles(PerfArticle[] arr) throws Exception JavaDoc
710         {
711             _tx = _kit.getTransaction(_conn);
712             _tx.begin();
713             for (int i = 0; i < arr.length; i++)
714             {
715                 _conn.makePersistent(arr[i]);
716             }
717             _tx.commit();
718         }
719
720         public Collection JavaDoc readArticlesByCursor(String JavaDoc articleName) throws Exception JavaDoc
721         {
722             Criteria c = new Criteria();
723             c.addLike("articleName", articleName);
724             Query q = new QueryByCriteria(PerfArticleImpl.class, c);
725
726             _tx = _kit.getTransaction(_conn);
727             _tx.begin();
728             Collection JavaDoc col = _conn.getCollectionByQuery(q, LockType.NO_LOCK);
729             _tx.commit();
730             return col;
731         }
732
733         public PerfArticle getArticleByIdentity(Long JavaDoc articleId) throws Exception JavaDoc
734         {
735             Criteria c = new Criteria();
736             c.addEqualTo("articleId", articleId);
737             Query q = new QueryByCriteria(PerfArticleImpl.class, c);
738
739             _tx = _kit.getTransaction(_conn);
740             _tx.begin();
741             // the getByIdeneityMethod() needs Identity and this is currently not supported
742
Collection JavaDoc col = _conn.getCollectionByQuery(q, LockType.NO_LOCK);
743             _tx.commit();
744             Iterator JavaDoc it = col.iterator();
745             return it.hasNext() ? (PerfArticle) it.next() : null;
746         }
747
748         public void updateArticles(PerfArticle[] arr) throws Exception JavaDoc
749         {
750             _tx = _kit.getTransaction(_conn);
751             _tx.begin();
752             for (int i = 0; i < arr.length; i++)
753             {
754                 Identity oid = _conn.getIdentity(arr[i]);
755                 PerfArticle a = (PerfArticle) _conn.getObjectByIdentity(oid, LockType.WRITE_LOCK);
756                 a.setArticleName("" + System.currentTimeMillis());
757             }
758             _tx.commit();
759         }
760
761         public void updateArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
762         {
763             for (int i = 0; i < arr.length; i++)
764             {
765                 _tx = _kit.getTransaction(_conn);
766                 _tx.begin();
767                 Identity oid = _conn.getIdentity(arr[i]);
768                 PerfArticle a = (PerfArticle) _conn.getObjectByIdentity(oid, LockType.WRITE_LOCK);
769                 a.setArticleName("" + System.currentTimeMillis());
770                 _tx.commit();
771             }
772         }
773
774         /**
775          * A resource cumbering delete-method implementation,
776          * used to test implementation
777          */

778         public void deleteArticlesStress(PerfArticle[] arr) throws Exception JavaDoc
779         {
780             for (int i = 0; i < arr.length; i++)
781             {
782                 _tx = _kit.getTransaction(_conn);
783                 _tx.begin();
784                 _conn.deletePersistent(arr[i]);
785                 _tx.commit();
786             }
787         }
788
789         /**
790          * A performance optimized delete-method implementation,
791          * used to test performance
792          */

793         public void deleteArticles(PerfArticle[] arr) throws Exception JavaDoc
794         {
795             _tx = _kit.getTransaction(_conn);
796             _tx.begin();
797             for (int i = 0; i < arr.length; i++)
798             {
799                 _conn.deletePersistent(arr[i]);
800             }
801             _tx.commit();
802         }
803     }
804 }
805
Popular Tags