protected PersistenceUnitInfo findPersistenceUnitInfo(Session session) { String sessionName = session.getName(); int index = sessionName.indexOf('-'); while (index != -1) { String urlAndName = sessionName.substring(0, index) + sessionName.substring(index + 1); if (log.isDebugEnabled()) { log.debug("Trying to find PersistenceInfo using [" + urlAndName + "]"); } EntityManagerSetupImpl emSetup = EntityManagerFactoryProvider.getEntityManagerSetupImpl(urlAndName); if (emSetup != null) { if (log.isDebugEnabled()) { log.debug("Found PersistenceInfo using [" + urlAndName + "]"); } return emSetup.getPersistenceUnitInfo(); } index = sessionName.indexOf('-', index + 1); } return null; } }
public static void runInSEMode(SchemaManager mgr, boolean shouldDropFirst) { String str = getConfigPropertyAsString(JAVASE_DB_INTERACTION, null ,"true"); boolean interactWithDB = Boolean.valueOf(str.toLowerCase()).booleanValue(); if (!interactWithDB){ return; } createOrReplaceDefaultTables(mgr, shouldDropFirst); }
/** * Check the provided map for an object with the given key. If that object is not available, check the * System properties. If it is not available from either location, return the default value. * @param propertyKey * @param defaultValue * @return */ public String getConfigPropertyAsString(String propertyKey, String defaultValue){ return getConfigPropertyAsStringLogDebug(propertyKey, predeployProperties, defaultValue, session); }
ddlGeneration = (String)getConfigPropertyAsString(DDL_GENERATION, props, NONE); ddlGeneration = ddlGeneration.toLowerCase(); if(ddlGeneration.equals(NONE)) { String ddlGenerationMode = (String) getConfigPropertyAsString(DDL_GENERATION_MODE, props, DEFAULT_DDL_GENERATION_MODE); appLocation = (String)getConfigPropertyAsString( APP_LOCATION, props, DEFAULT_APP_LOCATION); createDDLJdbc = (String)getConfigPropertyAsString( CREATE_JDBC_DDL_FILE, props, DEFAULT_CREATE_JDBC_FILE_NAME); dropDDLJdbc = (String)getConfigPropertyAsString( DROP_JDBC_DDL_FILE, props, DEFAULT_DROP_JDBC_FILE_NAME); runInSEMode(mgr, shouldDropFirst); writeDDLsToFiles(mgr, appLocation, createDDLJdbc, dropDDLJdbc); writeDDLsToFiles(mgr, appLocation, createDDLJdbc, dropDDLJdbc); } else if (ddlGenerationMode.equals(DDL_BOTH_GENERATION)) { runInSEMode(mgr, shouldDropFirst); writeDDLsToFiles(mgr, appLocation, createDDLJdbc, dropDDLJdbc);
if (persistenceActivator.isPersistenceProviderSupported(providerClassName)){ String puName = PersistenceUnitProcessor.buildPersistenceUnitName(persistenceUnitInfo.getPersistenceUnitRootUrl(),persistenceUnitInfo.getPersistenceUnitName()); EntityManagerSetupImpl emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(puName); Map mergedProperties = EntityManagerFactoryProvider.mergeMaps(m, persistenceUnitInfo.getProperties()); String weaving = EntityManagerFactoryProvider.getConfigPropertyAsString(TopLinkProperties.WEAVING, mergedProperties, null); if (emSetupImpl == null){ emSetupImpl = new EntityManagerSetupImpl(); EntityManagerFactoryProvider.addEntityManagerSetupImpl(persistenceUnitInfo.getPersistenceUnitRootUrl()+persistenceUnitInfo.getPersistenceUnitName(), emSetupImpl);
predeployProperties = mergeMaps(extendedProperties, persistenceUnitInfo.getProperties()); translateOldProperties(predeployProperties, null); warnOldProperties(predeployProperties, session); String transTypeString = getConfigPropertyAsStringLogDebug(TopLinkProperties.TRANSACTION_TYPE, predeployProperties, session); if ( transTypeString != null ){ transactionType=PersistenceUnitTransactionType.valueOf(transTypeString); EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerFactoryProvider.TOPLINK_ORM_THROW_EXCEPTIONS, predeployProperties, "true", session));
Map deployProperties = mergeMaps(additionalProperties, predeployProperties); translateOldProperties(deployProperties, session); session.initializeDescriptors(); } else { login(session, deployProperties); generateDDLFiles(session, deployProperties, !isInContainerMode);
String puName = PersistenceUnitProcessor.buildPersistenceUnitName(info.getPersistenceUnitRootUrl(), info.getPersistenceUnitName()); emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(puName); if (emSetupImpl == null){ emSetupImpl = new EntityManagerSetupImpl(); emSetupImpl.setIsInContainerMode(true); EntityManagerFactoryProvider.addEntityManagerSetupImpl(puName, emSetupImpl);
emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(puName); if (emSetupImpl == null || emSetupImpl.isUndeployed()){ if (!initialized) { emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl(puName); if (!isPersistenceProviderSupported(emSetupImpl.getPersistenceUnitInfo().getPersistenceProviderClassName())){ return null;
public static void writeDDLsToFiles(SchemaManager mgr, String appLocation, String createDDLJdbc, String dropDDLJdbc) { // Ensure that the appLocation string ends with File.seperator appLocation = addFileSeperator(appLocation); if (null != createDDLJdbc) { String createJdbcFileName = appLocation + createDDLJdbc; mgr.outputCreateDDLToFile(createJdbcFileName); } if (null != dropDDLJdbc) { String dropJdbcFileName = appLocation + dropDDLJdbc; mgr.outputDropDDLToFile(dropJdbcFileName); } mgr.setCreateSQLFiles(false); // When running in the application server environment always ensure that // we write out both the drop and create table files. createOrReplaceDefaultTables(mgr, true); mgr.closeDDLWriter(); }
/** * Check the provided map for an object with the given key. If that object is not available, check the * System properties. If it is not available from either location, return the default value. * @param propertyKey * @param map * @param defaultValue * @return */ public static String getConfigPropertyAsString(String propertyKey, Map overrides, String defaultValue){ String value = getConfigPropertyAsString(propertyKey, overrides); if (value == null){ value = defaultValue; } return value; }
/** * This is used to return either the defaultDatasource or, if one exists, a datasource * defined under the property from the Map m. This method will build a DataSourceImpl * object to hold the url if the property in Map m defines a string instead of a datasource. */ protected javax.sql.DataSource getDatasourceFromProperties(Map m, String property, javax.sql.DataSource defaultDataSource){ Object datasource = getConfigPropertyLogDebug(property, m, session); if ( datasource == null ){ return defaultDataSource; } if ( datasource instanceof String){ // Create a dummy DataSource that will throw an exception on access return new DataSourceImpl((String)datasource, null, null, null); } if ( !(datasource instanceof javax.sql.DataSource) ){ //A warning should be enough. Though an error might be better, the properties passed in could contain anything session.log(SessionLog.WARNING, SessionLog.PROPERTIES, "invalid_datasource_property_value", property, datasource); return defaultDataSource; } return (javax.sql.DataSource)datasource; }
/** * This is a TEMPORARY method that will be removed. * DON'T USE THIS METHOD - for internal use only. * @param Map m * @param AbstractSession session */ public static void translateOldProperties(Map m, AbstractSession session) { for(int i=0; i < oldPropertyNames.length; i++) { Object value = getConfigPropertyAsString(oldPropertyNames[i][1], m); if(value != null) { if(session != null){ session.log(SessionLog.INFO, SessionLog.TRANSACTION, "deprecated_property", oldPropertyNames[i]); } m.put(oldPropertyNames[i][0], value); } } }
public String getConfigPropertyAsString(String propertyKey){ return getConfigPropertyAsStringLogDebug(propertyKey, predeployProperties, session); }
if (EntityManagerFactoryProvider.getConfigPropertyAsString(TopLinkProperties.JDBC_BIND_PARAMETERS, m) == null) {
public static String getConfigPropertyAsStringLogDebug(String propertyKey, Map overrides, String defaultValue, AbstractSession session){ String value = getConfigPropertyAsStringLogDebug(propertyKey, overrides, session); if (value == null){ value = defaultValue; session.log(SessionLog.FINEST, SessionLog.PROPERTIES, "property_value_default", new Object[]{propertyKey, value}); } return value; }
/** * Set ServerSession name but do not register the session. * The session registration should be done in sync * with increment of the deployment counter, as otherwise the * undeploy will not behave correctly in case of a more * than one predeploy request for the same session name. * @param m the combined properties map. */ protected void setServerSessionName(Map m) { // use default session name if none is provided String name = EntityManagerFactoryProvider.getConfigPropertyAsString(TopLinkProperties.SESSION_NAME, m); if(name == null) { if (persistenceUnitInfo.getPersistenceUnitRootUrl() != null){ name = persistenceUnitInfo.getPersistenceUnitRootUrl().toString() + "-" + persistenceUnitInfo.getPersistenceUnitName(); } else { name = persistenceUnitInfo.getPersistenceUnitName(); } } session.setName(name); }
protected boolean isValidationOnly(Map m, boolean shouldMergeMap) { if(shouldMergeMap) { m = mergeWithExistingMap(m); } String validationOnlyString = getConfigPropertyAsStringLogDebug(TOPLINK_VALIDATION_ONLY_PROPERTY, m, session); if(validationOnlyString != null) { return Boolean.parseBoolean(validationOnlyString); } else { return false; } }
/** * In cases where there is no data source, we will use properties to configure the login for * our session. This method gets those properties and sets them on the login. * @param login * @param m */ protected void updateLoginDefaultConnector(DatasourceLogin login, Map m){ if((login.getConnector() instanceof DefaultConnector)) { DatabaseLogin dbLogin = (DatabaseLogin)login; // Note: This call does not checked the stored persistenceUnitInfo or extended properties because // the map passed into this method should represent the full set of properties we expect to process String jdbcDriver = getConfigPropertyAsStringLogDebug(TopLinkProperties.JDBC_DRIVER, m, session); String connectionString = getConfigPropertyAsStringLogDebug(TopLinkProperties.JDBC_URL, m, session); if(connectionString != null) { dbLogin.setConnectionString(connectionString); } if(jdbcDriver != null) { dbLogin.setDriverClassName(jdbcDriver); } } }
protected void processSessionCustomizer(Map m, ClassLoader loader) { String sessionCustomizerClassName = getConfigPropertyAsStringLogDebug(TopLinkProperties.SESSION_CUSTOMIZER, m, session); if(sessionCustomizerClassName == null) { return; } Class sessionCustomizerClass = findClassForProperty(sessionCustomizerClassName, TopLinkProperties.SESSION_CUSTOMIZER, loader); SessionCustomizer sessionCustomizer; try { sessionCustomizer = (SessionCustomizer)sessionCustomizerClass.newInstance(); sessionCustomizer.customize(session); } catch (Exception ex) { throw EntityManagerSetupException.failedWhileProcessingProperty(TopLinkProperties.SESSION_CUSTOMIZER, sessionCustomizerClassName, ex); } }