在下面给出的代码中,我试图在tenantIdentifier的基础上更改数据源和模式。
例如:
@Override
protected DataSource selectDataSource(String tenantIdentifier) {
try {
InitialContext ic = new InitialContext();
dataSource = (DataSource) ic.lookup(JNDI_NAME);
} catch (Exception e) {
e.printStackTrace();
}
return dataSource;
}
@Override
public Connection getConnection(String tenantIdentifier) throws SQLException {
final Connection connection = selectDataSource(tenantIdentifier).getConnection();
try {
connection.createStatement().execute("select now()");
connection.createStatement().execute("USE " + tenantIdentifier);
} catch (final SQLException e) {
throw new HibernateException("Error trying to alter schema [" + tenantIdentifier + "]", e);
}
return connection;
}
答案 0 :(得分:0)
切换DataSource和架构期间的小开销(以ms为单位)。