From: Tobias H. <thu...@us...> - 2005-05-11 10:45:13
|
Update of /cvsroot/magicmap/magicmapserver/src/net/sf/magicmap/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9267/src/net/sf/magicmap/server Modified Files: ApplicationWatch.java Added Files: Init.java Log Message: + Client is usable without server --- NEW FILE: Init.java --- /* * Created on 10.05.2005 * */ package net.sf.magicmap.server; import java.util.Collection; import java.util.Properties; import javax.jdo.Extent; import javax.jdo.JDOHelper; import javax.jdo.PersistenceManager; import javax.jdo.Query; import net.sf.magicmap.db.Client; import net.sf.magicmap.server.utils.JDOUtil; /** * @author thuebner * */ public class Init { /** * */ public static void initJDO(String dbDriver, String dbURL, String user, String password){ Properties properties = new Properties(); properties.setProperty("javax.jdo.PersistenceManagerFactoryClass", "org.jpox.PersistenceManagerFactoryImpl"); properties.setProperty("javax.jdo.option.ConnectionDriverName", dbDriver); properties.setProperty("javax.jdo.option.ConnectionURL", dbURL); if (user != null){ properties.setProperty("javax.jdo.option.ConnectionUserName", user); } if (password != null){ properties.setProperty("javax.jdo.option.ConnectionPassword", password); } properties.setProperty("org.jpox.autoCreateSchema", "true"); properties.setProperty("org.jpox.autoCreateTables", "true"); properties.setProperty("org.jpox.autoCreateColumns", "true"); properties.setProperty("org.jpox.autoCreateConstraints", "true"); properties.setProperty("org.jpox.validateTables", "true"); properties.setProperty("org.jpox.validateConstraints", "true"); //properties.setProperty("javax.jdo.option.NontransactionalRead", "true"); properties.setProperty("javax.jdo.option.Optimistic", "false"); properties.setProperty("javax.jdo.option.RestoreValues", "true"); properties.setProperty("org.jpox.cache.level2", "true"); properties.setProperty("org.jpox.poid.generatorClass", "org.jpox.poid.SequenceTablePoidGenerator"); JDOUtil.pmfactory = JDOHelper.getPersistenceManagerFactory(properties); PersistenceManager pm = JDOUtil.pmfactory.getPersistenceManager(); pm.currentTransaction().begin(); Extent e = pm.getExtent(Client.class, true); Query query = pm.newQuery(e); Collection c = (Collection) query.execute(); try{ Client client = new Client("dummy", "client", "dumm"); pm.makePersistent(client); pm.currentTransaction().commit(); pm.currentTransaction().begin(); pm.deletePersistent(client); } catch (Exception ex){ System.out.println("Fatal: " + ex.getMessage()); pm.currentTransaction().begin(); } pm.currentTransaction().commit(); pm.close(); } } Index: ApplicationWatch.java =================================================================== RCS file: /cvsroot/magicmap/magicmapserver/src/net/sf/magicmap/server/ApplicationWatch.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ApplicationWatch.java 23 Jan 2005 18:11:00 -0000 1.2 --- ApplicationWatch.java 11 May 2005 10:45:05 -0000 1.3 *************** *** 7,21 **** import java.io.IOException; import java.sql.Timestamp; - import java.util.Collection; - import java.util.Properties; - import javax.jdo.Extent; - import javax.jdo.JDOHelper; - import javax.jdo.PersistenceManager; - import javax.jdo.Query; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; - import net.sf.magicmap.db.Client; import net.sf.magicmap.server.utils.JDOUtil; --- 7,14 ---- *************** *** 67,108 **** startUp = System.currentTimeMillis(); ! Properties properties = new Properties(); ! ! properties.setProperty("javax.jdo.PersistenceManagerFactoryClass", "org.jpox.PersistenceManagerFactoryImpl"); ! properties.setProperty("javax.jdo.option.ConnectionDriverName", "org.jpox.driver.JPOXDriver"); ! properties.setProperty("javax.jdo.option.ConnectionURL", "jpox:java:comp/env/jdbc/magicmap"); ! properties.setProperty("org.jpox.autoCreateSchema", "true"); ! properties.setProperty("org.jpox.autoCreateTables", "true"); ! properties.setProperty("org.jpox.autoCreateColumns", "true"); ! properties.setProperty("org.jpox.autoCreateConstraints", "true"); ! ! properties.setProperty("org.jpox.validateTables", "true"); ! properties.setProperty("org.jpox.validateConstraints", "true"); ! //properties.setProperty("javax.jdo.option.NontransactionalRead", "true"); ! properties.setProperty("javax.jdo.option.Optimistic", "false"); ! properties.setProperty("javax.jdo.option.RestoreValues", "true"); ! ! properties.setProperty("org.jpox.cache.level2", "true"); ! properties.setProperty("org.jpox.poid.generatorClass", "org.jpox.poid.SequenceTablePoidGenerator"); ! ! JDOUtil.pmfactory = JDOHelper.getPersistenceManagerFactory(properties); ! PersistenceManager pm = JDOUtil.pmfactory.getPersistenceManager(); ! pm.currentTransaction().begin(); ! Extent e = pm.getExtent(Client.class, true); ! Query query = pm.newQuery(e); ! Collection c = (Collection) query.execute(); ! logger.debug("Anzahl der gespeicherten Clients: " + c.size()); ! try{ ! Client client = new Client("dummy", "client", "dumm"); ! pm.makePersistent(client); ! pm.currentTransaction().commit(); ! pm.currentTransaction().begin(); ! pm.deletePersistent(client); ! } catch (Exception ex){ ! logger.fatal("Fehler beim Anlegen des \"dumm\" Clients", ex); ! pm.currentTransaction().begin(); ! } ! pm.currentTransaction().commit(); ! pm.close(); logger.info("Init MagicMap - done (took " + (System.currentTimeMillis() - startUp) + " ms)"); } --- 60,64 ---- startUp = System.currentTimeMillis(); ! Init.initJDO("org.jpox.driver.JPOXDriver", "jpox:java:comp/env/jdbc/magicmap", null, null); logger.info("Init MagicMap - done (took " + (System.currentTimeMillis() - startUp) + " ms)"); } |