com.landawn.abacus.util.SimpleDataSourceManager Maven / Gradle / Ivy
package com.landawn.abacus.util;
import java.util.Map;
import com.landawn.abacus.DataSource;
import com.landawn.abacus.DataSourceManager;
import com.landawn.abacus.DataSourceSelector;
import com.landawn.abacus.dataSource.SimpleSourceSelector;
class SimpleDataSourceManager implements DataSourceManager {
private final DataSource primaryDataSource;
private final Map activeDataSources;
private final Properties props = new Properties<>();
private final DataSourceSelector dataSourceSelector = new SimpleSourceSelector();
private boolean isClosed = false;
public SimpleDataSourceManager(final DataSource ds) {
this.primaryDataSource = ds;
if (N.isNullOrEmpty(ds.getName())) {
this.activeDataSources = N.asMap(SimpleDataSource.PRIMARY, ds);
} else {
this.activeDataSources = N.asMap(ds.getName(), ds);
}
}
/**
* Gets the primary data source.
*
* @return
*/
@Override
public DataSource getPrimaryDataSource() {
return primaryDataSource;
}
/**
* Gets the active data source.
*
* @param dataSourceName
* @return
*/
@Override
public DataSource getActiveDataSource(String dataSourceName) {
return activeDataSources.get(dataSourceName);
}
/**
* Gets the active data sources.
*
* @return
*/
@Override
public Map getActiveDataSources() {
return activeDataSources;
}
/**
* Gets the data source selector.
*
* @return
*/
@Override
public DataSourceSelector getDataSourceSelector() {
return dataSourceSelector;
}
/**
* Gets the properties.
*
* @return
*/
@Override
public Properties getProperties() {
return props;
}
/**
* Close.
*/
@Override
public void close() {
if (isClosed) {
return;
}
primaryDataSource.close();
isClosed = true;
}
/**
* Checks if is closed.
*
* @return true, if is closed
*/
@Override
public boolean isClosed() {
return isClosed;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy