Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support different KRAD/KNS database platform #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
value="false" />
</bean>

<bean id="kradDbPlatform" class="org.kuali.rice.core.framework.persistence.platform.ConfigurableDatabasePlatform">
<property name="configProperty" value="krad.datasource.platform"/>
<property name="defaultPlatform" ref="dbPlatform"/>
</bean>


<bean
id="platformAwareDaoJdbc"
abstract="true"
Expand All @@ -87,7 +93,7 @@
ref="kradApplicationDataSource" />
<property
name="dbPlatform"
ref="dbPlatform" />
ref="kradDbPlatform" />
</bean>

<import resource="KRADSpringBeans-jpa.xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@
<bean id="lookupCriteriaGenerator" class="org.kuali.rice.krad.service.impl.LookupCriteriaGeneratorImpl"
p:dateTimeService-ref="dateTimeService"
p:dataDictionaryService-ref="dataDictionaryService"
p:dbPlatform-ref="dbPlatform"
p:dbPlatform-ref="kradDbPlatform"
p:dataObjectService-ref="dataObjectService"/>

<!-- Legacy Data Adapter Beans -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.kuali.rice.core.framework.persistence.platform;

import org.apache.commons.lang.StringUtils;
import org.kuali.rice.core.api.config.property.ConfigContext;
import org.kuali.rice.core.api.util.ClassLoaderUtils;
import org.springframework.beans.factory.FactoryBean;

/**
* Factory bean that allows for loading a {@link DatabasePlatform} from a classname specified by a specified
* configProperty. If the configProperty has no value, then the provided defaultPlatform will be returned from this
* factory bean instead.
*
* @author Eric Westfall
*/
public class ConfigurableDatabasePlatform implements FactoryBean<DatabasePlatform> {

private String configProperty;
private DatabasePlatform defaultPlatform;

@Override
public DatabasePlatform getObject() throws Exception {
if (!StringUtils.isBlank(configProperty)) {
String platformClassName = ConfigContext.getCurrentContextConfig().getProperty(configProperty);
if (!StringUtils.isBlank(platformClassName)) {
return (DatabasePlatform)ClassLoaderUtils.getClass(platformClassName).newInstance();
}
}
if (defaultPlatform == null) {
throw new IllegalArgumentException("No value for config property '" + configProperty + "' and no default platform specified.");
}
return defaultPlatform;
}

@Override
public Class<?> getObjectType() {
return DatabasePlatform.class;
}

@Override
public boolean isSingleton() {
return true;
}

public void setConfigProperty(String configProperty) {
this.configProperty = configProperty;
}

public void setDefaultPlatform(DatabasePlatform defaultPlatform) {
this.defaultPlatform = defaultPlatform;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<param name="datasource.pool.maxWait" override="false">30000</param>

<param name="datasource.ojb.platform" override="false">Oracle9i</param>
<param name="krad.datasource.ojb.platform" override="false">${datasource.ojb.platform}</param>

<param name="datasource.driver.name.Oracle" override="false">oracle.jdbc.OracleDriver</param>
<param name="datasource.platform.Oracle" override="false">org.kuali.rice.core.framework.persistence.platform.OracleDatabasePlatform</param>
Expand All @@ -59,12 +60,16 @@
<param name="datasource.platform.Oracle9i" override="false">org.kuali.rice.core.framework.persistence.platform.OracleDatabasePlatform</param>
<param name="datasource.ojb.sequenceManager.Oracle9i" override="false"></param>
<param name="datasource.ojb.sequenceManager.className.Oracle9i" override="false"></param>
<param name="krad.datasource.ojb.sequenceManager.Oracle9i" override="false"></param>
<param name="krad.datasource.ojb.sequenceManager.className.Oracle9i" override="false"></param>
<param name="datasource.pool.validationQuery.Oracle9i" override="false">select 1 from dual</param>

<param name="datasource.driver.name.MySQL" override="false">com.mysql.jdbc.Driver</param>
<param name="datasource.platform.MySQL" override="false">org.kuali.rice.core.framework.persistence.platform.MySQLDatabasePlatform</param>
<param name="datasource.ojb.sequenceManager.MySQL" override="false">org.apache.ojb.broker.platforms.KualiMySQLSequenceManagerImpl</param>
<param name="datasource.ojb.sequenceManager.className.MySQL" override="false">org.apache.ojb.broker.platforms.KualiMySQLSequenceManagerImpl</param>
<param name="krad.datasource.ojb.sequenceManager.MySQL" override="false">org.apache.ojb.broker.platforms.KualiMySQLSequenceManagerImpl</param>
<param name="krad.datasource.ojb.sequenceManager.className.MySQL" override="false">org.apache.ojb.broker.platforms.KualiMySQLSequenceManagerImpl</param>
<param name="datasource.pool.validationQuery.MySQL" override="false">select 1</param>

<param name="datasource.driver.name.Derby" override="false">org.apache.derby.jdbc.EmbeddedDriver</param>
Expand All @@ -77,6 +82,8 @@
<param name="datasource.platform" override="false">${datasource.platform.${datasource.ojb.platform}}</param>
<param name="datasource.ojb.sequenceManager" override="false">${datasource.ojb.sequenceManager.${datasource.ojb.platform}}</param>
<param name="datasource.ojb.sequenceManager.className" override="false">${datasource.ojb.sequenceManager.className.${datasource.ojb.platform}}</param>
<param name="krad.datasource.ojb.sequenceManager" override="false">${krad.datasource.ojb.sequenceManager.${krad.datasource.ojb.platform}}</param>
<param name="krad.datasource.ojb.sequenceManager.className" override="false">${krad.datasource.ojb.sequenceManager.className.${krad.datasource.ojb.platform}}</param>
<param name="datasource.pool.validationQuery" override="false">${datasource.pool.validationQuery.${datasource.ojb.platform}}</param>

<!-- datasource.btm.journal can be "null", "disk", or a class name -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
p:dataDictionaryService-ref="dataDictionaryService"
p:dataObjectMetaDataService-ref="dataObjectMetaDataService"
p:kualiConfigurationService-ref="kualiConfigurationService"
p:databasePlatform-ref="dbPlatform"
p:databasePlatform-ref="kradDbPlatform"
p:documentDao-ref="documentDao"
p:dateTimeService-ref="dateTimeService"
p:viewDictionaryService-ref="viewDictionaryService"/>
Expand Down Expand Up @@ -407,20 +407,21 @@
</list>
</property>
<property name="metadataLocation" value="classpath:org/kuali/rice/kns/config/OJB-repository-kns.xml"/>
<property name="platformConfigProperty" value="krad.datasource.ojb.platform" />
</bean>

<bean id="ojbCollectionHelper" class="org.kuali.rice.krad.service.util.OjbCollectionHelper"/>

<bean id="platformAwareDao" abstract="true"
class="org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb">
<property name="jcdAlias" value="kradApplicationDataSource"/>
<property name="dbPlatform" ref="dbPlatform"/>
<property name="dbPlatform" ref="kradDbPlatform"/>
</bean>

<bean id="platformAwareDaoJdbc" abstract="true"
class="org.kuali.rice.core.framework.persistence.jdbc.dao.PlatformAwareDaoBaseJdbc">
<property name="dataSource" ref="kradApplicationDataSource"/>
<property name="dbPlatform" ref="dbPlatform"/>
<property name="dbPlatform" ref="kradDbPlatform"/>
</bean>

<bean id="persistenceStructureServiceOjb"
Expand All @@ -432,7 +433,7 @@

<bean id="persistenceDaoOjb" parent="platformAwareDao" class="org.kuali.rice.krad.dao.impl.PersistenceDaoOjb">
<property name="jcdAlias" value="kradApplicationDataSource"/>
<property name="dbPlatform" ref="dbPlatform"/>
<property name="dbPlatform" ref="kradDbPlatform"/>
</bean>

<bean id="documentDaoOjb" parent="platformAwareDao" class="org.kuali.rice.krad.dao.impl.DocumentDaoOjb">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
useAutoCommit="0" ignoreAutoCommitExceptions="false">
<object-cache class="org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl"/>
<sequence-manager className="org.kuali.rice.core.framework.persistence.ojb.ConfigurableSequenceManager">
<attribute attribute-name="property.prefix" attribute-value="datasource.ojb.sequenceManager"/>
<attribute attribute-name="property.prefix" attribute-value="krad.datasource.ojb.sequenceManager"/>
</sequence-manager>
</jdbc-connection-descriptor>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class BaseOjbConfigurer extends BaseLifecycle implements InitializingBean

protected List<String> additionalMetadataLocations;

/**
* Defines the config property to use to determine the database platform for this OJB Configurer, configurer will
* check this first then fall back to the default of {@link Config#OJB_PLATFORM}
*/
private String platformConfigProperty;

/**
* No-arg constructor
*/
Expand Down Expand Up @@ -165,9 +171,9 @@ protected InputStream preprocessConnectionMetadata(InputStream inputStream) thro
Element descriptor = (Element)connectionDescriptors.item(index);
String currentPlatform = descriptor.getAttribute("platform");
if (StringUtils.isBlank(currentPlatform)) {
String ojbPlatform = ConfigContext.getCurrentContextConfig().getProperty(Config.OJB_PLATFORM);
String ojbPlatform = ConfigContext.getCurrentContextConfig().getProperty(identifyValidPlatformConfigProperty());
if (StringUtils.isEmpty(ojbPlatform)) {
throw new ConfigurationException("Could not configure OJB, the '" + Config.OJB_PLATFORM + "' configuration property was not set.");
throw new ConfigurationException("Could not configure OJB, the '" + identifyValidPlatformConfigProperty() + "' configuration property was not set.");
}
LOG.info("Setting OJB connection descriptor database platform to '" + ojbPlatform + "'");
descriptor.setAttribute("platform", ojbPlatform);
Expand Down Expand Up @@ -291,4 +297,23 @@ public List<String> getAdditionalMetadataLocations() {
public void setAdditionalMetadataLocations(List<String> additionalMetadataLocations) {
this.additionalMetadataLocations = additionalMetadataLocations;
}

public String getPlatformConfigProperty() {
return platformConfigProperty;
}

public void setPlatformConfigProperty(String platformConfigProperty) {
this.platformConfigProperty = platformConfigProperty;
}

private String identifyValidPlatformConfigProperty() {
String validPlatformConfigProperty = Config.OJB_PLATFORM;
if (!StringUtils.isBlank(getPlatformConfigProperty())) {
String ojbPlatform = ConfigContext.getCurrentContextConfig().getProperty(getPlatformConfigProperty());
if (!StringUtils.isBlank(ojbPlatform)) {
validPlatformConfigProperty = getPlatformConfigProperty();
}
}
return validPlatformConfigProperty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ public PersistenceBroker getBroker() {
return this.broker;
}

public String getPropertyPrefix() {
private String getPropertyPrefix() {
String propertyPrefix = DEFAULT_PROPERTY_PREFIX;
// check the sequence descriptor
SequenceDescriptor sd = getBroker().serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
String propertyPrefix = null;
if (sd != null) {
propertyPrefix = sd.getConfigurationProperties().getProperty(PROPERTY_PREFIX_ATTRIBUTE);
}
if (StringUtils.isBlank(propertyPrefix)) {
propertyPrefix = DEFAULT_PROPERTY_PREFIX;
String configuredPropertyPrefix = sd.getConfigurationProperties().getProperty(PROPERTY_PREFIX_ATTRIBUTE);
if (!StringUtils.isBlank(ConfigContext.getCurrentContextConfig().getProperty(getSequenceManagerClassNameProperty(configuredPropertyPrefix)))) {
propertyPrefix = configuredPropertyPrefix;
}
}
return propertyPrefix;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.kuali.rice.core.api.criteria.GenericQueryResults;
import org.kuali.rice.core.api.criteria.LookupCustomizer;
import org.kuali.rice.core.api.criteria.QueryByCriteria;
import org.kuali.rice.core.framework.persistence.dao.PlatformAwareDao;
import org.kuali.rice.krad.bo.ModuleConfiguration;
import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
import org.kuali.rice.krad.service.KualiModuleService;
Expand All @@ -30,6 +31,7 @@
import java.util.Map;

public class CriteriaLookupDaoProxy implements CriteriaLookupDao {

CriteriaLookupDao criteriaLookupDaoOjb;

private static KualiModuleService kualiModuleService;
Expand All @@ -54,6 +56,8 @@ private CriteriaLookupDao getDao(Class clazz) {
} else {
CriteriaLookupDaoOjb classSpecificLookupDaoOjb = new CriteriaLookupDaoOjb();
classSpecificLookupDaoOjb.setJcdAlias(dataSourceName);
// now we need to make sure we set the platform properly by grabbing the one from the OJB platform...
classSpecificLookupDaoOjb.setDbPlatform(((PlatformAwareDao)criteriaLookupDaoOjb).getDbPlatform());
lookupDaoValues.put(dataSourceName, classSpecificLookupDaoOjb);
return classSpecificLookupDaoOjb;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.kuali.rice.krad.dao.proxy;

import org.apache.commons.lang.StringUtils;
import org.kuali.rice.core.framework.persistence.dao.PlatformAwareDao;
import org.kuali.rice.kns.service.KNSServiceLocator;
import org.kuali.rice.krad.bo.BusinessObject;
import org.kuali.rice.krad.bo.ModuleConfiguration;
Expand Down Expand Up @@ -63,6 +64,8 @@ private BusinessObjectDao getDao(Class clazz) {
BusinessObjectDaoOjb boDaoOjb = new BusinessObjectDaoOjb(
KNSServiceLocator.getPersistenceStructureService());
boDaoOjb.setJcdAlias(dataSourceName);
// now we need to make sure we set the platform properly by grabbing the one from the OJB platform...
boDaoOjb.setDbPlatform(((PlatformAwareDao)businessObjectDaoOjb).getDbPlatform());
// add to our cache of bo daos
boDaoValues.put(dataSourceName, boDaoOjb);
return boDaoOjb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.kuali.rice.krad.dao.proxy;

import org.apache.commons.lang.StringUtils;
import org.kuali.rice.core.framework.persistence.dao.PlatformAwareDao;
import org.kuali.rice.krad.bo.ModuleConfiguration;
import org.kuali.rice.krad.dao.BusinessObjectDao;
import org.kuali.rice.krad.dao.DocumentDao;
Expand Down Expand Up @@ -61,6 +62,8 @@ private DocumentDao getDao(Class<? extends Document> clazz) {

// set the data source alias
documentDaoOjbInstance.setJcdAlias(dataSourceName);
// now we need to make sure we set the platform properly by grabbing the one from the OJB platform...
documentDaoOjbInstance.setDbPlatform(((PlatformAwareDao)documentDaoOjb).getDbPlatform());

documentDaoValues.put(dataSourceName, documentDaoOjbInstance);
return documentDaoOjbInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.commons.lang.StringUtils;
import org.kuali.rice.core.api.CoreApiServiceLocator;
import org.kuali.rice.core.framework.persistence.dao.PlatformAwareDao;
import org.kuali.rice.kns.service.KNSServiceLocator;
import org.kuali.rice.krad.bo.ModuleConfiguration;
import org.kuali.rice.krad.dao.LookupDao;
Expand Down Expand Up @@ -64,6 +65,8 @@ private LookupDao getDao(Class clazz) {
classSpecificLookupDaoOjb.setDateTimeService(CoreApiServiceLocator.getDateTimeService());
classSpecificLookupDaoOjb.setDataDictionaryService(
KRADServiceLocatorWeb.getDataDictionaryService());
// now we need to make sure we set the platform properly by grabbing the one from the OJB platform...
classSpecificLookupDaoOjb.setDbPlatform(((PlatformAwareDao)lookupDaoOjb).getDbPlatform());
lookupDaoValues.put(dataSourceName, classSpecificLookupDaoOjb);
return classSpecificLookupDaoOjb;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.commons.lang.StringUtils;
import org.apache.ojb.broker.core.proxy.ProxyHelper;
import org.kuali.rice.core.framework.persistence.dao.PlatformAwareDao;
import org.kuali.rice.krad.bo.ModuleConfiguration;
import org.kuali.rice.krad.dao.PersistenceDao;
import org.kuali.rice.krad.dao.impl.PersistenceDaoOjb;
Expand Down Expand Up @@ -56,6 +57,8 @@ private PersistenceDao getDao(Class clazz) {
//using OJB
PersistenceDaoOjb persistDaoOjb = new PersistenceDaoOjb();
persistDaoOjb.setJcdAlias(dataSourceName);
// now we need to make sure we set the platform properly by grabbing the one from the OJB platform...
persistDaoOjb.setDbPlatform(((PlatformAwareDao)persistenceDaoOjb).getDbPlatform());

persistenceDaoValues.put(dataSourceName, persistDaoOjb);
return persistDaoOjb;
Expand Down