Change-Id: I9f408922ea7eb60f2919594ca84fdf8540c2611a
try {
DatabaseManager.run(new String[] {
testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password")
try {
DatabaseManager.run(new String[] {
testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password")
- }, ImportType.TRUNCATE);
+ }, ImportType.TRUNCATE, false);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
boolean test = false;
public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
boolean test = false;
if (args.length >= 1 && args[0].equals("--test")) {
test = true;
String[] ne = new String[args.length - 1];
System.arraycopy(args, 1, ne, 0, ne.length);
args = ne;
}
if (args.length >= 1 && args[0].equals("--test")) {
test = true;
String[] ne = new String[args.length - 1];
System.arraycopy(args, 1, ne, 0, ne.length);
args = ne;
}
+ if (args.length >= 1 && args[0].equals("--stdin")) {
+ stdin = true;
+ String[] ne = new String[args.length - 1];
+ System.arraycopy(args, 1, ne, 0, ne.length);
+ args = ne;
+ }
if (args.length == 0) {
Properties p = new Properties();
try (Reader reader = new InputStreamReader(new FileInputStream("config/gigi.properties"), "UTF-8")) {
if (args.length == 0) {
Properties p = new Properties();
try (Reader reader = new InputStreamReader(new FileInputStream("config/gigi.properties"), "UTF-8")) {
System.err.println("Usage: org.postgresql.Driver jdbc:postgresql://localhost/gigi user password");
return;
}
System.err.println("Usage: org.postgresql.Driver jdbc:postgresql://localhost/gigi user password");
return;
}
- run(args, test ? ImportType.TEST : ImportType.PRODUCTION);
+ run(args, test ? ImportType.TEST : ImportType.PRODUCTION, stdin);
- public static void run(String[] args, ImportType truncate) throws ClassNotFoundException, SQLException, IOException {
+ public static void run(String[] args, ImportType truncate, boolean stdin) throws ClassNotFoundException, SQLException, IOException {
Class.forName(args[0]);
final Connection conn = DriverManager.getConnection(args[1], args[2], args[3]);
try {
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
try {
Class.forName(args[0]);
final Connection conn = DriverManager.getConnection(args[1], args[2], args[3]);
try {
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
try {
- try (InputStream structure = DatabaseConnection.class.getResourceAsStream("tableStructure.sql")) {
+ try (InputStream structure = stdin ? System.in : DatabaseConnection.class.getResourceAsStream("tableStructure.sql")) {
SQLFileManager.addFile(stmt, structure, truncate);
}
File localData = new File("doc/sampleData.sql");
SQLFileManager.addFile(stmt, structure, truncate);
}
File localData = new File("doc/sampleData.sql");