1 24 package org.objectweb.jalisto.samples.basic2; 25 26 import org.objectweb.jalisto.se.impl.meta.type.MetaTypeFactory; 27 import org.objectweb.jalisto.se.impl.*; 28 import org.objectweb.jalisto.se.api.Session; 29 import org.objectweb.jalisto.se.api.Transaction; 30 import org.objectweb.jalisto.se.api.ClassDescription; 31 import org.objectweb.jalisto.samples.basic2.data.Book; 32 33 import java.util.Collection ; 34 import java.util.Iterator ; 35 36 public class JalistoBookDemo { 37 38 public static void main(String [] args) { 39 String jalistoPropertiesFilename = "jalisto.properties"; 40 int nbrBook = 5000; 41 42 try { 43 jalistoPropertiesFilename = args[0]; 44 nbrBook = Integer.parseInt(args[1]); 45 } catch (Exception e) { 46 } 47 48 JalistoBookDemo demo = new JalistoBookDemo(); 49 demo.initialise(jalistoPropertiesFilename); 50 demo.run(nbrBook); 51 } 52 53 public void initialise(String jalistoPropertiesFilename) { 54 session = null; 56 tx = session.currentTransaction(); 58 59 ClassDescription meta = JalistoFactory.createClassDescription(Book.class.getName()); 61 meta.addField(JalistoFactory.createFieldDescription("title", MetaTypeFactory.StringType)); 62 meta.addField(JalistoFactory.createFieldDescription("pages", MetaTypeFactory.IntegerType)); 63 meta.addField(JalistoFactory.createFieldDescription("comments", MetaTypeFactory.StringType)); 64 session.defineClass(meta); 66 } 67 68 public void run(int nbrBook) { 69 long startTime; 70 long execTime; 71 Iterator iterator; 72 73 System.out.println("JalistoBookDemo is running :"); 74 75 System.out.println("Create " + nbrBook + " books..."); 76 startTime = System.currentTimeMillis(); 77 78 tx.begin(); 79 for (int i = 0; i < nbrBook; i++) { 80 Book book = Book.newBook(); 81 Object [] o = book.toArray(); 82 Object oid = session.createObject(o, Book.class); 83 } 84 tx.commit(); 85 86 execTime = System.currentTimeMillis() - startTime; 87 System.out.println("ok ! It takes " + execTime + " ms.\n"); 88 89 90 System.out.println("Get oids of all books..."); 91 startTime = System.currentTimeMillis(); 92 93 tx.begin(); 94 Collection oids = session.getExtent(Book.class).readFully().collection(); 95 tx.commit(); 96 97 execTime = System.currentTimeMillis() - startTime; 98 System.out.println("ok ! It takes " + execTime + " ms.\n"); 99 100 101 System.out.println("Add a comment to all books..."); 102 startTime = System.currentTimeMillis(); 103 104 tx.begin(); 105 iterator = oids.iterator(); 106 int i = 0; 107 while (iterator.hasNext()) { 108 Object oid = iterator.next(); 109 Object [] o = session.readObjectByOid(oid); 110 Book book = Book.toBook(o); 111 book.setComments("comments number " + i); 112 session.updateObjectByOid(oid, book.toArray()); 113 i++; 114 } 115 tx.commit(); 116 117 execTime = System.currentTimeMillis() - startTime; 118 System.out.println("ok ! It takes " + execTime + " ms.\n"); 119 120 121 System.out.println("Delete all books..."); 122 startTime = System.currentTimeMillis(); 123 124 tx.begin(); 125 iterator = oids.iterator(); 126 while (iterator.hasNext()) { 127 session.deleteObjectByOid(iterator.next()); 128 } 129 tx.commit(); 130 131 execTime = System.currentTimeMillis() - startTime; 132 System.out.println("ok ! It takes " + execTime + " ms.\n"); 133 134 session.reorganize(); 135 } 136 137 private Session session; 138 private Transaction tx; 139 } 140 | Popular Tags |