1 19 20 package org.polepos.teams.hibernate; 21 22 import java.io.*; 23 24 import org.polepos.circuits.imola.*; 25 import org.polepos.framework.*; 26 import org.polepos.teams.hibernate.data.*; 27 28 import net.sf.hibernate.*; 29 30 public class ImolaHibernate extends HibernateDriver implements ImolaDriver { 31 private final String FROM = "from org.polepos.teams.hibernate.data.HibernateIndexedPilot"; 32 private Serializable[] ids; 33 private int step; 34 35 public void takeSeatIn(Car car, TurnSetup setup) throws CarMotorFailureException{ 36 ids=new Serializable[setup.getSelectCount()]; 37 super.takeSeatIn(car, setup); 38 } 39 40 public void store() { 41 try{ 42 Transaction tx = db().beginTransaction(); 43 for ( int i = 1; i <= setup().getObjectCount(); i++ ){ 44 storePilot(tx, i); 45 } 46 tx.commit(); 47 } 48 catch ( HibernateException hex ){ 49 hex.printStackTrace(); 50 } 51 } 52 53 public void retrieve() { 54 for(Serializable id : ids) { 55 try { 56 HibernateIndexedPilot pilot=(HibernateIndexedPilot) db().load(HibernateIndexedPilot.class,id); 57 addToCheckSum(pilot.getPoints()); 58 if(pilot==null) { 59 System.err.println("Got no pilot by ID."); 60 } 61 } catch (HibernateException e) { 62 e.printStackTrace(); 63 } 64 } 65 } 66 67 private void storePilot(Transaction trans, int idx) throws HibernateException { 68 Serializable id=db().save( new HibernateIndexedPilot( "Pilot_" + idx, "Jonny_" + idx, idx , idx ) ); 69 if ( isCommitPoint(idx) ){ 70 trans.commit(); 71 Log.logger.fine( "commit while writing at " + idx+1 ); } 73 if(idx <= setup().getSelectCount()) { 74 ids[idx - 1] = id; 75 } 76 } 77 78 private boolean isCommitPoint(int idx) { 79 int commitInterval = setup().getCommitInterval(); 80 return commitInterval> 0 && idx%commitInterval==0 && idx < setup().getObjectCount(); 81 } 82 } 83 | Popular Tags |