1 19 20 package org.polepos.teams.hibernate; 21 22 import org.polepos.circuits.melbourne.*; 23 import org.polepos.teams.hibernate.data.*; 24 25 import net.sf.hibernate.*; 26 27 30 public class MelbourneHibernate extends HibernateDriver implements MelbourneDriver{ 31 32 private final String FROM = "from org.polepos.teams.hibernate.data.HibernatePilot"; 33 34 public void write( ){ 35 36 int numobjects = setup().getObjectCount(); 37 int commitintervall = setup().getCommitInterval(); 38 39 int commitctr = 0; 40 try{ 41 42 Transaction tx = db().beginTransaction(); 43 44 for ( int i = 1; i <= numobjects; i++ ){ 45 46 HibernatePilot p = new HibernatePilot( "Pilot_" + i, "Herkules", i, 1 ); 47 48 db().save( p ); 49 50 addToCheckSum(i); 51 52 if ( commitintervall > 0 && ++commitctr >= commitintervall ) 53 { 54 commitctr = 0; 55 tx.commit(); 56 tx = db().beginTransaction(); 57 Log.logger.fine( "commit while writing at " + i+1 ); } 59 } 60 tx.commit(); 61 } 62 catch ( HibernateException hex ){ 63 hex.printStackTrace(); 64 } 65 } 66 67 public void read(){ 68 doQuery(FROM); 69 } 70 71 public void read_hot() { 72 read(); 73 } 74 75 public void delete(){ 76 try{ 77 Transaction tx = db().beginTransaction(); 78 db().delete(FROM); 79 tx.commit(); 80 }catch ( HibernateException hex ){ 81 hex.printStackTrace(); 82 } 83 } 84 85 } 86 | Popular Tags |