1 package org.apache.ojb.junit; 2 3 17 18 import org.apache.ojb.broker.PersistenceBroker; 19 import org.apache.ojb.broker.PersistenceBrokerFactory; 20 import org.apache.ojb.broker.PersistenceBrokerException; 21 import org.apache.ojb.broker.platforms.Platform; 22 23 30 public class PBTestCase extends OJBTestCase 31 { 32 public PersistenceBroker broker; 33 private String platformClass; 34 35 public PBTestCase() 36 { 37 } 38 39 public PBTestCase(String name) 40 { 41 super(name); 42 } 43 44 public void setUp() throws Exception 45 { 46 Platform platform; 47 48 super.setUp(); 49 assertNotNull(broker = PersistenceBrokerFactory.defaultPersistenceBroker()); 50 assertNotNull(platform = broker.serviceConnectionManager().getSupportedPlatform()); 51 platformClass = platform.getClass().getName(); 52 } 53 54 public void tearDown() throws Exception 55 { 56 if(broker != null) 57 { 58 try 59 { 60 broker.close(); 61 } 62 catch(Exception ignore) 63 { 64 } 65 } 66 super.tearDown(); 67 } 68 69 74 public String getPlatformClass() 75 { 76 return platformClass; 77 } 78 79 87 public void pbPersist(Object obj) 88 { 89 try 90 { 91 broker.beginTransaction(); 92 broker.store(obj); 93 broker.commitTransaction(); 94 } 95 catch (PersistenceBrokerException pbe) 96 { 97 throw pbe; 98 } 99 catch (ClassCastException cce) 100 { 101 System.err.println("Error in JDBC-driver while storing: " + obj); 102 throw cce; 103 } 104 finally 105 { 106 if (broker.isInTransaction()) 107 { 108 try 109 { 110 broker.abortTransaction(); 111 } 112 catch (Throwable ignore) 113 { 114 } 116 } 117 } 118 } 119 120 } 121 | Popular Tags |