use of org.jdbi.v3.core.Jdbi in project presto by prestodb.
the class MySqlConnectionModule method createJdbi.
public static Jdbi createJdbi(ConnectionFactory connectionFactory, MySqlFunctionNamespaceManagerConfig config) {
Jdbi jdbi = Jdbi.create(connectionFactory).installPlugin(new SqlObjectPlugin());
jdbi.getConfig(FunctionNamespacesTableCustomizerFactory.Config.class).setTableName(config.getFunctionNamespacesTableName());
jdbi.getConfig(SqlFunctionsTableCustomizerFactory.Config.class).setTableName(config.getFunctionsTableName());
jdbi.getConfig(UserDefinedTypesTableCustomizerFactory.Config.class).setTableName(config.getUserDefinedTypesTableName());
return jdbi;
}
use of org.jdbi.v3.core.Jdbi in project presto by prestodb.
the class H2ConnectionModule method setup.
@Override
protected void setup(Binder binder) {
String databaseName = buildConfigObject(H2ConnectionConfig.class).getDatabaseName();
Jdbi jdbi = createJdbi(() -> DriverManager.getConnection(getJdbcUrl(databaseName)), buildConfigObject(MySqlFunctionNamespaceManagerConfig.class));
binder.bind(Jdbi.class).toInstance(jdbi);
binder.bind(HandleLifecycleManager.class).in(SINGLETON);
binder.bind(FunctionNamespaceDao.class).toProvider(new FunctionNamespaceDaoProvider()).in(SINGLETON);
binder.bind(new TypeLiteral<Class<? extends FunctionNamespaceDao>>() {
}).toInstance(H2FunctionNamespaceDao.class);
}
use of org.jdbi.v3.core.Jdbi in project Rosetta by HubSpot.
the class AbstractJdbiTest method setup.
@Before
public void setup() {
jdbi = Jdbi.create("jdbc:h2:mem:rosetta;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=FALSE");
jdbi.installPlugin(new SqlObjectPlugin());
jdbi.registerRowMapper(new RosettaRowMapperFactory());
jdbi.useHandle(handle -> {
handle.execute("CREATE TABLE IF NOT EXISTS test_table (id INT, name VARCHAR(255) NOT NULL, PRIMARY KEY (id))");
handle.execute("TRUNCATE TABLE test_table");
});
}
use of org.jdbi.v3.core.Jdbi in project irontest by zheng-wang.
the class UpgradeActions method upgrade.
protected void upgrade(DefaultArtifactVersion systemDatabaseVersion, DefaultArtifactVersion jarFileVersion, String ironTestHome, String fullyQualifiedSystemDBURL, String user, String password) throws Exception {
Formatter logFormatter = new LogFormatter();
// set formatter for console logging
LOGGER.getParent().getHandlers()[0].setFormatter(logFormatter);
LOGGER.info("Upgrading Iron Test from v" + systemDatabaseVersion + " to v" + jarFileVersion + ".");
// set up temp upgrade directory
Path upgradeWorkspace = Files.createTempDirectory("irontest-upgrade-");
Path logFilePath = Paths.get(upgradeWorkspace.toString(), "upgrade-from-v" + systemDatabaseVersion + "-to-v" + jarFileVersion + ".log");
FileHandler logFileHandler = new FileHandler(logFilePath.toString());
logFileHandler.setFormatter(logFormatter);
LOGGER.addHandler(logFileHandler);
LOGGER.info("Created temp upgrade directory " + upgradeWorkspace.toString());
Path oldFolderInTempUpgradeDir = Paths.get(upgradeWorkspace.toString(), "old");
Path newFolderInTempUpgradeDir = Paths.get(upgradeWorkspace.toString(), "new");
Files.createDirectory(oldFolderInTempUpgradeDir);
Files.createDirectory(newFolderInTempUpgradeDir);
// system DB upgrade includes schema change and/or data migration
boolean needsSystemDBUpgrade = upgradeSystemDBInTempDirIfNeeded(systemDatabaseVersion, jarFileVersion, ironTestHome, fullyQualifiedSystemDBURL, user, password, oldFolderInTempUpgradeDir, newFolderInTempUpgradeDir);
boolean clearBrowserCacheNeeded = clearBrowserCacheIfNeeded(systemDatabaseVersion, jarFileVersion);
// ------------------------- below steps will modify files in <IronTest_Home> -------------------------
copyFilesToBeUpgraded(ironTestHome, systemDatabaseVersion, jarFileVersion);
deleteOldJarsFromIronTestHome(ironTestHome);
copyNewJarFromDistToIronTestHome(jarFileVersion, ironTestHome);
// request user to execute pre system database change (upgrade, or simply version update) general manual upgrades if needed
preSystemDBChangeGeneralManualUpgrades(systemDatabaseVersion, jarFileVersion);
if (needsSystemDBUpgrade) {
// copy files from the temp 'new' folder to <IronTest_Home>
String systemDBFileName = getSystemDBFileName(fullyQualifiedSystemDBURL);
Path ironTestHomeSystemDatabaseFolder = Paths.get(ironTestHome, "database");
Path sourceFilePath = Paths.get(newFolderInTempUpgradeDir.toString(), "database", systemDBFileName);
Path targetFilePath = Paths.get(ironTestHomeSystemDatabaseFolder.toString(), systemDBFileName);
Files.copy(sourceFilePath, targetFilePath, StandardCopyOption.REPLACE_EXISTING);
LOGGER.info("Copied " + sourceFilePath + " to " + targetFilePath + ".");
} else {
// only update version of system database under <IronTest_Home>
Jdbi jdbi = Jdbi.create(fullyQualifiedSystemDBURL, user, password);
updateVersionTableInSystemDatabase(jdbi, fullyQualifiedSystemDBURL, jarFileVersion);
}
String lineDelimiter = "------------------------------------------------------------------------";
LOGGER.info(lineDelimiter);
LOGGER.info("UPGRADE SUCCESS");
LOGGER.info(lineDelimiter);
LOGGER.info("You can start Iron Test now.");
if (clearBrowserCacheNeeded) {
LOGGER.info("If Iron Test page is already open, refresh the page (no need to restart browser).");
}
LOGGER.info(lineDelimiter);
LOGGER.info("Refer to " + logFilePath + " for upgrade logs.");
}
use of org.jdbi.v3.core.Jdbi in project irontest by zheng-wang.
the class UpgradeActions method upgradeSystemDBInTempDir.
private void upgradeSystemDBInTempDir(String ironTestHome, String fullyQualifiedSystemDBURL, String user, String password, List<ResourceFile> applicableSystemDBUpgrades, Path oldDir, Path newDir, DefaultArtifactVersion jarFileVersion) throws IOException {
Path oldDatabaseFolder = Files.createDirectory(Paths.get(oldDir.toString(), "database"));
Path newDatabaseFolder = Files.createDirectory(Paths.get(newDir.toString(), "database"));
String systemDBFileName = getSystemDBFileName(fullyQualifiedSystemDBURL);
Path sourceFile = Paths.get(ironTestHome, "database", systemDBFileName);
Path targetOldFile = Paths.get(oldDatabaseFolder.toString(), systemDBFileName);
Path targetNewFile = Paths.get(newDatabaseFolder.toString(), systemDBFileName);
Files.copy(sourceFile, targetOldFile);
LOGGER.info("Copied current system database to " + oldDatabaseFolder.toString());
Files.copy(sourceFile, targetNewFile);
LOGGER.info("Copied current system database to " + newDatabaseFolder.toString());
String newSystemDBURL = "jdbc:h2:" + targetNewFile.toString().replace(".mv.db", "") + ";IFEXISTS=TRUE";
Jdbi jdbi = Jdbi.create(newSystemDBURL, user, password);
// run SQL scripts against the system database in the 'new' folder
for (ResourceFile sqlFile : applicableSystemDBUpgrades) {
String sqlScript = sqlFile.getResourceAsText();
jdbi.withHandle(handle -> handle.createScript(sqlScript).execute());
LOGGER.info("Executed SQL script " + sqlFile.getResourcePath() + " in " + newSystemDBURL + ".");
}
updateVersionTableInSystemDatabase(jdbi, newSystemDBURL, jarFileVersion);
}
Aggregations