1 24 package org.objectweb.jalisto.samples.basic; 25 26 import org.objectweb.jalisto.samples.basic.data.Book; 27 import org.objectweb.jalisto.se.impl.meta.type.MetaTypeFactory; 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.se.JalistoFactory; 32 33 public class JalistoDemo { 34 35 private Session session; 36 private Transaction tx; 37 38 private Object oid; 39 40 public static void main(String [] args) { 41 JalistoDemo demo = new JalistoDemo(); 42 43 demo.initJalisto("samples.properties"); 44 demo.defineData(); 45 demo.createBook(); 46 demo.updateBook(); 47 demo.deleteBook(); 48 demo.closeJalisto(); 49 } 50 51 public void initJalisto(String propertiesFile) { 52 System.out.println("JalistoDemo.initJalisto : "+propertiesFile); 53 54 session = JalistoFactory.getSession(propertiesFile); 56 session.openSession(); 57 tx = session.currentTransaction(); 59 } 60 61 public void closeJalisto() { 62 System.out.println("JalistoDemo.closeJalisto"); 63 64 session.closeSession(); 65 } 66 67 public void defineData() { 68 System.out.println("JalistoDemo.defineData"); 69 70 ClassDescription meta = JalistoFactory.createClassDescription(Book.class.getName()); 72 meta.addField(JalistoFactory.createFieldDescription("title", MetaTypeFactory.StringType)); 73 meta.addField(JalistoFactory.createFieldDescription("author", MetaTypeFactory.StringType)); 74 meta.addField(JalistoFactory.createFieldDescription("price", MetaTypeFactory.IntegerType)); 75 76 session.defineClass(meta); 78 } 79 80 public void createBook() { 81 System.out.println("JalistoDemo.createBook"); 82 83 tx.begin(); 84 Book book = new Book("The Bible", "God", 777); 85 Object [] array = book.toArray(); 86 oid = session.createObject(array, Book.class); 87 tx.commit(); 88 } 89 90 public void updateBook() { 91 System.out.println("JalistoDemo.updateBook"); 92 93 tx.begin(); 94 Object [] o = session.readObjectByOid(oid); 95 Book book = Book.toBook(o); 96 book.setPrice(8888); 97 session.updateObjectByOid(oid, book.toArray()); 98 tx.commit(); 99 } 100 101 public void deleteBook() { 102 System.out.println("JalistoDemo.deleteBook"); 103 104 tx.begin(); 105 session.deleteObjectByOid(oid); 106 tx.commit(); 107 } 108 } 109 | Popular Tags |