use of org.h2.jdbcx.JdbcDataSource in project syndesis by syndesisio.
the class MetricsCollectorTest method before.
@Before
public void before() throws IOException, ParseException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
DBI dbi = new DBI(ds);
this.jsondb = new SqlJsonDB(dbi, null, Arrays.asList(new Index("/pair", "key")));
try {
this.jsondb.dropTables();
} catch (Exception e) {
}
this.jsondb.createTables();
jsondbRM = new JsonDBRawMetrics(jsondb);
load();
CacheManager cacheManager = new LRUCacheManager(100);
EncryptionComponent encryptionComponent = new EncryptionComponent(null);
ResourceLoader resourceLoader = new DefaultResourceLoader();
// Create Data Manager
dataManager = new DataManager(cacheManager, Collections.emptyList(), null, encryptionComponent, resourceLoader);
intMH = new IntegrationMetricsHandler(dataManager);
}
use of org.h2.jdbcx.JdbcDataSource in project syndesis by syndesisio.
the class MemorySqlJsonDB method create.
public static CloseableJsonDB create(Collection<Index> indexes) {
JdbcDataSource ds = new JdbcDataSource();
DBI dbi = new DBI(ds);
ds.setURL("jdbc:h2:mem:" + KeyGenerator.createKey() + ";MODE=PostgreSQL");
try {
Connection keepsDBOpen = ds.getConnection();
ClosableSqlJsonDB result = new ClosableSqlJsonDB(keepsDBOpen, dbi, indexes);
result.createTables();
return result;
} catch (SQLException e) {
throw new JsonDBException(e);
}
}
use of org.h2.jdbcx.JdbcDataSource in project ma-core-public by infiniteautomation.
the class H2InMemoryDatabaseProxy method initialize.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.DatabaseProxy#initialize(java.lang.ClassLoader)
*/
@Override
public void initialize(ClassLoader classLoader) {
JdbcDataSource jds = new JdbcDataSource();
String url = "jdbc:h2:mem:" + databaseName + ";DB_CLOSE_DELAY=-1";
jds.setUrl(url);
dataSource = JdbcConnectionPool.create(jds);
transactionManager = new DataSourceTransactionManager(dataSource);
if (initWebConsole) {
String[] webArgs = new String[4];
webArgs[0] = "-webPort";
webArgs[1] = webPort.toString();
webArgs[2] = "-ifExists";
webArgs[3] = "-webAllowOthers";
try {
this.web = Server.createWebServer(webArgs);
this.web.start();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(getDataSource());
// Create the empty database
if (!tableExists(ejt, SchemaDefinition.USERS_TABLE)) {
// The users table wasn't found, so assume that this is a new instance.
// Create the tables
runScript(this.getClass().getResourceAsStream("/createTables-" + getType().name() + ".sql"), null);
for (DatabaseSchemaDefinition def : ModuleRegistry.getDefinitions(DatabaseSchemaDefinition.class)) def.newInstallationCheck(ejt);
SystemSettingsDao.instance.setValue(SystemSettingsDao.DATABASE_SCHEMA_VERSION, Integer.toString(Common.getDatabaseSchemaVersion()));
SystemSettingsDao.instance.setValue(SystemSettingsDao.BACKUP_ENABLED, "false");
SystemSettingsDao.instance.setValue(SystemSettingsDao.DATABASE_BACKUP_ENABLED, "false");
// Add the settings flag that this is a new instance. This flag is removed when an administrator
// logs in.
SystemSettingsDao.instance.setBooleanValue(SystemSettingsDao.NEW_INSTANCE, true);
Providers.get(IMangoLifecycle.class).addStartupTask(new Runnable() {
@Override
public void run() {
// New database. Create a default user.
User user = new User();
user.setId(Common.NEW_ID);
user.setName("Administrator");
user.setUsername("admin");
user.setPassword(Common.encrypt("admin"));
user.setEmail("admin@yourMangoDomain.com");
user.setPhone("");
user.setPermissions(SuperadminPermissionDefinition.GROUP_NAME);
user.setDisabled(false);
UserDao.instance.saveUser(user);
DefaultDataPointPropertiesTemplateFactory factory = new DefaultDataPointPropertiesTemplateFactory();
factory.saveDefaultTemplates();
}
});
}
// Check if we are using NoSQL
if (NoSQLProxyFactory.instance.getProxy() != null) {
noSQLProxy = NoSQLProxyFactory.instance.getProxy();
noSQLProxy.initialize();
}
initialized = true;
}
use of org.h2.jdbcx.JdbcDataSource in project logging-log4j2 by apache.
the class LoggerPrintWriterJdbcH2Test method testDataSource_setLogWriter.
@Test
@Ignore("DataSource#setLogWriter() has no effect in H2, it uses its own internal logging and an SLF4J bridge.")
public void testDataSource_setLogWriter() throws SQLException {
final JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setUrl(H2_URL);
dataSource.setUser(USER_ID);
dataSource.setPassword(PASSWORD);
dataSource.setLogWriter(createLoggerPrintWriter());
// dataSource.setLogWriter(new PrintWriter(new OutputStreamWriter(System.out)));
try (final Connection conn = dataSource.getConnection()) {
conn.prepareCall("select 1");
}
Assert.assertTrue(this.getListAppender().getMessages().size() > 0);
}
use of org.h2.jdbcx.JdbcDataSource in project nzbhydra2 by theotherp.
the class NzbHydra method repairDb.
protected static void repairDb(String databaseFilePath) throws ClassNotFoundException {
if (!databaseFilePath.contains("mv.db")) {
databaseFilePath = databaseFilePath + ".mv.db";
}
File file = new File(databaseFilePath);
if (!file.exists()) {
logger.error("File {} doesn't exist", file.getAbsolutePath());
}
databaseFilePath = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 6);
Flyway flyway = new Flyway();
flyway.setLocations("classpath:migration");
Class.forName("org.h2.Driver");
JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:file:" + databaseFilePath);
dataSource.setUser("sa");
flyway.setDataSource(dataSource);
flyway.repair();
}
Aggregations