import java.util.UUID; import org.tupeloproject.kernel.BeanSession; import org.tupeloproject.kernel.TripleWriter; import org.tupeloproject.kernel.beans.reflect.BeanMapping; import org.tupeloproject.kernel.beans.reflect.BeanMappingCache; import org.tupeloproject.kernel.impl.MemoryContext; import org.tupeloproject.rdf.Resource; import org.tupeloproject.rdf.terms.Dc; import org.tupeloproject.rdf.terms.Foaf; import org.tupeloproject.rdf.terms.Rdf; public class BeanTester { private static int COUNT = 100; public static void main( String[] args ) throws Exception { long total; // WARMING UP JVM System.gc(); System.gc(); testBeanSession(); System.gc(); System.gc(); testTripleWriter(); // RUNNING TRIPLEWRITER TIME total = 0; for ( int i = 0; i < 4; i++ ) { System.gc(); System.gc(); long l = System.currentTimeMillis(); testTripleWriter(); total += (System.currentTimeMillis() - l); } System.out.println( "TW TIME : " + (total / 4.0) ); // RUNNING BEANSESSION TIME total = 0; for ( int i = 0; i < 4; i++ ) { System.gc(); System.gc(); long l = System.currentTimeMillis(); testBeanSession(); total += (System.currentTimeMillis() - l); } System.out.println( "BS TIME : " + (total / 4.0) ); } private static void testBeanSession() throws Exception { BeanSession bs = getBeanSession(); for ( int i = 0; i < COUNT; i++ ) { PeopleBean bean = new PeopleBean(); bs.save( bean ); } } private static void testTripleWriter() throws Exception { BeanSession bs = getBeanSession(); // write beans for ( int i = 0; i < COUNT; i++ ) { Resource bean = Resource.uriRef( "tag:cet.ncsa.uiuc.edu,2008:/bean/people/" + UUID.randomUUID().toString() ); //$NON-NLS-1$ TripleWriter tw = new TripleWriter(); tw.add( bean, Rdf.TYPE, Foaf.NAME ); tw.add( bean, Dc.IDENTIFIER, bean.getString() ); tw.add( bean, Foaf.NAME, "Rob Kooper" ); bs.getContext().perform( tw ); } } private static BeanSession getBeanSession() { BeanMapping map = new BeanMapping(); // java class representing the bean map.setJavaClassName( PeopleBean.class.getName() ); // the rdf type of the bean map.setRdfType( Foaf.PERSON ); // properties for the bean map.addProperty( Foaf.NAME, "name", String.class); //$NON-NLS-1$ // add to cache BeanMappingCache cache = new BeanMappingCache(); cache.put( map ); // create beansession MemoryContext mc = new MemoryContext(); BeanSession bs = new BeanSession( mc ); bs.setBeanMappingCache( cache ); return bs; } public static class PeopleBean { private String name; public String getName() { return name; } public void setName( String name ) { this.name = name; } } }