[#3956] Add Configuration set(DataSource) and set(Connection) for convenience

This commit is contained in:
lukaseder 2015-01-16 10:33:41 +01:00
parent a0471d19ea
commit f89c14fd49
2 changed files with 54 additions and 8 deletions

View File

@ -344,6 +344,32 @@ public interface Configuration extends Serializable {
*/
Configuration set(ConnectionProvider newConnectionProvider);
/**
* Change this configuration to hold a new connection wrapped in a
* {@link DefaultConnectionProvider}.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newConnection The new connection to be contained in the changed
* configuration.
* @return The changed configuration.
*/
Configuration set(Connection newConnection);
/**
* Change this configuration to hold a new data source wrapped in a
* {@link DataSourceConnectionProvider}.
* <p>
* This method is not thread-safe and should not be used in globally
* available <code>Configuration</code> objects.
*
* @param newConnection The new data source to be contained in the changed
* configuration.
* @return The changed configuration.
*/
Configuration set(DataSource newDataSource);
/**
* Change this configuration to hold a new transaction provider.
* <p>
@ -462,6 +488,26 @@ public interface Configuration extends Serializable {
*/
Configuration derive(ConnectionProvider newConnectionProvider);
/**
* Create a derived configuration from this one, with a new connection
* wrapped in a {@link DefaultConnectionProvider}.
*
* @param newConnection The new connection to be contained in the derived
* configuration.
* @return The derived configuration.
*/
Configuration derive(Connection newConnection);
/**
* Create a derived configuration from this one, with a new data source
* wrapped in a {@link DataSourceConnectionProvider}.
*
* @param newDataSource The new data source to be contained in the derived
* configuration.
* @return The derived configuration.
*/
Configuration derive(DataSource newDataSource);
/**
* Create a derived configuration from this one, with a new transaction
* provider.

View File

@ -343,17 +343,17 @@ public class DefaultConfiguration implements Configuration {
}
/**
* Convenience method for {@link #derive(ConnectionProvider)}, using a
* {@link DefaultConnectionProvider}.
* {@inheritDoc}
*/
@Override
public final Configuration derive(Connection newConnection) {
return derive(new DefaultConnectionProvider(newConnection));
}
/**
* Convenience method for {@link #derive(ConnectionProvider)}, using a
* {@link DataSourceConnectionProvider}.
* {@inheritDoc}
*/
@Override
public final Configuration derive(DataSource newDataSource) {
return derive(new DataSourceConnectionProvider(newDataSource));
}
@ -534,17 +534,17 @@ public class DefaultConfiguration implements Configuration {
// -------------------------------------------------------------------------
/**
* Convenience method for {@link #set(ConnectionProvider)}, using a
* {@link DefaultConnectionProvider}.
* {@inheritDoc}
*/
@Override
public final Configuration set(Connection newConnection) {
return set(new DefaultConnectionProvider(newConnection));
}
/**
* Convenience method for {@link #set(ConnectionProvider)}, using a
* {@link DataSourceConnectionProvider}.
* {@inheritDoc}
*/
@Override
public final Configuration set(DataSource newDataSource) {
return set(new DataSourceConnectionProvider(newDataSource));
}