You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ol...@apache.org on 2009/11/18 11:06:12 UTC
svn commit: r881711 - in /cayenne/main/trunk:
framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/ConnectionProperties.java
framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
pom.xml
Author: oltka
Date: Wed Nov 18 10:06:12 2009
New Revision: 881711
URL: http://svn.apache.org/viewvc?rev=881711&view=rev
Log:
CAY-1311
* rename 'cayenne.test.connection' to 'cayenneTestConnection' (Hudson chokes on the variables with dots since it executes some of the relevant scripts with Groovy).
* absorb the connection dictionary variables into the default config so that we can run the tests against all Java dbs without needing any external file. Even Derby can run with a completely in-memory database.
Add new variables, and in maven you can set new connection properties:
-DcayenneAdapter
-DcayenneJdbcUsername
-DcayenneJdbcPassword
-DcayenneJdbcUrl
-DcayenneJdbcDriver
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/ConnectionProperties.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
cayenne/main/trunk/pom.xml
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/ConnectionProperties.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/ConnectionProperties.java?rev=881711&r1=881710&r2=881711&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/ConnectionProperties.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/ConnectionProperties.java Wed Nov 18 10:06:12 2009
@@ -32,16 +32,19 @@
import org.apache.cayenne.conn.DataSourceInfo;
import org.apache.cayenne.project.CayenneUserDir;
+import org.apache.cayenne.unit.CayenneResources;
import org.apache.commons.collections.ExtendedProperties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* ConnectionProperties handles a set of DataSourceInfo objects using information stored
* in $HOME/.cayenne/connection.properties. As of now this is purely a utility class. Its
* features are not used in deployment.
- *
*/
public class ConnectionProperties {
+ private static Log logObj = LogFactory.getLog(ConnectionProperties.class);
public static final String EMBEDDED_DATASOURCE = "internal_embedded_datasource";
public static final String EMBEDDED_DATASOURCE_DBADAPTER = "org.apache.cayenne.dba.hsqldb.HSQLDBAdapter";
public static final String EMBEDDED_DATASOURCE_USERNAME = "sa";
@@ -57,8 +60,15 @@
public static final String URL_KEY = "jdbc.url";
public static final String DRIVER_KEY = "jdbc.driver";
+ public static final String ADAPTER_KEY_MAVEN = "cayenneAdapter";
+ public static final String USER_NAME_KEY_MAVEN = "cayenneJdbcUsername";
+ public static final String PASSWORD_KEY_MAVEN = "cayenneJdbcPassword";
+ public static final String URL_KEY_MAVEN = "cayenneJdbcUrl";
+ public static final String DRIVER_KEY_MAVEN = "cayenneJdbcDriver";
+
protected static ConnectionProperties sharedInstance;
- protected Map<String, DataSourceInfo> connectionInfos = Collections.synchronizedMap(new HashMap<String, DataSourceInfo>());
+ protected static Map<String, DataSourceInfo> connectionInfos = Collections
+ .synchronizedMap(new HashMap<String, DataSourceInfo>());
static {
sharedInstance = loadDefaultProperties();
@@ -75,16 +85,101 @@
* Loads connection properties from $HOME/.cayenne/connection.properties.
*/
protected static ConnectionProperties loadDefaultProperties() {
+
+ DataSourceInfo dsi = new DataSourceInfo();
+
+ String adapter = System.getProperty(ADAPTER_KEY_MAVEN);
+ String usr = System.getProperty(USER_NAME_KEY_MAVEN);
+ String pass = System.getProperty(PASSWORD_KEY_MAVEN);
+ String url = System.getProperty(URL_KEY_MAVEN);
+ String driver = System.getProperty(DRIVER_KEY_MAVEN);
+
File f = CayenneUserDir.getInstance().resolveFile(PROPERTIES_FILE);
try {
if (f.exists()) {
- return new ConnectionProperties(new ExtendedProperties(f
- .getAbsolutePath()));
+
+ ConnectionProperties cp = new ConnectionProperties(
+ new ExtendedProperties(f.getAbsolutePath()));
+
+ if ((!adapter.startsWith("$")
+ || !usr.startsWith("$")
+ || !pass.startsWith("$")
+ || !url.startsWith("$") || !driver.startsWith("$"))
+ && !System.getProperty("cayenneTestConnection").equals("null")) {
+
+ DataSourceInfo dsiOld = null;
+ if (connectionInfos.get(System.getProperty("cayenneTestConnection")) != null) {
+ dsiOld = connectionInfos.get(System
+ .getProperty("cayenneTestConnection"));
+ connectionInfos.remove(System
+ .getProperty("cayenneTestConnection"));
+ }
+
+ if (!adapter.startsWith("$")) {
+ dsi.setAdapterClassName(adapter);
+ }
+ else if (dsiOld != null) {
+ dsi.setAdapterClassName(dsiOld.getAdapterClassName());
+ }
+ if (!usr.startsWith("$")) {
+ dsi.setUserName(usr);
+ }
+ else if (dsiOld != null) {
+ dsi.setUserName(dsiOld.getUserName());
+ }
+ if (!pass.startsWith("$")) {
+ dsi.setPassword(pass);
+ }
+ else if (dsiOld != null) {
+ dsi.setPassword(dsiOld.getPassword());
+ }
+ if (!url.startsWith("$")) {
+ dsi.setDataSourceUrl(url);
+ }
+ else if (dsiOld != null) {
+ dsi.setDataSourceUrl(dsiOld.getDataSourceUrl());
+ }
+ if (!driver.startsWith("$")) {
+ dsi.setJdbcDriver(driver);
+ }
+ else if (dsiOld != null) {
+ dsi.setJdbcDriver(dsiOld.getJdbcDriver());
+ }
+ connectionInfos.put(System.getProperty("cayenneTestConnection"), dsi);
+ }
+ else {
+ return cp;
+ }
}
else {
+ if ((!adapter.startsWith("$")
+ || !usr.startsWith("$")
+ || !pass.startsWith("$")
+ || !url.startsWith("$") || !driver.startsWith("$"))
+ && !System.getProperty("cayenneTestConnection").equals("null")) {
+
+ if (!adapter.startsWith("$")) {
+ dsi.setAdapterClassName(adapter);
+ }
+ if (!usr.startsWith("$")) {
+ dsi.setUserName(usr);
+ }
+ if (!pass.startsWith("$")) {
+ dsi.setPassword(pass);
+ }
+ if (!url.startsWith("$")) {
+ dsi.setDataSourceUrl(url);
+ }
+ if (!driver.startsWith("$")) {
+ dsi.setJdbcDriver(driver);
+ }
+ connectionInfos.put(System.getProperty("cayenneTestConnection"), dsi);
+ }
+
// lets touch this file so that users would get a clue of what it is
createSamplePropertiesFile(f);
+
}
}
catch (IOException e) {
@@ -181,12 +276,12 @@
DataSourceInfo dsi = new DataSourceInfo();
String adapter = props.getString(ADAPTER_KEY);
-
+
// try legacy adapter key
- if(adapter == null) {
+ if (adapter == null) {
adapter = props.getString(ADAPTER20_KEY);
}
-
+
dsi.setAdapterClassName(adapter);
dsi.setUserName(props.getString(USER_NAME_KEY));
dsi.setPassword(props.getString(PASSWORD_KEY));
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java?rev=881711&r1=881710&r2=881711&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java Wed Nov 18 10:06:12 2009
@@ -54,7 +54,7 @@
public static final String TEST_RESOURCES_DESCRIPTOR = "spring-test-resources.xml";
- public static final String CONNECTION_NAME_KEY = "cayenne.test.connection";
+ public static final String CONNECTION_NAME_KEY = "cayenneTestConnection";
public static final String SKIP_SCHEMA_KEY = "cayenne.test.schema.skip";
public static final String TEST_DIR_KEY = "cayenne.test.dir";
public static final String DEFAULT_TEST_DIR = "target/testrun";
Modified: cayenne/main/trunk/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/pom.xml?rev=881711&r1=881710&r2=881711&view=diff
==============================================================================
--- cayenne/main/trunk/pom.xml (original)
+++ cayenne/main/trunk/pom.xml Wed Nov 18 10:06:12 2009
@@ -569,8 +569,31 @@
<version>2.5-SNAPSHOT</version>
<configuration>
<argLine>
- -Dcayenne.test.connection=${cayenne.test.connection} -Djava.net.preferIPv4Stack=true
+ -DcayenneTestConnection=${cayenneTestConnection} -Djava.net.preferIPv4Stack=true
</argLine>
+ <systemProperties>
+ <property>
+ <name>cayenneAdapter</name>
+ <value>${cayenneAdapter}</value>
+ </property>
+ <property>
+ <name>cayenneJdbcUsername</name>
+ <value>${cayenneJdbcUsername}</value>
+ </property>
+ <property>
+ <name>cayenneJdbcPassword</name>
+ <value>${cayenneJdbcPassword}</value>
+ </property>
+ <property>
+ <name>cayenneJdbcUrl</name>
+ <value>${cayenneJdbcUrl}</value>
+ </property>
+ <property>
+ <name>cayenneJdbcDriver</name>
+ <value>${cayenneJdbcDriver}</value>
+ </property>
+ </systemProperties>
+
</configuration>
</plugin>
<plugin>
@@ -670,7 +693,7 @@
<activation>
<activeByDefault>true</activeByDefault>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>internal_embedded_datasource</value>
</property>
</activation>
@@ -679,7 +702,7 @@
<id>frontbase</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>frontbase</value>
</property>
</activation>
@@ -696,7 +719,7 @@
<id>openbase</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>openbase</value>
</property>
</activation>
@@ -713,7 +736,7 @@
<id>h2</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>h2</value>
</property>
</activation>
@@ -730,7 +753,7 @@
<id>mysql</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>mysql</value>
</property>
</activation>
@@ -747,7 +770,7 @@
<id>oracle</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>oracle</value>
</property>
</activation>
@@ -764,7 +787,7 @@
<id>postgres</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>postgres</value>
</property>
</activation>
@@ -781,7 +804,7 @@
<id>derby</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>derby</value>
</property>
</activation>
@@ -796,7 +819,7 @@
<id>sqlserver</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>sqlserver</value>
</property>
</activation>
@@ -813,7 +836,7 @@
<id>sybase</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>sybase</value>
</property>
</activation>
@@ -830,7 +853,7 @@
<id>sqlite</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>sqlite</value>
</property>
</activation>
@@ -847,7 +870,7 @@
<id>db2</id>
<activation>
<property>
- <name>cayenne.test.connection</name>
+ <name>cayenneTestConnection</name>
<value>db2</value>
</property>
</activation>