use of io.clownfish.clownfish.jdbc.ScriptRunner in project Clownfish by rawdog71.
the class Main method bootstrap_update.
/**
* Checks the applications.properties file and runs the bootstrap routine when the bootstrap parameter is set to 1
* Fetches the database (MySQL) parameters from applications.properties and runs the sql-bootstrap.sql script
* The script creates the database user for reading/writing (user=clownfish), creates all tables and initializes some tables with data
*/
public static void bootstrap_update() {
InputStream fis = null;
try {
Properties props = new Properties();
String propsfile = "application.properties";
fis = new FileInputStream(propsfile);
if (null != fis) {
props.load(fis);
}
String dbclass = props.getProperty("app.datasource.driverClassName");
String dburl = props.getProperty("app.datasource.url");
String dbuser = props.getProperty("app.datasource.username");
String dbpassword = props.getProperty("app.datasource.password");
String path = new File(".").getCanonicalPath();
File bootstrapDirectory = new File(path);
File[] files = bootstrapDirectory.listFiles();
Arrays.sort(files);
for (int i = 0; i < files.length; i++) {
if (files[i].getName().startsWith("bootstrap_")) {
InputStream is = null;
try {
Properties boot_props = new Properties();
is = new FileInputStream(files[i]);
if (null != is) {
boot_props.load(is);
}
int bootstrap = Integer.parseInt(boot_props.getProperty("bootstrap"));
String version = boot_props.getProperty("version");
String bootstrapfile = boot_props.getProperty("bootstrapfile");
if (1 == bootstrap) {
bootstrap = 0;
AnsiConsole.systemInstall();
System.out.println(ansi().fg(GREEN));
System.out.println("BOOTSTRAPPING UPDATE VERSION " + version);
System.out.println(ansi().reset());
JDBCUtil jdbcutil = new JDBCUtil(dbclass, dburl, dbuser, dbpassword);
ScriptRunner runner = new ScriptRunner(jdbcutil.getConnection(), false, false);
runner.runScript(new BufferedReader(new FileReader(bootstrapfile)));
File f = new File(files[i].getName());
OutputStream out = new FileOutputStream(f);
boot_props.setProperty("bootstrap", String.valueOf(bootstrap));
DefaultPropertiesPersister p = new DefaultPropertiesPersister();
p.store(boot_props, out, "Bootstrap properties");
}
} catch (FileNotFoundException ex) {
LOGGER.error(ex.getMessage());
} catch (IOException | SQLException ex) {
LOGGER.error(ex.getMessage());
} finally {
try {
if (null != is) {
is.close();
}
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
}
}
}
} catch (FileNotFoundException ex) {
LOGGER.error(ex.getMessage());
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
} finally {
try {
if (null != fis) {
fis.close();
}
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
}
}
use of io.clownfish.clownfish.jdbc.ScriptRunner in project Clownfish by rawdog71.
the class Main method bootstrap.
/**
* Checks the applications.properties file and runs the bootstrap routine when the bootstrap parameter is set to 1
* Fetches the database (MySQL) parameters from applications.properties and runs the sql-bootstrap.sql script
* The script creates the database user for reading/writing (user=clownfish), creates all tables and initializes some tables with data
*/
public static void bootstrap() {
InputStream is = null;
try {
Properties props = new Properties();
String propsfile = "application.properties";
is = new FileInputStream(propsfile);
if (null != is) {
props.load(is);
}
int bootstrap = Integer.parseInt(props.getProperty("bootstrap"));
String dbclass = props.getProperty("app.datasource.driverClassName");
String dburl = props.getProperty("app.datasource.urlroot");
String dbuser = props.getProperty("app.datasource.root");
String dbpassword = props.getProperty("app.datasource.rootpw");
if (1 == bootstrap) {
AnsiConsole.systemInstall();
System.out.println(ansi().fg(GREEN));
System.out.println("BOOTSTRAPPING I");
System.out.println(ansi().reset());
JDBCUtil jdbcutil = new JDBCUtil(dbclass, dburl, dbuser, dbpassword);
ScriptRunner runner = new ScriptRunner(jdbcutil.getConnection(), true, false);
String file = "sql-bootstrap.sql";
runner.runScript(new BufferedReader(new FileReader(file)));
}
} catch (FileNotFoundException ex) {
LOGGER.error(ex.getMessage());
} catch (IOException | SQLException ex) {
LOGGER.error(ex.getMessage());
} finally {
try {
if (null != is) {
is.close();
}
} catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
}
}
Aggregations