1 19 20 package org.polepos.teams.hibernate; 21 22 23 24 import java.util.Iterator ; 25 26 import org.polepos.circuits.bahrain.*; 27 import org.polepos.teams.hibernate.data.*; 28 29 import net.sf.hibernate.*; 30 31 32 35 public class BahrainHibernate extends HibernateDriver implements BahrainDriver{ 36 37 private final String FROM = "from org.polepos.teams.hibernate.data.HibernateIndexedPilot"; 38 39 public void write(){ 40 41 try{ 42 43 Transaction tx = db().beginTransaction(); 44 45 int commitctr = 0; 46 int count = setup().getObjectCount(); 47 int commitInterval = setup().getCommitInterval(); 48 49 for ( int i = 1; i <= count; i++ ){ 50 51 db().save( new HibernateIndexedPilot( "Pilot_" + i, "Jonny_" + i, i , i ) ); 52 if ( commitInterval> 0 && ++commitctr >= commitInterval ){ 53 commitctr = 0; 54 tx.commit(); 55 Log.logger.fine( "commit while writing at " + i+1 ); } 57 58 addToCheckSum(i); 59 60 } 61 62 tx.commit(); 63 } 64 catch ( HibernateException hex ){ 65 hex.printStackTrace(); 66 } 67 68 } 69 70 71 public void query_indexed_string(){ 72 73 int count = setup().getSelectCount(); 74 75 for (int i = 1; i <= count; i++) { 76 doSingleResultQuery( FROM + " where Name='Pilot_" + i + "'" ); 77 } 78 79 } 80 81 82 public void query_string(){ 83 84 int count = setup().getSelectCount(); 85 86 for (int i = 1; i <= count; i++) { 87 doSingleResultQuery( FROM + " where FirstName='Jonny_" + i + "'" ); 88 } 89 90 } 91 92 93 public void query_indexed_int(){ 94 95 int count = setup().getSelectCount(); 96 97 for (int i = 1; i <= count; i++) { 98 doSingleResultQuery( FROM + " where LicenseID=" + i ); 99 } 100 101 } 102 103 public void query_int(){ 104 105 int count = setup().getSelectCount(); 106 107 for (int i = 1; i <= count; i++) { 108 doQuery( FROM + " where Points=" + i ); 109 } 110 111 } 112 113 public void update(){ 114 115 try{ 116 int updateCount = setup().getUpdateCount(); 117 118 Transaction tx = db().beginTransaction(); 119 Iterator it = db().iterate(FROM); 120 for (int i = 0; i < updateCount; i++) { 121 HibernateIndexedPilot p = (HibernateIndexedPilot) it.next(); 122 p.setName( p.getName().toUpperCase() ); 123 db().update( p ); 124 addToCheckSum(1); 125 } 126 tx.commit(); 127 } 128 catch ( HibernateException hex ){ 129 hex.printStackTrace(); 130 } 131 } 132 133 public void delete(){ 134 try{ 135 Transaction tx = db().beginTransaction(); 136 Iterator it = db().iterate(FROM); 137 while(it.hasNext()){ 138 db().delete(it.next()); 139 addToCheckSum(1); 140 } 141 tx.commit(); 142 } 143 catch ( HibernateException hex ){ 144 hex.printStackTrace(); 145 } 146 } 147 148 } 149 | Popular Tags |