You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2015/05/03 11:29:14 UTC
cayenne git commit: CAY-2010 Splitting DataSourceBuilder from
ServerRuntimeBuilder
Repository: cayenne
Updated Branches:
refs/heads/master 517df07b7 -> c2ce2dfa6
CAY-2010 Splitting DataSourceBuilder from ServerRuntimeBuilder
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/c2ce2dfa
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/c2ce2dfa
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/c2ce2dfa
Branch: refs/heads/master
Commit: c2ce2dfa6c3424093205f726ddbb59fb285ed2b3
Parents: 517df07
Author: aadamchik <aa...@apache.org>
Authored: Sun May 3 05:22:09 2015 -0400
Committer: aadamchik <aa...@apache.org>
Committed: Sun May 3 05:29:07 2015 -0400
----------------------------------------------------------------------
.../server/ServerRuntimeBuilder.java | 103 +------------------
.../cayenne/datasource/DataSourceBuilder.java | 1 +
.../server/ServerRuntimeBuilderIT.java | 43 ++------
docs/doc/src/main/resources/RELEASE-NOTES.txt | 1 +
4 files changed, 15 insertions(+), 133 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c2ce2dfa/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
index 55d390c..03e9bcd 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java
@@ -28,8 +28,8 @@ import javax.sql.DataSource;
import org.apache.cayenne.access.DataDomain;
import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.datasource.DataSourceBuilder;
import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.MapBuilder;
import org.apache.cayenne.di.Module;
/**
@@ -47,18 +47,11 @@ public class ServerRuntimeBuilder {
private Collection<String> configs;
private List<Module> modules;
private DataSourceFactory dataSourceFactory;
- private String jdbcUrl;
- private String jdbcDriver;
- private String jdbcUser;
- private String jdbcPassword;
- private int jdbcMinConnections;
- private int jdbcMaxConnections;
- private String validationQuery;
-
+
public static ServerRuntimeBuilder builder() {
return new ServerRuntimeBuilder();
}
-
+
public static ServerRuntimeBuilder builder(String name) {
return new ServerRuntimeBuilder(name);
}
@@ -86,6 +79,8 @@ public class ServerRuntimeBuilder {
* mapping. Moreover if the mapping contains no DataNodes, and the
* DataSource is set with this method, the builder would create a single
* default DataNode.
+ *
+ * @see DataSourceBuilder
*/
public ServerRuntimeBuilder dataSource(DataSource dataSource) {
this.dataSourceFactory = new FixedDataSourceFactory(dataSource);
@@ -100,61 +95,6 @@ public class ServerRuntimeBuilder {
return this;
}
- /**
- * Sets a database URL for the default DataSource.
- */
- public ServerRuntimeBuilder url(String url) {
- this.jdbcUrl = url;
- return this;
- }
-
- /**
- * Sets a driver Java class for the default DataSource.
- */
- public ServerRuntimeBuilder jdbcDriver(String driver) {
- // TODO: guess the driver from URL
- this.jdbcDriver = driver;
- return this;
- }
-
- /**
- * Sets a validation query for the default DataSource.
- *
- * @param validationQuery
- * a SQL string that returns some result. It will be used to
- * validate connections in the pool.
- */
- public ServerRuntimeBuilder validationQuery(String validationQuery) {
- this.validationQuery = validationQuery;
- return this;
- }
-
- /**
- * Sets a user name for the default DataSource.
- */
- public ServerRuntimeBuilder user(String user) {
- this.jdbcUser = user;
- return this;
- }
-
- /**
- * Sets a password for the default DataSource.
- */
- public ServerRuntimeBuilder password(String password) {
- this.jdbcPassword = password;
- return this;
- }
-
- public ServerRuntimeBuilder minConnections(int minConnections) {
- this.jdbcMinConnections = minConnections;
- return this;
- }
-
- public ServerRuntimeBuilder maxConnections(int maxConnections) {
- this.jdbcMaxConnections = maxConnections;
- return this;
- }
-
public ServerRuntimeBuilder addConfig(String configurationLocation) {
configs.add(configurationLocation);
return this;
@@ -226,39 +166,6 @@ public class ServerRuntimeBuilder {
});
}
- // URL and driver are the minimal requirement for
- // DelegatingDataSourceFactory to work
- else if (jdbcUrl != null && jdbcDriver != null) {
- prepend(new Module() {
- @Override
- public void configure(Binder binder) {
- binder.bind(DataDomain.class).toProvider(SyntheticNodeDataDomainProvider.class);
- MapBuilder<Object> props = binder.bindMap(Constants.PROPERTIES_MAP)
- .put(Constants.JDBC_DRIVER_PROPERTY, jdbcDriver).put(Constants.JDBC_URL_PROPERTY, jdbcUrl);
-
- if (jdbcUser != null) {
- props.put(Constants.JDBC_USERNAME_PROPERTY, jdbcUser);
- }
-
- if (jdbcPassword != null) {
- props.put(Constants.JDBC_PASSWORD_PROPERTY, jdbcPassword);
- }
-
- if (jdbcMinConnections > 0) {
- props.put(Constants.JDBC_MIN_CONNECTIONS_PROPERTY, Integer.toString(jdbcMinConnections));
- }
-
- if (jdbcMaxConnections > 0) {
- props.put(Constants.JDBC_MAX_CONNECTIONS_PROPERTY, Integer.toString(jdbcMaxConnections));
- }
-
- if (validationQuery != null) {
- props.put(Constants.JDBC_VALIDATION_QUERY_PROPERTY, validationQuery);
- }
-
- }
- });
- }
}
private void prepend(Module module) {
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c2ce2dfa/cayenne-server/src/main/java/org/apache/cayenne/datasource/DataSourceBuilder.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/datasource/DataSourceBuilder.java b/cayenne-server/src/main/java/org/apache/cayenne/datasource/DataSourceBuilder.java
index e02f8eb..a2659db 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/datasource/DataSourceBuilder.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/datasource/DataSourceBuilder.java
@@ -69,6 +69,7 @@ public class DataSourceBuilder {
}
public DataSourceBuilder driver(String driver) {
+ // TODO: guess the driver from URL
this.driver = driver;
return this;
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c2ce2dfa/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderIT.java b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderIT.java
index 36c8734..b220bc2 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilderIT.java
@@ -18,6 +18,14 @@
****************************************************************/
package org.apache.cayenne.configuration.server;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+import java.util.List;
+
+import javax.sql.DataSource;
+
import org.apache.cayenne.DataRow;
import org.apache.cayenne.access.DataNode;
import org.apache.cayenne.conn.DataSourceInfo;
@@ -33,14 +41,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import javax.sql.DataSource;
-
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-
@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
public class ServerRuntimeBuilderIT extends ServerCase {
@@ -87,16 +87,6 @@ public class ServerRuntimeBuilderIT extends ServerCase {
}
@Test
- public void testConfigFree_WithDBParams() {
-
- localRuntime = new ServerRuntimeBuilder().jdbcDriver(dsi.getJdbcDriver()).url(dsi.getDataSourceUrl())
- .password(dsi.getPassword()).user(dsi.getUserName()).minConnections(1).maxConnections(2).build();
-
- List<DataRow> result = SQLSelect.dataRowQuery("SELECT * FROM ARTIST").select(localRuntime.newContext());
- assertEquals(2, result.size());
- }
-
- @Test
public void testNoNodeConfig_WithDataSource() {
localRuntime = new ServerRuntimeBuilder().addConfig(CayenneProjects.TESTMAP_PROJECT).dataSource(dataSource)
@@ -113,23 +103,6 @@ public class ServerRuntimeBuilderIT extends ServerCase {
}
@Test
- public void testNoNodeConfig_WithDBParams() {
-
- localRuntime = new ServerRuntimeBuilder().addConfig(CayenneProjects.TESTMAP_PROJECT)
- .jdbcDriver(dsi.getJdbcDriver()).url(dsi.getDataSourceUrl()).password(dsi.getPassword())
- .user(dsi.getUserName()).minConnections(1).maxConnections(2).build();
-
- DataMap map = localRuntime.getDataDomain().getDataMap("testmap");
- assertNotNull(map);
-
- DataNode node = localRuntime.getDataDomain().getDefaultNode();
- assertNotNull(node);
- assertEquals(1, node.getDataMaps().size());
-
- assertSame(map, node.getDataMap("testmap"));
- }
-
- @Test
public void test_UnnamedDomain_MultiLocation() {
localRuntime = new ServerRuntimeBuilder().addConfigs(CayenneProjects.TESTMAP_PROJECT,
CayenneProjects.EMBEDDABLE_PROJECT).build();
http://git-wip-us.apache.org/repos/asf/cayenne/blob/c2ce2dfa/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index ecc2b48..c56c8a1 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -22,6 +22,7 @@ CAY-2004 EJBQL: Support for ordering on aggregate expressions
CAY-2007 Refactoring SelectTranslator for better extensibility
CAY-2008 Connection pool refactoring and validation query support in Cayenne DataSource
CAY-2009 Non-blocking connection pool
+CAY-2010 Splitting DataSourceBuilder from ServerRuntimeBuilder
Bug Fixes: