В приведенном ниже коде я пытаюсь изменить источник данных и схему на основе 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;
}