@@ -724,8 +724,11 @@ public void testBulkWritReadeWithTransaction() throws Exception {
724724 }
725725 finally {
726726 if (tstatus ) {
727- termQueryResults .close ();
728- tx .rollback ();}
727+ if (termQueryResults != null )
728+ termQueryResults .close ();
729+ }
730+ tx .rollback ();
731+ tx = null ;
729732 }
730733 }
731734
@@ -2098,6 +2101,7 @@ public void testTransactionCommit() throws Exception {
20982101 }
20992102
21002103 transaction .commit ();
2104+ transaction = null ;
21012105
21022106 // There should still be no documents in latest collection
21032107 queryMgr = writerClient .newQueryManager ();
@@ -2112,176 +2116,196 @@ public void testTransactionCommit() throws Exception {
21122116 termQueryResults .getTotalSize ());
21132117 } catch (Exception ex ) {
21142118 transaction .rollback ();
2119+ transaction = null ;
21152120
21162121 assertTrue ("testTransactionCommit failed" , false );
21172122 }
2123+ finally {
2124+ if ( transaction != null ) {
2125+ transaction .rollback ();
2126+ transaction = null ;
2127+ }
2128+ }
21182129 }
21192130
21202131 @ Test
21212132 // Test transaction rollback with bitemporal documents
21222133 public void testTransactionRollback () throws Exception {
21232134
21242135 System .out .println ("Inside testTransactionRollback" );
2125-
2126- String docId = "javaSingleJSONDoc.json" ;
2127-
21282136 Transaction transaction = writerClient
2129- .openTransaction ("Transaction for BiTemporal" );
2137+ .openTransaction ("Transaction for BiTemporal" );
21302138
21312139 try {
2132- insertJSONSingleDocument (temporalCollectionName , docId , null ,
2133- transaction , null );
2134- } catch (Exception ex ) {
2135- transaction .rollback ();
2136-
2137- assertTrue ("insertJSONSingleDocument failed in testTransactionRollback" ,
2138- false );
2139- }
2140+ String docId = "javaSingleJSONDoc.json" ;
2141+ try {
2142+ insertJSONSingleDocument (temporalCollectionName , docId , null ,
2143+ transaction , null );
2144+ } catch (Exception ex ) {
2145+ transaction .rollback ();
2146+ transaction = null ;
2147+
2148+ assertTrue ("insertJSONSingleDocument failed in testTransactionRollback" ,
2149+ false );
2150+ }
21402151
2141- // Verify that the document was inserted
2142- JSONDocumentManager docMgr = writerClient .newJSONDocumentManager ();
2143- DocumentPage readResults = docMgr .read (transaction , docId );
2152+ // Verify that the document was inserted
2153+ JSONDocumentManager docMgr = writerClient .newJSONDocumentManager ();
2154+ DocumentPage readResults = docMgr .read (transaction , docId );
21442155
2145- System .out .println ("Number of results = " + readResults .size ());
2146- if (readResults .size () != 1 ) {
2147- transaction .rollback ();
2156+ System .out .println ("Number of results = " + readResults .size ());
2157+ if (readResults .size () != 1 ) {
2158+ transaction .rollback ();
21482159
2149- assertEquals ("Wrong number of results" , 1 , readResults .size ());
2150- }
2160+ assertEquals ("Wrong number of results" , 1 , readResults .size ());
2161+ }
21512162
2152- DocumentRecord latestDoc = readResults .next ();
2153- System .out .println ("URI after insert = " + latestDoc .getUri ());
2154- if (!docId .equals (latestDoc .getUri ())) {
2155- transaction .rollback ();
2163+ DocumentRecord latestDoc = readResults .next ();
2164+ System .out .println ("URI after insert = " + latestDoc .getUri ());
2165+ if (!docId .equals (latestDoc .getUri ())) {
2166+ transaction .rollback ();
21562167
2157- assertEquals ("Document uri wrong after insert" , docId , latestDoc .getUri ());
2158- }
2168+ assertEquals ("Document uri wrong after insert" , docId , latestDoc .getUri ());
2169+ }
21592170
2160- try {
2161- updateJSONSingleDocument (temporalCollectionName , docId , transaction , null );
2162- } catch (Exception ex ) {
2163- transaction .rollback ();
2171+ try {
2172+ updateJSONSingleDocument (temporalCollectionName , docId , transaction , null );
2173+ } catch (Exception ex ) {
2174+ transaction .rollback ();
2175+ transaction = null ;
21642176
2165- assertTrue ("updateJSONSingleDocument failed in testTransactionRollback" ,
2166- false );
2167- }
2177+ assertTrue ("updateJSONSingleDocument failed in testTransactionRollback" ,
2178+ false );
2179+ }
21682180
2169- // Verify that the document is visible and count is 4
2170- // Fetch documents associated with a search term (such as XML) in Address
2171- // element
2172- QueryManager queryMgr = writerClient .newQueryManager ();
2173- StructuredQueryBuilder sqb = queryMgr .newStructuredQueryBuilder ();
2181+ // Verify that the document is visible and count is 4
2182+ // Fetch documents associated with a search term (such as XML) in Address
2183+ // element
2184+ QueryManager queryMgr = writerClient .newQueryManager ();
2185+ StructuredQueryBuilder sqb = queryMgr .newStructuredQueryBuilder ();
21742186
2175- StructuredQueryDefinition termQuery = sqb .collection (docId );
2187+ StructuredQueryDefinition termQuery = sqb .collection (docId );
21762188
2177- long start = 1 ;
2178- DocumentPage termQueryResults = docMgr
2179- .search (termQuery , start , transaction );
2180- System .out
2181- .println ("Number of results = " + termQueryResults .getTotalSize ());
2182- if (termQueryResults .getTotalSize () != 4 ) {
2183- transaction .rollback ();
2189+ long start = 1 ;
2190+ DocumentPage termQueryResults = docMgr
2191+ .search (termQuery , start , transaction );
2192+ System .out
2193+ .println ("Number of results = " + termQueryResults .getTotalSize ());
2194+ if (termQueryResults .getTotalSize () != 4 ) {
2195+ transaction .rollback ();
21842196
2185- assertEquals ("Wrong number of results" , 4 ,
2186- termQueryResults .getTotalSize ());
2187- }
2197+ assertEquals ("Wrong number of results" , 4 ,
2198+ termQueryResults .getTotalSize ());
2199+ }
21882200
2189- transaction .rollback ();
2201+ transaction .rollback ();
2202+
2203+ // Verify that the document is not there after rollback
2204+ boolean exceptionThrown = false ;
2205+ try {
2206+ JacksonDatabindHandle <ObjectNode > contentHandle = new JacksonDatabindHandle <ObjectNode >(
2207+ ObjectNode .class );
2208+ DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle ();
2209+ docMgr .read (docId , metadataHandle , contentHandle );
2210+ } catch (Exception ex ) {
2211+ exceptionThrown = true ;
2212+ }
21902213
2191- // Verify that the document is not there after rollback
2192- boolean exceptionThrown = false ;
2193- try {
2194- JacksonDatabindHandle <ObjectNode > contentHandle = new JacksonDatabindHandle <ObjectNode >(
2195- ObjectNode .class );
2196- DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle ();
2197- docMgr .read (docId , metadataHandle , contentHandle );
2198- } catch (Exception ex ) {
2199- exceptionThrown = true ;
2200- }
2214+ if (!exceptionThrown ) {
2215+ transaction .rollback ();
2216+
2217+ assertTrue ("Exception not thrown during read on non-existing uri" ,
2218+ exceptionThrown );
2219+ }
22012220
2202- if (!exceptionThrown ) {
2203- transaction .rollback ();
2204-
2205- assertTrue ("Exception not thrown during read on non-existing uri" ,
2206- exceptionThrown );
2207- }
2221+ // =======================================================================
2222+ // Now try rollback with delete
2223+ System .out .println ("Test Rollback after delete" );
2224+ docId = "javaSingleJSONDocForDelete.json" ;
22082225
2209- // =======================================================================
2210- // Now try rollback with delete
2211- System .out .println ("Test Rollback after delete" );
2212- docId = "javaSingleJSONDocForDelete.json" ;
2226+ transaction = writerClient
2227+ .openTransaction ("Transaction Rollback for BiTemporal Delete" );
22132228
2214- transaction = writerClient
2215- .openTransaction ("Transaction Rollback for BiTemporal Delete" );
2229+ try {
2230+ insertJSONSingleDocument (temporalCollectionName , docId , null ,
2231+ transaction , null );
2232+ } catch (Exception ex ) {
2233+ transaction .rollback ();
2234+ transaction = null ;
22162235
2217- try {
2218- insertJSONSingleDocument (temporalCollectionName , docId , null ,
2219- transaction , null );
2220- } catch (Exception ex ) {
2221- transaction .rollback ();
2236+ assertTrue ("insertJSONSingleDocument failed in testTransactionRollback" ,
2237+ false );
2238+ }
22222239
2223- assertTrue ( "insertJSONSingleDocument failed in testTransactionRollback" ,
2224- false );
2225- }
2240+ // Verify that the document was inserted
2241+ docMgr = writerClient . newJSONDocumentManager ( );
2242+ readResults = docMgr . read ( transaction , docId );
22262243
2227- // Verify that the document was inserted
2228- docMgr = writerClient . newJSONDocumentManager ();
2229- readResults = docMgr . read ( transaction , docId );
2244+ System . out . println ( "Number of results = " + readResults . size ());
2245+ if ( readResults . size () != 1 ) {
2246+ transaction . rollback ( );
22302247
2231- System .out .println ("Number of results = " + readResults .size ());
2232- if (readResults .size () != 1 ) {
2233- transaction .rollback ();
2248+ assertEquals ("Wrong number of results" , 1 , readResults .size ());
2249+ }
22342250
2235- assertEquals ("Wrong number of results" , 1 , readResults .size ());
2236- }
2251+ latestDoc = readResults .next ();
2252+ System .out .println ("URI after insert = " + latestDoc .getUri ());
2253+ if (!docId .equals (latestDoc .getUri ())) {
2254+ transaction .rollback ();
22372255
2238- latestDoc = readResults .next ();
2239- System .out .println ("URI after insert = " + latestDoc .getUri ());
2240- if (!docId .equals (latestDoc .getUri ())) {
2241- transaction .rollback ();
2256+ assertEquals ("Document uri wrong after insert" , docId , latestDoc .getUri ());
2257+ }
22422258
2243- assertEquals ("Document uri wrong after insert" , docId , latestDoc .getUri ());
2244- }
2259+ try {
2260+ deleteJSONSingleDocument (temporalCollectionName , docId , transaction );
2261+ } catch (Exception ex ) {
2262+ transaction .rollback ();
2263+ transaction = null ;
22452264
2246- try {
2247- deleteJSONSingleDocument (temporalCollectionName , docId , transaction );
2248- } catch (Exception ex ) {
2249- transaction .rollback ();
2265+ assertTrue ("deleteJSONSingleDocument failed in testTransactionRollback" ,
2266+ false );
2267+ }
22502268
2251- assertTrue ("deleteJSONSingleDocument failed in testTransactionRollback" ,
2252- false );
2253- }
2269+ // Verify that the document is visible and count is 1
2270+ // Fetch documents associated with a search term (such as XML) in Address
2271+ // element
2272+ queryMgr = writerClient .newQueryManager ();
2273+ sqb = queryMgr .newStructuredQueryBuilder ();
22542274
2255- // Verify that the document is visible and count is 1
2256- // Fetch documents associated with a search term (such as XML) in Address
2257- // element
2258- queryMgr = writerClient .newQueryManager ();
2259- sqb = queryMgr .newStructuredQueryBuilder ();
2275+ termQuery = sqb .collection (docId );
22602276
2261- termQuery = sqb .collection (docId );
2277+ start = 1 ;
2278+ termQueryResults = docMgr .search (termQuery , start , transaction );
2279+ System .out
2280+ .println ("Number of results = " + termQueryResults .getTotalSize ());
2281+ if (termQueryResults .getTotalSize () != 1 ) {
2282+ transaction .rollback ();
22622283
2263- start = 1 ;
2264- termQueryResults = docMgr .search (termQuery , start , transaction );
2265- System .out
2266- .println ("Number of results = " + termQueryResults .getTotalSize ());
2267- if (termQueryResults .getTotalSize () != 1 ) {
2268- transaction .rollback ();
2284+ assertEquals ("Wrong number of results" , 1 ,
2285+ termQueryResults .getTotalSize ());
2286+ }
22692287
2270- assertEquals ("Wrong number of results" , 1 ,
2271- termQueryResults .getTotalSize ());
2272- }
2288+ transaction .rollback ();
2289+ transaction = null ;
22732290
2274- transaction .rollback ();
2291+ // Verify that the document was rolled back and count is 0
2292+ exceptionThrown = false ;
2293+ try {
2294+ readResults = docMgr .read (docId );
2295+ } catch (Exception ex ) {
2296+ exceptionThrown = true ;
2297+ }
22752298
2276- // Verify that the document was rolled back and count is 0
2277- exceptionThrown = false ;
2278- try {
2279- readResults = docMgr .read (docId );
2280- } catch (Exception ex ) {
2281- exceptionThrown = true ;
2299+ System .out .println ("Done" );
2300+ } catch (Exception e ) {
2301+ e .printStackTrace ();
2302+ }
2303+ finally {
2304+ if (transaction != null ) {
2305+ transaction .rollback ();
2306+ transaction = null ;
2307+ }
22822308 }
2283-
2284- System .out .println ("Done" );
22852309 }
22862310
22872311 @ Test
0 commit comments