1 24 package org.objectweb.speedo.j2eedo.test; 25 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.util.Properties ; 29 30 import javax.jdo.JDOException; 31 import javax.jdo.JDOHelper; 32 import javax.jdo.PersistenceManagerFactory; 33 34 import org.objectweb.speedo.api.SpeedoProperties; 35 import org.objectweb.speedo.j2eedo.bo.DatabaseImpl; 36 import org.objectweb.speedo.j2eedo.common.PMHolder; 37 import org.objectweb.util.monolog.Monolog; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 import org.objectweb.util.monolog.api.Logger; 40 import org.objectweb.util.monolog.api.LoggerFactory; 41 42 49 public class MainLauncher { 50 static Logger logger = null; 51 static { 52 LoggerFactory lf = Monolog.initialize(); 53 logger = lf.getLogger(MainLauncher.class.getName()); 54 } 55 56 final static Properties p = new Properties (); 57 public void initPMF() throws JDOException, Exception { 58 String speedoProperties = "speedo.properties"; 60 InputStream is = 61 DatabaseImpl.class.getClassLoader().getResourceAsStream( 62 speedoProperties); 63 if (is == null) { 64 System.err.println( 65 "[ERROR] No '" 66 + speedoProperties 67 + "' property file availlable in the classpath (classloader=" 68 + DatabaseImpl.class.getClassLoader()); 69 System.exit(2); 70 } 71 try { 72 p.load(is); 73 } catch (IOException e) { 74 System.err.println( 75 "[ERROR] Impossible to load the '" 76 + speedoProperties 77 + "' property file from the classpath: " 78 + e.getMessage()); 79 System.exit(2); 80 } 81 p.setProperty( 84 SpeedoProperties.MAPPING_STRUCTURE, 85 SpeedoProperties.MAPPING_STRUCTURE_CIR); 86 boolean useDriverDirectly = false; 87 String s = 88 System.getProperty( 89 SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME); 90 if (s != null) { 91 p.setProperty( 92 SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME, 93 s); 94 useDriverDirectly = true; 95 } 96 s = System.getProperty(SpeedoProperties.JDO_OPTION_CONNECTION_URL); 97 if (s != null) { 98 p.setProperty(SpeedoProperties.JDO_OPTION_CONNECTION_URL, s); 99 useDriverDirectly = true; 100 } 101 s = 102 System.getProperty( 103 SpeedoProperties.JDO_OPTION_CONNECTION_USER_NAME); 104 if (s != null) { 105 p.setProperty(SpeedoProperties.JDO_OPTION_CONNECTION_USER_NAME, s); 106 useDriverDirectly = true; 107 } 108 s = System.getProperty(SpeedoProperties.JDO_OPTION_CONNECTION_PASSWORD); 109 if (s != null) { 110 p.setProperty(SpeedoProperties.JDO_OPTION_CONNECTION_PASSWORD, s); 111 useDriverDirectly = true; 112 } 113 s = System.getProperty(SpeedoProperties.MAPPER_NAME); 114 if (s != null) { 115 p.setProperty(SpeedoProperties.MAPPER_NAME, s); 116 } 117 118 if (useDriverDirectly) { 119 p.remove(SpeedoProperties.JDO_OPTION_CONNECTION_FACTORY_NAME); 122 } 123 124 PersistenceManagerFactory pmf = 125 JDOHelper.getPersistenceManagerFactory(p); 126 PMHolder pmHolder = new PMHolder(pmf); 127 DatabaseImpl.initTestData(pmHolder); 128 } 129 130 139 public static void main(String [] args) throws JDOException, Exception { 140 MainLauncher ml = new MainLauncher(); 141 ml.initPMF(); 142 ml.doTest(); 143 } 144 145 152 public void doTest() throws JDOException, Exception { 153 PersistenceManagerFactory pmf = 155 JDOHelper.getPersistenceManagerFactory(p); 156 logger.log(BasicLevel.INFO, "Show connection properties:\n\t" + pmf.getProperties()); 157 } 158 } 159 | Popular Tags |