Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1053 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
13 changed files with 215 additions and 113 deletions
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/* |
||||
* Copyright 2002-2009 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.jdbc.datasource.embedded; |
||||
|
||||
/** |
||||
* Allows DataSource connection properties to be configured in a DataSource implementation independent manner. |
||||
* @author Keith Donald |
||||
* @see DataSourceFactory |
||||
*/ |
||||
public interface ConnectionProperties { |
||||
|
||||
/** |
||||
* Set the JDBC driver to use to connect to the database. |
||||
* @param driverClass the jdbc driver class
|
||||
*/ |
||||
void setDriverClass(Class<?> driverClass); |
||||
|
||||
/** |
||||
* Sets the JDBC connection URL of the database. |
||||
* @param url the connection url |
||||
*/ |
||||
void setUrl(String url); |
||||
|
||||
/** |
||||
* Sets the username to use to connect to the database. |
||||
* @param username the username |
||||
*/ |
||||
void setUsername(String username); |
||||
|
||||
/** |
||||
* Sets the password to use to connect to the database. |
||||
* @param password the password |
||||
*/ |
||||
void setPassword(String password); |
||||
} |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2002-2009 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.jdbc.datasource.embedded; |
||||
|
||||
import javax.sql.DataSource; |
||||
|
||||
import org.springframework.jdbc.datasource.SimpleDriverDataSource; |
||||
|
||||
/** |
||||
* A factory for a kind of DataSource, such as a {@link SimpleDriverDataSource} or connection pool such as Apache DBCP or c3p0. |
||||
* Call {@link #getConnectionProperties()} to configure normalized DataSource properties before calling {@link #getDataSource()} to actually get the configured DataSource instance. |
||||
* @author Keith Donald |
||||
*/ |
||||
public interface DataSourceFactory { |
||||
|
||||
/** |
||||
* Allows properties of the DataSource to be configured. |
||||
*/ |
||||
ConnectionProperties getConnectionProperties(); |
||||
|
||||
/** |
||||
* Returns the DataSource with the connection properties applied. |
||||
*/ |
||||
DataSource getDataSource(); |
||||
|
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
package org.springframework.jdbc.datasource.embedded; |
||||
|
||||
import javax.sql.DataSource; |
||||
|
||||
import org.springframework.jdbc.datasource.SimpleDriverDataSource; |
||||
|
||||
public class SimpleDriverDataSourceFactory implements DataSourceFactory { |
||||
|
||||
private SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); |
||||
|
||||
public ConnectionProperties getConnectionProperties() { |
||||
return new ConnectionProperties() { |
||||
|
||||
public void setDriverClass(Class<?> driverClass) { |
||||
dataSource.setDriverClass(driverClass); |
||||
} |
||||
|
||||
public void setUrl(String url) { |
||||
dataSource.setUrl(url); |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
dataSource.setUsername(username); |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
dataSource.setPassword(password); |
||||
} |
||||
|
||||
}; |
||||
} |
||||
|
||||
public DataSource getDataSource() { |
||||
return dataSource; |
||||
} |
||||
|
||||
|
||||
} |
||||
Loading…
Reference in new issue