use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.
the class AbstractSQLTest method init.
private static synchronized void init() {
try {
Properties prop = new Properties();
prop.load(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/env.properties"));
boolean initialized = null == prop.getProperty("initialized") ? false : Boolean.valueOf(prop.getProperty("initialized"));
String databases = prop.getProperty("databases");
if (!Strings.isNullOrEmpty(databases)) {
for (String each : databases.split(",")) {
databaseTypes.add(findDatabaseType(each.trim()));
}
}
if (initialized) {
createSchema(DatabaseType.H2);
} else {
for (DatabaseType each : getDatabaseTypes()) {
createSchema(each);
}
}
} catch (final IOException ex) {
ex.printStackTrace();
}
}
use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.
the class AbstractSQLTest method importDataSet.
protected final void importDataSet() throws Exception {
for (DatabaseType databaseType : getDatabaseTypes()) {
if (databaseType == getCurrentDatabaseType() || null == getCurrentDatabaseType()) {
DatabaseEnvironment dbEnv = new DatabaseEnvironment(databaseType);
for (String each : getInitDataSetFiles()) {
InputStream is = AbstractSQLTest.class.getClassLoader().getResourceAsStream(each);
IDataSet dataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(is));
IDatabaseTester databaseTester = new ShardingJdbcDatabaseTester(dbEnv.getDriverClassName(), dbEnv.getURL(getDatabaseName(each)), dbEnv.getUsername(), dbEnv.getPassword(), dbEnv.getSchema(getDatabaseName(each)));
databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
}
}
}
}
use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.
the class AbstractHintTest method initShardingDataSources.
protected final Map<DatabaseType, ShardingDataSource> initShardingDataSources() throws SQLException {
Map<DatabaseType, Map<String, DataSource>> dataSourceMap = createDataSourceMap();
for (Map.Entry<DatabaseType, Map<String, DataSource>> each : dataSourceMap.entrySet()) {
ShardingRule shardingRule = getShardingRule(each);
getShardingDataSources().put(each.getKey(), new ShardingDataSource(each.getValue(), shardingRule));
}
return getShardingDataSources();
}
use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.
the class RoutingDatabaseOnlyWithHintForDMLTest method assertInsertWithPartialPlaceholders.
@Test
public void assertInsertWithPartialPlaceholders() throws SQLException, DatabaseUnitException {
for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
for (int i = 1; i <= 10; i++) {
try (HintShardingValueHelper helper = new HintDatabaseShardingValueHelper(i);
Connection connection = each.getValue().getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(String.format(DatabaseTestSQL.INSERT_WITH_PARTIAL_PLACEHOLDERS_SQL, i, i))) {
preparedStatement.setString(1, "insert");
preparedStatement.executeUpdate();
}
}
assertDataSet(each.getValue().getConnection(), each.getKey(), "insert", "insert");
}
}
use of io.shardingjdbc.core.constant.DatabaseType in project sharding-jdbc by shardingjdbc.
the class ShardingDatabaseOnlyWithHintForDMLTest method assertInsertWithPartialPlaceholders.
@Test
public void assertInsertWithPartialPlaceholders() throws SQLException, DatabaseUnitException {
for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
for (int i = 1; i <= 10; i++) {
try (HintShardingValueHelper helper = new HintShardingValueHelper(i, i);
Connection connection = each.getValue().getConnection()) {
PreparedStatement preparedStatement = connection.prepareStatement(String.format(DatabaseTestSQL.INSERT_WITH_PARTIAL_PLACEHOLDERS_SQL, i, i));
preparedStatement.setString(1, "insert");
preparedStatement.executeUpdate();
}
}
assertDataSet(each.getValue().getConnection(), each.getKey(), "insert", "insert");
}
}
Aggregations