javadocs

Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/5ce09a7b
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/5ce09a7b
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/5ce09a7b

Branch: refs/heads/CAY-1946_1
Commit: 5ce09a7b7b708a6310e96ae4b18a887fea8baa02
Parents: 84b7514
Author: aadamchik <aadamc...@apache.org>
Authored: Sat Nov 22 17:45:50 2014 +0300
Committer: aadamchik <aadamc...@apache.org>
Committed: Sat Nov 22 17:47:13 2014 +0300

----------------------------------------------------------------------
 .../server/ServerRuntimeBuilder.java            | 310 ++++++++++---------
 1 file changed, 166 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/5ce09a7b/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 8b0263d..01115b7 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
@@ -40,148 +40,170 @@ import org.apache.cayenne.di.Module;
  */
 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;
-
-    public ServerRuntimeBuilder() {
-        this.configs = new LinkedHashSet<String>();
-        this.modules = new ArrayList<Module>();
-    }
-
-    public ServerRuntimeBuilder(String configurationLocation) {
-        this();
-        addConfig(configurationLocation);
-    }
-
-    /**
-     * Sets a DataSource that will override any DataSources found in the
-     * mapping. Moreover if the mapping contains no DataNodes, and the
-     * DataSource is set with this method, the builder would create a single
-     * default DataNode.
-     */
-    public ServerRuntimeBuilder dataSource(DataSource dataSource) {
-        this.dataSourceFactory = new FixedDataSourceFactory(dataSource);
-        return this;
-    }
-
-    public ServerRuntimeBuilder jndiDataSource(String location) {
-        this.dataSourceFactory = new FixedJNDIDataSourceFactory(location);
-        return this;
-    }
-
-    public ServerRuntimeBuilder url(String url) {
-        this.jdbcUrl = url;
-        return this;
-    }
-
-    public ServerRuntimeBuilder jdbcDriver(String driver) {
-        // TODO: guess the driver from URL
-        this.jdbcDriver = driver;
-        return this;
-    }
-
-    public ServerRuntimeBuilder user(String user) {
-        this.jdbcUser = user;
-        return this;
-    }
-
-    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;
-    }
-
-    public ServerRuntimeBuilder addConfigs(Collection<String> 
configurationLocations) {
-        configs.addAll(configurationLocations);
-        return this;
-    }
-
-    public ServerRuntimeBuilder addModule(Module module) {
-        modules.add(module);
-        return this;
-    }
-
-    public ServerRuntimeBuilder addModules(Collection<Module> modules) {
-        this.modules.addAll(modules);
-        return this;
-    }
-
-    public ServerRuntime build() {
-
-        buildModules();
-
-        String[] configs = this.configs.toArray(new 
String[this.configs.size()]);
-        Module[] modules = this.modules.toArray(new 
Module[this.modules.size()]);
-        return new ServerRuntime(configs, modules);
-    }
-
-    private void buildModules() {
-
-        if (dataSourceFactory != null) {
-
-            prepend(new Module() {
-                @Override
-                public void configure(Binder binder) {
-                    
binder.bind(DataDomain.class).toProvider(SyntheticNodeDataDomainProvider.class);
-                    
binder.bind(DataSourceFactory.class).toInstance(dataSourceFactory);
-                }
-            });
-
-        }
-        // 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));
-                    }
-                }
-            });
-        }
-    }
-
-    private void prepend(Module module) {
-        // prepend any special modules BEFORE custom modules, to allow callers
-        // to override our stuff
-        modules.add(0, module);
-    }
+       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;
+
+       /**
+        * Creates an empty builder.
+        */
+       public ServerRuntimeBuilder() {
+               this.configs = new LinkedHashSet<String>();
+               this.modules = new ArrayList<Module>();
+       }
+
+       /**
+        * An equivalent to creating builder with default constructor and 
calling
+        * {@link #addConfig(String)}.
+        */
+       public ServerRuntimeBuilder(String configurationLocation) {
+               this();
+               addConfig(configurationLocation);
+       }
+
+       /**
+        * Sets a DataSource that will override any DataSources found in the
+        * mapping. Moreover if the mapping contains no DataNodes, and the
+        * DataSource is set with this method, the builder would create a single
+        * default DataNode.
+        */
+       public ServerRuntimeBuilder dataSource(DataSource dataSource) {
+               this.dataSourceFactory = new FixedDataSourceFactory(dataSource);
+               return this;
+       }
+
+       /**
+        * Sets JNDI location for the default DataSource.
+        */
+       public ServerRuntimeBuilder jndiDataSource(String location) {
+               this.dataSourceFactory = new 
FixedJNDIDataSourceFactory(location);
+               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 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;
+       }
+
+       public ServerRuntimeBuilder addConfigs(Collection<String> 
configurationLocations) {
+               configs.addAll(configurationLocations);
+               return this;
+       }
+
+       public ServerRuntimeBuilder addModule(Module module) {
+               modules.add(module);
+               return this;
+       }
+
+       public ServerRuntimeBuilder addModules(Collection<Module> modules) {
+               this.modules.addAll(modules);
+               return this;
+       }
+
+       public ServerRuntime build() {
+
+               buildModules();
+
+               String[] configs = this.configs.toArray(new 
String[this.configs.size()]);
+               Module[] modules = this.modules.toArray(new 
Module[this.modules.size()]);
+               return new ServerRuntime(configs, modules);
+       }
+
+       private void buildModules() {
+
+               if (dataSourceFactory != null) {
+
+                       prepend(new Module() {
+                               @Override
+                               public void configure(Binder binder) {
+                                       
binder.bind(DataDomain.class).toProvider(SyntheticNodeDataDomainProvider.class);
+                                       
binder.bind(DataSourceFactory.class).toInstance(dataSourceFactory);
+                               }
+                       });
+
+               }
+               // 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));
+                                       }
+                               }
+                       });
+               }
+       }
+
+       private void prepend(Module module) {
+               // prepend any special modules BEFORE custom modules, to allow 
callers
+               // to override our stuff
+               modules.add(0, module);
+       }
 }

Reply via email to