1 23 24 29 30 package com.sun.jdo.spi.persistence.support.sqlstore.ejb; 31 32 import java.sql.Connection ; 33 import java.sql.SQLException ; 34 import java.util.Properties ; 35 import java.util.ResourceBundle ; 36 37 import javax.sql.DataSource ; 38 import javax.naming.InitialContext ; 39 import javax.naming.NamingException ; 40 41 import com.sun.jdo.api.persistence.support.JDOFatalUserException; 42 import com.sun.jdo.api.persistence.support.PersistenceManagerFactory; 43 import com.sun.jdo.spi.persistence.support.sqlstore.LogHelperPersistenceManager; 44 45 import com.sun.jdo.spi.persistence.utility.I18NHelper; 46 import com.sun.jdo.spi.persistence.utility.StringHelper; 47 import com.sun.jdo.spi.persistence.utility.database.DatabaseConstants; 48 import com.sun.jdo.spi.persistence.utility.logging.Logger; 49 50 import com.sun.enterprise.deployment.Application; 51 import com.sun.enterprise.deployment.BundleDescriptor; 52 import com.sun.enterprise.deployment.EjbBundleDescriptor; 53 import com.sun.enterprise.connectors.ConnectorRuntime; 54 55 61 public class DeploymentHelper 62 { 63 64 71 private final static String DEFAULT_NAME = "default"; 73 74 private final static ResourceBundle messages = I18NHelper.loadBundle( 75 "com.sun.jdo.spi.persistence.support.sqlstore.Bundle", DeploymentHelper.class.getClassLoader()); 77 78 79 private static Logger logger = LogHelperPersistenceManager.getLogger(); 80 81 88 public static String getDDLNamePrefix(Object info) { 89 StringBuffer rc = new StringBuffer (); 90 91 if (info instanceof BundleDescriptor) { 92 BundleDescriptor bundle = (BundleDescriptor)info; 93 rc.append(bundle.getApplication().getRegistrationName()); 94 95 Application application = bundle.getApplication(); 96 if (!application.isVirtual()) { 97 String modulePath = bundle.getModuleDescriptor().getArchiveUri(); 98 int l = modulePath.length(); 99 100 rc.append(DatabaseConstants.NAME_SEPARATOR). 102 append(modulePath.substring(0, l - 4)); 103 } 104 105 } 107 return (rc.length() == 0)? DEFAULT_NAME : rc.toString(); 108 } 109 110 118 public static boolean isJavaToDatabase(EjbBundleDescriptor bundle) { 119 Properties userPolicy = bundle.getCMPResourceReference() 120 .getSchemaGeneratorProperties(); 121 return isJavaToDatabase(userPolicy); 122 } 123 124 132 public static boolean isJavaToDatabase(Properties prop) { 133 if (prop != null) { 134 String value = prop.getProperty(DatabaseConstants.JAVA_TO_DB_FLAG); 135 if (! StringHelper.isEmpty(value)) { 136 if (logger.isLoggable(Logger.FINE)) 137 logger.fine(DatabaseConstants.JAVA_TO_DB_FLAG + " property is set."); return Boolean.valueOf(value).booleanValue(); 139 } 140 } 141 return false; 142 } 143 144 156 public static Connection getConnection(String name) throws SQLException { 157 if (logger.isLoggable(logger.FINE)) { 158 logger.fine("ejb.DeploymentHelper.getconnection", name); } 160 return ConnectorRuntime.getRuntime().getConnection(name); 161 } 162 163 170 private static void handleUnexpectedInstance(String name, Object value) { 171 RuntimeException e = new JDOFatalUserException( 172 I18NHelper.getMessage(messages, 173 "ejb.jndi.unexpectedinstance", name, value.getClass().getName())); 175 logger.severe(e.toString()); 176 177 throw e; 178 179 } 180 } 181 | Popular Tags |