jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1347064 - in /jena/Scratch/AFS/Jena-Dev/trunk/src: dev/ dev/xsddt/ reports/archive/ reports/archive/xsddt_247/
Date Wed, 06 Jun 2012 19:12:35 GMT
Author: andy
Date: Wed Jun  6 19:12:35 2012
New Revision: 1347064

URL: http://svn.apache.org/viewvc?rev=1347064&view=rev
Log: (empty)

Added:
    jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena250_TestStoreRelease.java
    jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/Jena247_XSDDatimeTzBoundary.java
      - copied, changed from r1346974, jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JENA247_XSDDatimeTzBoundary.java
    jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/
      - copied from r1346931, jena/Scratch/AFS/Jena-Dev/trunk/src/dev/xsddt/
Removed:
    jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JENA247_XSDDatimeTzBoundary.java
    jena/Scratch/AFS/Jena-Dev/trunk/src/dev/xsddt/
Modified:
    jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/DT.java
    jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/XSDDateTime2.java

Added: jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena250_TestStoreRelease.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena250_TestStoreRelease.java?rev=1347064&view=auto
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena250_TestStoreRelease.java (added)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena250_TestStoreRelease.java Wed Jun  6 19:12:35
2012
@@ -0,0 +1,189 @@
+//package com.ibm.jena.tdb.tx.test;
+package dev ;
+
+import java.io.File ;
+import java.util.UUID ;
+
+import org.openjena.atlas.lib.FileOps ;
+
+import com.hp.hpl.jena.query.* ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.Property ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.tdb.StoreConnection ;
+import com.hp.hpl.jena.tdb.TDB ;
+import com.hp.hpl.jena.tdb.TDBFactory ;
+import com.hp.hpl.jena.tdb.base.file.Location ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
+
+/**
+ * @author shelsen
+ * 
+ */
+public class Jena250_TestStoreRelease {
+
+	final private static String INDEX_INFO_SUBJECT = "http://jazz.net/xmlns/foundation/1.0/test1";

+	final private static String TIMESTAMP_PREDICATE = "http://jazz.net/xmlns/foundation/1.0/test2";

+	final private static String URI_PREDICATE = "http://jazz.net/xmlns/foundation/1.0/test3";

+	final private static String VERSION_PREDICATE = "http://jazz.net/xmlns/foundation/1.0/test4";

+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		System.out.println("Starting TestStoreRelease");
+
+		// we always use direct mode
+		ARQ.getContext().set(SystemTDB.symFileMode, "direct");
+		if (!SystemTDB.fileMode().toString().equals("direct")) {
+			throw new RuntimeException("file mode is not direct, but " + SystemTDB.fileMode()); //$NON-NLS-1$
+		}
+
+		TDB.getContext().set(TDB.symUnionDefaultGraph, true);
+	
+//		if (args.length == 0) {
+//			throw new RuntimeException("provide a location"); //$NON-NLS-1$
+//		}
+//
+//		String locationStr = args[0];
+		String locationStr = "DB" ;
+		if ( FileOps.exists(locationStr) )
+		{
+		    FileOps.clearDirectory(locationStr) ;
+		    new File(locationStr).delete() ;
+		}
+		
+		String absoluteLocationStr = new File(locationStr).getAbsolutePath();
+
+		System.out.println("Testing on store located at " + absoluteLocationStr);
+
+		Location location = new Location(absoluteLocationStr);
+
+		new Jena250_TestStoreRelease().testStoreRelease(location);
+
+		new Jena250_TestStoreRelease().testStoreRelease(location);
+    
+		new Jena250_TestStoreRelease().testStoreRelease(location);
+
+	}
+
+	private Location location;
+
+	public void testStoreRelease(Location location) {
+		this.location = location;
+		// create a dummy dataset at the provided location to force creation if the store does
not exist
+		TDBFactory.createDataset(this.location);
+
+		System.out.println("The store size is " + this.storeSize());
+		
+		// insert a few triples
+		System.out.println("Writing triples");
+		this.saveSomeTriples();
+
+		System.out.println("The store size is " + this.storeSize());
+		
+		System.out.println("Writing more triples");
+		this.saveSomeTriples();
+		
+		System.out.println("Releasing the store at location: " + this.location.getDirectoryPath());
+		StoreConnection.release(this.location);
+	}
+
+	public interface QueryActivity<E> {
+		E run(QueryExecution qe) throws Exception;
+	}
+
+	private <E> E storeOperation(String query, QueryActivity<E> queryActivity) {
+		long t = System.currentTimeMillis();
+		Dataset dataset = TDBFactory.createDataset(this.location);
+		QueryExecution qe = null;
+		try {
+			dataset.begin(ReadWrite.READ);
+			qe = QueryExecutionFactory.create(query, dataset);
+			E e = queryActivity.run(qe);
+			dataset.commit();
+			return e;
+		} catch (Throwable e) {
+			dataset.abort();
+			throw new RuntimeException(e);
+		} finally {
+			try {
+				if (qe != null) {
+					qe.close();
+				}
+			} finally {
+				dataset.end();
+			}
+			//System.out.println("QueryActivity: " + (System.currentTimeMillis() - t) + "ms");
+		}
+	}
+
+	public interface ModelWriteActivity<E> {
+		E run(Model model) throws Exception;
+	}
+
+	private <E> E storeOperation(String graphName, ModelWriteActivity<E> modelWriteActivity)
{
+		long t = System.currentTimeMillis();
+		Dataset dataset = TDBFactory.createDataset(this.location);
+		try {
+			dataset.begin(ReadWrite.WRITE);
+			Model m = dataset.getNamedModel(graphName);
+			E e = modelWriteActivity.run(m);
+			dataset.commit();
+			return e;
+		} catch (Throwable e) {
+			dataset.abort();
+			throw new RuntimeException(e);
+		} finally {
+			dataset.end();
+			//System.out.println("ModelWriteActivity: " + (System.currentTimeMillis() - t) + "ms");

+		}
+	}
+
+	protected void saveSomeTriples() {
+
+		this.storeOperation(INDEX_INFO_SUBJECT, new ModelWriteActivity<Void>() {
+
+			@Override
+            public Void run(Model timestampModel) throws Exception {
+				Resource subject = timestampModel.createResource(INDEX_INFO_SUBJECT);
+				Property predicate = timestampModel.createProperty(TIMESTAMP_PREDICATE);
+				timestampModel.addLiteral(subject, predicate, System.currentTimeMillis());
+				predicate = timestampModel.createProperty(URI_PREDICATE);
+				for (int i = 0; i < 9; i++) {
+					timestampModel.add(subject, predicate, timestampModel.createResource("https://localhost/"
+ UUID.randomUUID().toString()));
+				}
+				predicate = timestampModel.createProperty(VERSION_PREDICATE);
+				timestampModel.addLiteral(subject, predicate, 1.0);
+
+				return null;
+			}
+		});
+	}
+
+	private int storeSize() {
+		String queryStr = "SELECT (COUNT(?s) as ?c)\n" + 
+				"WHERE { \n" + 
+				"  ?s ?p ?o ." + 
+				"}  \n";
+
+		return this.storeOperation(queryStr, new QueryActivity<Integer>() {
+
+		    // AFS : properly close 
+		    // Added qe.close, and additional rs.hasNext
+			@Override
+            public Integer run(QueryExecution qe) throws Exception {
+			    ResultSet rs = qe.execSelect();
+			    try {
+				if (rs.hasNext()) {
+				    int x = rs.next().get("c").asLiteral().getInt();
+				    ResultSetFormatter.consume(rs) ;
+				    return x ;
+				}
+			    } finally { qe.close() ; }
+				return 0;
+
+			}
+		});
+	}
+}

Copied: jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/Jena247_XSDDatimeTzBoundary.java
(from r1346974, jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JENA247_XSDDatimeTzBoundary.java)
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/Jena247_XSDDatimeTzBoundary.java?p2=jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/Jena247_XSDDatimeTzBoundary.java&p1=jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JENA247_XSDDatimeTzBoundary.java&r1=1346974&r2=1347064&rev=1347064&view=diff
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JENA247_XSDDatimeTzBoundary.java (original)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/Jena247_XSDDatimeTzBoundary.java Wed
Jun  6 19:12:35 2012
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package dev;
+package reports.archive;
 
 
 import java.text.SimpleDateFormat ;
@@ -26,8 +26,8 @@ import java.util.TimeZone ;
 
 import org.junit.Assert ;
 import org.junit.Test ;
-import dev.xsddt.DT ;
-import dev.xsddt.XSDDateTime2 ;
+import reports.archive.xsddt_247.DT ;
+import reports.archive.xsddt_247.XSDDateTime2 ;
 
  
 /* from
@@ -49,11 +49,11 @@ with:
 
  */
 
-public class JENA247_XSDDatimeTzBoundary {
+public class Jena247_XSDDatimeTzBoundary {
     
     public static void main(String ... argv) throws Exception
     {
-        new JENA247_XSDDatimeTzBoundary().test() ;
+        new Jena247_XSDDatimeTzBoundary().test() ;
     }
 
     

Modified: jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/DT.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/DT.java?rev=1347064&r1=1346931&r2=1347064&view=diff
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/DT.java (original)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/DT.java Wed Jun  6 19:12:35
2012
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package dev.xsddt;
+package reports.archive.xsddt_247;
 
 import com.hp.hpl.jena.datatypes.RDFDatatype;
 import com.hp.hpl.jena.datatypes.xsd.AbstractDateTime ;

Modified: jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/XSDDateTime2.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/XSDDateTime2.java?rev=1347064&r1=1346931&r2=1347064&view=diff
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/XSDDateTime2.java (original)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/reports/archive/xsddt_247/XSDDateTime2.java Wed Jun
 6 19:12:35 2012
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package dev.xsddt;
+package reports.archive.xsddt_247;
 
 import java.util.Calendar ;
 import java.util.GregorianCalendar ;



Mime
View raw message