2022-05-10 15:34:16 +02:00
|
|
|
package de.swingbe.pg_lct_msg_client;
|
|
|
|
|
2022-05-11 21:30:27 +02:00
|
|
|
import de.swingbe.ifleet.controller.PgConnection;
|
|
|
|
import de.swingbe.ifleet.controller.PgPrepStatement;
|
|
|
|
import de.swingbe.ifleet.model.LctMsg;
|
2022-05-11 15:34:43 +02:00
|
|
|
|
2022-05-10 15:34:16 +02:00
|
|
|
public class Main {
|
|
|
|
|
2022-05-11 15:34:43 +02:00
|
|
|
private static final String TABLE = "lct_msg";
|
2022-05-11 20:36:50 +02:00
|
|
|
private static final String SCHEMA = "public";
|
2022-05-11 15:34:43 +02:00
|
|
|
|
2022-05-10 15:34:16 +02:00
|
|
|
public static void main(String[] args) {
|
2022-05-11 15:34:43 +02:00
|
|
|
System.out.println("main() start...");
|
|
|
|
|
|
|
|
LctMsg lctMsgEdz = new LctMsg("4457006", "534651826", "74635669", "2022-05-10", "13:34:05,824");
|
|
|
|
lctMsgEdz.setTenant("EDZ/247");
|
|
|
|
System.out.println("" + lctMsgEdz);
|
|
|
|
LctMsg lctMsgAlb = new LctMsg("1152427", "527980303", "89021481", "2022-05-10", "13:33:54,789");
|
|
|
|
lctMsgAlb.setTenant("ALB/8241");
|
|
|
|
System.out.println("" + lctMsgAlb);
|
|
|
|
LctMsg lctMsgGer = new LctMsg("9984", "534019410", "83551613", "2022-05-10", "13:33:54,789");
|
|
|
|
lctMsgGer.setTenant("GER/201");
|
|
|
|
System.out.println("" + lctMsgGer);
|
|
|
|
LctMsg lctMsgWol = new LctMsg("0", "530382858", "89636652", "2022-05-09", "10:09:28,654");
|
|
|
|
lctMsgWol.setTenant("WOL/238");
|
|
|
|
System.out.println("" + lctMsgWol);
|
|
|
|
|
|
|
|
//connection URL for the postgres database
|
|
|
|
String host = "host";
|
|
|
|
String port = "port";
|
|
|
|
String db = "db";
|
|
|
|
String usr = "usr";
|
|
|
|
String key = "key";
|
|
|
|
|
|
|
|
PgConnection pgCon = new PgConnection(host, port, db, usr, key);
|
|
|
|
|
|
|
|
if (pgCon.getConnection() == null) {
|
|
|
|
pgCon.setConnection();
|
|
|
|
System.out.println("main() pgCon set");
|
|
|
|
}
|
|
|
|
|
|
|
|
PgPrepStatement pgPrepStatement = new PgPrepStatement(pgCon);
|
|
|
|
|
2022-05-11 20:36:50 +02:00
|
|
|
boolean hasTable = false;
|
|
|
|
while (!hasTable) {
|
|
|
|
hasTable = pgPrepStatement.hasTable(TABLE, SCHEMA);
|
|
|
|
if (hasTable) {
|
|
|
|
System.out.print("main() has table: ");
|
|
|
|
System.out.println("" + TABLE);
|
|
|
|
} else {
|
|
|
|
System.out.print("main() has NOT table: ");
|
|
|
|
System.out.println("" + TABLE);
|
|
|
|
pgPrepStatement.createTable(TABLE);
|
|
|
|
}
|
|
|
|
}
|
2022-05-11 15:34:43 +02:00
|
|
|
|
|
|
|
boolean hasEdz = false;
|
|
|
|
while (!hasEdz) {
|
|
|
|
hasEdz = pgPrepStatement.hasLctMsg(lctMsgEdz, TABLE);
|
|
|
|
if (hasEdz) {
|
|
|
|
System.out.print("main() has msg: ");
|
|
|
|
System.out.println("" + lctMsgEdz);
|
|
|
|
} else {
|
|
|
|
System.out.print("main() has NOT msg: ");
|
|
|
|
System.out.println("" + lctMsgEdz);
|
|
|
|
pgPrepStatement.insert(lctMsgEdz, TABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("main() done.");
|
2022-05-10 15:34:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|