/** * 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); }
/** * 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; }
/** * Returns the current Compass session associated with the {@link javax.persistence.EntityManager}. * Compass Session is associated with an Entity Manager when a transaction is started and removed when the * transaction commits/rollsback. * * <p>The session can be used to perform searches that needs to take into account current transactional changes * or to perform additional Compass operations that are not reflected by the mirroring feature. */ public static CompassSession getCurrentCompassSession(EntityManager em) { oracle.toplink.essentials.ejb.cmp3.EntityManager nativeEm = (oracle.toplink.essentials.ejb.cmp3.EntityManager) NativeJpaHelper.extractNativeJpa(em); return findCompassSessionEventListener(nativeEm.getServerSession()).getCurrentCompassSession(nativeEm.getUnitOfWork()); }
private static CompassSessionEventListener findCompassSessionEventListener(EntityManager em) throws CompassException { return findCompassSessionEventListener(((oracle.toplink.essentials.ejb.cmp3.EntityManager) NativeJpaHelper.extractNativeJpa(em)).getServerSession()); }
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); }
/** * @see org.seasar.framework.jpa.Dialect#detach(javax.persistence.EntityManager, java.lang.Object) */ public void detach(EntityManager em, Object managedEntity) { Object delegate = em.getDelegate(); oracle.toplink.essentials.ejb.cmp3.EntityManager toplinkEm = oracle.toplink.essentials.ejb.cmp3.EntityManager.class .cast(delegate); UnitOfWork work = toplinkEm.getUnitOfWork(); work.unregisterObject(managedEntity); }
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(); }
/** * 実行結果がEJBQueryだった場合、getDatabaseQueryメソッドを実行してNamedQueryの存在チェックを行います。 * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) */ public Object invoke(MethodInvocation invocation) throws Throwable { Object ret = invocation.proceed(); if (ret instanceof EJBQuery) { EJBQuery query = EJBQuery.class.cast(ret); query.getDatabaseQuery(); } return ret; }
/** * 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; }
/** * Convert the given object to the class represented by the given temporal type. * @return an object represting the given TemporalType */ protected Object convertTemporalType(Object value, TemporalType type) { ConversionManager conversionManager = ((oracle.toplink.essentials.internal.sessions.AbstractSession)getEntityManager().getActiveSession()).getDatasourcePlatform().getConversionManager(); if (type == TemporalType.TIME) { return conversionManager.convertObject(value, ClassConstants.TIME); } else if (type == TemporalType.TIMESTAMP) { return conversionManager.convertObject(value, ClassConstants.TIMESTAMP); } else if (type == TemporalType.DATE) { return conversionManager.convertObject(value, ClassConstants.SQLDATE); } return value; }
/** * @see org.seasar.framework.jpa.Dialect#getConnection(javax.persistence.EntityManager) */ public Connection getConnection(EntityManager em) { Object delegate = em.getDelegate(); oracle.toplink.essentials.ejb.cmp3.EntityManager toplinkEm = oracle.toplink.essentials.ejb.cmp3.EntityManager.class .cast(delegate); return toplinkEm.getServerSession().getLogin().getConnector().connect( new Properties()); }
public String getConfigPropertyAsString(String propertyKey){ return getConfigPropertyAsStringLogDebug(propertyKey, predeployProperties, session); }
/** * 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 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); } }
/** * Updates server session name if changed. * @return true if the name has changed. */ protected boolean updateSessionName(Map m) { String newName = getConfigPropertyAsStringLogDebug(TopLinkProperties.SESSION_NAME, m, session); if(newName == null || newName.equals(session.getName())) { return false; } removeSessionFromGlobalSessionManager(); session.setName(newName); addSessionToGlobalSessionManager(); return true; }