1 6 7 package com.hp.hpl.jena.db.test; 8 9 22 23 import junit.framework.*; 24 25 import com.hp.hpl.jena.db.IDBConnection; 26 import com.hp.hpl.jena.db.ModelRDB; 27 import com.hp.hpl.jena.db.impl.DriverRDB; 28 import com.hp.hpl.jena.db.impl.Driver_MySQL; 29 import com.hp.hpl.jena.rdf.model.*; 30 31 public class TestTransactions extends TestCase 32 { 33 34 public TestTransactions( String name ) 35 { super( name ); } 36 37 public static TestSuite suite() 38 { return new TestSuite( TestTransactions.class ); } 39 40 ModelRDB model = null; 41 Model dbProperties = null; 42 IDBConnection conn = null; 43 DriverRDB m_driver = null; 44 45 protected void setUp() throws java.lang.Exception { 46 47 conn = TestConnection.makeAndCleanTestConnection(); 48 dbProperties = conn.getDatabaseProperties(); 49 model = ModelRDB.createModel(conn); 50 m_driver = new Driver_MySQL(); 51 m_driver.setConnection(conn); 52 } 53 54 protected void tearDown() throws java.lang.Exception { 55 model.close(); 56 model = null; 57 conn.cleanDB(); 58 conn.close(); 59 conn = null; 60 } 61 62 private void addCommit(Statement stmt) { 63 model.remove(stmt); 64 model.begin(); 65 model.add(stmt); 66 model.commit(); 67 assertTrue( model.contains(stmt) ); 68 } 69 70 private void addAbort(Statement stmt) { 71 model.remove(stmt); 72 model.begin(); 74 model.add(stmt); 75 model.abort(); 76 assertTrue(!model.contains(stmt) ); 80 } 81 82 public void testAddCommitURI() { 83 Resource s = model.createResource("test#subject"); 84 Property p = model.createProperty("test#predicate"); 85 Resource o = model.createResource("test#object"); 86 87 addCommit( model.createStatement(s,p,o)); 88 } 89 90 public void testAddAbortURI() { 91 Resource s = model.createResource("test#subject"); 92 Property p = model.createProperty("test#predicate"); 93 Resource o = model.createResource("test#object"); 94 95 addAbort( model.createStatement(s,p,o)); 96 } 97 98 public void testAddCommitLiteral() { 99 Resource s = model.createResource("test#subject"); 100 Property p = model.createProperty("test#predicate"); 101 Literal l = model.createLiteral("testLiteral"); 102 103 addCommit( model.createStatement(s,p,l)); 104 } 105 106 107 public void testAddCommitHugeLiteral() { 108 String base = "This is a huge string that repeats."; 109 StringBuffer buffer = new StringBuffer (4096); 110 while(buffer.length() < 4000 ) 111 buffer.append(base); 112 Resource s = model.createResource("test#subject"); 113 Property p = model.createProperty("test#predicate"); 114 Literal l = model.createLiteral(buffer.toString()); 115 116 addCommit( model.createStatement(s,p,l)); 117 } 118 119 public void testAddAbortHugeLiteral() { 120 String base = "This is a huge string that repeats."; 121 StringBuffer buffer = new StringBuffer (4096); 122 while(buffer.length() < 4000 ) 123 buffer.append(base); 124 Resource s = model.createResource("test#subject"); 125 Property p = model.createProperty("test#predicate"); 126 Literal l = model.createLiteral(buffer.toString()); 127 128 addAbort( model.createStatement(s,p,l)); 129 } 130 131 public void testAddCommitDatatype() { 132 Resource s = model.createResource("test#subject"); 133 Property p = model.createProperty("test#predicate"); 134 Literal l = model.createTypedLiteral("stringType"); 135 136 addCommit( model.createStatement(s,p,l)); 137 } 138 139 public void testAddAbortDatatype() { 140 Resource s = model.createResource("test#subject"); 141 Property p = model.createProperty("test#predicate"); 142 Literal l = model.createTypedLiteral("stringType"); 143 144 addAbort( model.createStatement(s,p,l)); 145 } 146 147 148 public void testAddAbortHugeDatatype() { 149 String base = "This is a huge string that repeats."; 150 StringBuffer buffer = new StringBuffer (4096); 151 while(buffer.length() < 4000 ) 152 buffer.append(base); 153 Resource s = model.createResource("test#subject"); 154 Property p = model.createProperty("test#predicate"); 155 Literal l2 = model.createTypedLiteral(buffer.toString()); 156 157 addAbort( model.createStatement(s,p,l2)); 158 } 159 160 public void testAddCommitHugeDatatype() { 161 String base = "This is a huge string that repeats."; 162 StringBuffer buffer = new StringBuffer (4096); 163 while(buffer.length() < 4000 ) 164 buffer.append(base); 165 Resource s = model.createResource("test#subject"); 166 Property p = model.createProperty("test#predicate"); 167 Literal l2 = model.createTypedLiteral(buffer.toString()); 168 169 addCommit( model.createStatement(s,p,l2)); 170 } 171 172 public void testAddCommitBNode() { 173 Resource s = model.createResource(); 174 Property p = model.createProperty("test#predicate"); 175 Resource o = model.createResource(); 176 177 addCommit( model.createStatement(s,p,o)); 178 } 179 180 public void testAddAbortBNode() { 181 Resource s = model.createResource(); 182 Property p = model.createProperty("test#predicate"); 183 Resource o = model.createResource(); 184 185 addAbort( model.createStatement(s,p,o)); 186 } 187 188 189 } 190 191 192 221 | Popular Tags |