diff --git a/pg-lct-msg-client/pom.xml b/pg-lct-msg-client/pom.xml
index 8d242c9..311d5ba 100644
--- a/pg-lct-msg-client/pom.xml
+++ b/pg-lct-msg-client/pom.xml
@@ -9,7 +9,7 @@
https://swingbe.de
de.swingbe
pg_lct_msg_client
- 0.0.1
+ 0.0.2
jar
@@ -84,12 +84,10 @@
-
-
- org.postgresql
- postgresql
- 42.3.5
+ de.swingbe.ifleet
+ pg-lct-msg-api
+ 0.0.3
diff --git a/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/Main.java b/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/Main.java
index 4346d04..5ca82c4 100644
--- a/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/Main.java
+++ b/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/Main.java
@@ -1,8 +1,8 @@
package de.swingbe.pg_lct_msg_client;
-import de.swingbe.pg_lct_msg_client.controller.PgConnection;
-import de.swingbe.pg_lct_msg_client.controller.PgPrepStatement;
-import de.swingbe.pg_lct_msg_client.model.LctMsg;
+import de.swingbe.ifleet.controller.PgConnection;
+import de.swingbe.ifleet.controller.PgPrepStatement;
+import de.swingbe.ifleet.model.LctMsg;
public class Main {
diff --git a/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/controller/PgConnection.java b/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/controller/PgConnection.java
deleted file mode 100644
index 610c6af..0000000
--- a/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/controller/PgConnection.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package de.swingbe.pg_lct_msg_client.controller;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class PgConnection {
- private final String host;
- private final String port;
- private final String db;
- private final String url;
- private final String usr;
- private final String key;
- private Connection connection = null;
-
- public PgConnection(String host, String port, String db, String usr, String key) {
- this.host = Objects.requireNonNull(host, "host must not be null");
- this.port = Objects.requireNonNull(port, "port must not be null");
- this.db = Objects.requireNonNull(db, "db must not be null");
- this.url = "jdbc:postgresql://" + host + ":" + port + "/" + db;
- this.usr = Objects.requireNonNull(usr, "usr must not be null");
- this.key = Objects.requireNonNull(key, "key must not be null");
- }
-
- public String getHost() {
- return host;
- }
-
- public String getPort() {
- return port;
- }
-
- public String getDb() {
- return db;
- }
-
- public String getUrl() {
- return url;
- }
-
- public String getUsr() {
- return usr;
- }
-
- public String getKey() {
- return key;
- }
-
- public Connection getConnection() {
- return connection;
- }
-
- public void setConnection() {
- System.out.println("setConnection() start...");
- if (connection == null) {
- try {
- connection = DriverManager.getConnection(url, usr, key);
- } catch (SQLException e) {
- //TODO handle logging properly
- Logger lgr = Logger.getLogger(PgConnection.class.getName());
- lgr.log(Level.SEVERE, e.getMessage(), e);
- }
- }
- System.out.println("setConnection() done.");
- }
-}
diff --git a/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/controller/PgPrepStatement.java b/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/controller/PgPrepStatement.java
deleted file mode 100644
index f09c9fc..0000000
--- a/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/controller/PgPrepStatement.java
+++ /dev/null
@@ -1,177 +0,0 @@
-package de.swingbe.pg_lct_msg_client.controller;
-
-import de.swingbe.pg_lct_msg_client.model.LctMsg;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class PgPrepStatement {
- private final PgConnection pgCon;
-
- public PgPrepStatement(PgConnection connection) {
- this.pgCon = connection;
- }
-
- public void createTable(String table) {
- System.out.println("createTable() start...");
- Objects.requireNonNull(table, "table must not be null");
-
- try (Statement st = pgCon.getConnection().createStatement()) {
-
- //autocommit should always be turned off when doing batch updates
- pgCon.getConnection().setAutoCommit(false);
-
- //sql query
- String sqlDrop = "DROP TABLE IF EXISTS " + table;
- String sqlCreate = "CREATE TABLE " + table + "(bs_id bigserial PRIMARY KEY NOT NULL,vc_trip VARCHAR(20) NOT NULL,vc_route VARCHAR(20),vc_tenant VARCHAR(20),vc_date VARCHAR(20) NOT NULL,vc_time VARCHAR(20) NOT NULL,vc_lat VARCHAR(20) NOT NULL,vc_lon VARCHAR(20) NOT NULL)";
-
- //create a new table
- st.addBatch(sqlDrop);
- st.addBatch(sqlCreate);
-
- //method returns an array of committed changes
- int[] counts = st.executeBatch();
-
- pgCon.getConnection().commit();
-
- System.out.println("Committed " + counts.length + " updates");
-
- } catch (SQLException ex) {
-
- if (pgCon != null) {
- try {
- pgCon.getConnection().rollback();
- } catch (SQLException ex1) {
- Logger lgr = Logger.getLogger(PgPrepStatement.class.getName());
- lgr.log(Level.WARNING, ex1.getMessage(), ex1);
- }
- }
-
- Logger lgr = Logger.getLogger(PgPrepStatement.class.getName());
- lgr.log(Level.SEVERE, ex.getMessage(), ex);
- }
-
- System.out.println("createTable() done.");
- }
-
- public void insert(LctMsg lctMsg, String table) {
- System.out.println("insert() start...");
- Objects.requireNonNull(lctMsg, "lctMsg must not be null");
- Objects.requireNonNull(table, "table must not be null");
-
- try (Statement st = pgCon.getConnection().createStatement()) {
-
- //autocommit should always be turned off when doing batch updates
- pgCon.getConnection().setAutoCommit(false);
-
- //sql query
- String sql = "INSERT INTO " + table + "(vc_trip,vc_route,vc_tenant,vc_date,vc_time,vc_lat,vc_lon) VALUES ('" + lctMsg.getTrip() + "','" + lctMsg.getRoute() + "','" + lctMsg.getTenant() + "','" + lctMsg.getDate() + "','" + lctMsg.getTime() + "','" + lctMsg.getLat() + "','" + lctMsg.getLon() + "')";
-
- //insert lct
- st.addBatch(sql);
-
- //method returns an array of committed changes
- int[] counts = st.executeBatch();
-
- pgCon.getConnection().commit();
-
- System.out.println("Committed " + counts.length + " updates");
-
- } catch (SQLException ex) {
-
- if (pgCon != null) {
- try {
- pgCon.getConnection().rollback();
- } catch (SQLException ex1) {
- Logger lgr = Logger.getLogger(PgPrepStatement.class.getName());
- lgr.log(Level.WARNING, ex1.getMessage(), ex1);
- }
- }
-
- Logger lgr = Logger.getLogger(PgPrepStatement.class.getName());
- lgr.log(Level.SEVERE, ex.getMessage(), ex);
- }
-
- System.out.println("insert() done.");
- }
-
- public boolean hasTable(String table, String schema){
- System.out.println("hasTable() start...");
- Objects.requireNonNull(table, "table must not be null");
- Objects.requireNonNull(schema, "schema must not be null");
-
- String query = "SELECT CASE WHEN EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" +
- schema +
- "' AND TABLE_NAME = '" +
- table +
- "') THEN 'true' ELSE 'false' END;";
-
- String result = null;
- //create prepared statement using placeholders instead of directly writing values
- try (PreparedStatement pst = pgCon.getConnection().prepareStatement(query); ResultSet rs = pst.executeQuery()) {
-
- //advance cursor to the next record
- //return false if there are no more records in the result set
- while (rs.next()) {
- result = rs.getString(1);
- }
-
- } catch (SQLException ex) {
-
- Logger lgr = Logger.getLogger(PgPrepStatement.class.getName());
- lgr.log(Level.SEVERE, ex.getMessage(), ex);
- }
-
- System.out.println("result: " + result);
- if (result != null && result.equals("true")) {
- System.out.println("result: " + result + " equals true");
- return true;
- } else {
- System.out.println("result: " + result + " equals true NOT");
- }
- System.out.println("hasTable() done.");
- return false;
- }
-
- public boolean hasLctMsg(LctMsg lctMsg, String table) {
- System.out.println("hasLct() start...");
- Objects.requireNonNull(lctMsg, "lctMsg must not be null");
- Objects.requireNonNull(table, "table must not be null");
-
- String query = "SELECT CASE WHEN EXISTS (SELECT * FROM " +
- table + " where vc_date='" +
- lctMsg.getDate() + "' AND vc_trip='" +
- lctMsg.getTrip() + "') THEN 'true' ELSE 'false' END;";
-
- String result = null;
- //create prepared statement using placeholders instead of directly writing values
- try (PreparedStatement pst = pgCon.getConnection().prepareStatement(query); ResultSet rs = pst.executeQuery()) {
-
- //advance cursor to the next record
- //return false if there are no more records in the result set
- while (rs.next()) {
- result = rs.getString(1);
- }
-
- } catch (SQLException ex) {
-
- Logger lgr = Logger.getLogger(PgPrepStatement.class.getName());
- lgr.log(Level.SEVERE, ex.getMessage(), ex);
- }
-
- System.out.println("result: " + result);
- if (result != null && result.equals("true")) {
- System.out.println("result: " + result + " equals true");
- return true;
- } else {
- System.out.println("result: " + result + " equals true NOT");
- }
- System.out.println("hasLct() done.");
- return false;
- }
-}
diff --git a/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/model/LctMsg.java b/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/model/LctMsg.java
deleted file mode 100644
index 0e74c72..0000000
--- a/pg-lct-msg-client/src/main/java/de/swingbe/pg_lct_msg_client/model/LctMsg.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package de.swingbe.pg_lct_msg_client.model;
-
-import java.util.Objects;
-
-public class LctMsg {
- private final String trip;
- private final String lat;
- private final String lon;
- private final String date;
- private final String time;
- private String tenant;
- private String route;
-
- public LctMsg(String trip, String lat, String lon, String date, String time) {
- //TODO alternative null checking could happen in setters if params are not final
- this.trip = Objects.requireNonNull(trip, "trip must not be null");
- this.lat = Objects.requireNonNull(lat, "lat must not be null");
- this.lon = Objects.requireNonNull(lon, "lon must not be null");
- this.date = Objects.requireNonNull(date, "date must not be null");
- this.time = Objects.requireNonNull(time, "time must not be null");
- }
-
- @Override
- public String toString() {
- return "LctMsg{" + "trip='" + trip + '\'' + ", lat='" + lat + '\'' + ", lon='" + lon + '\'' + ", date='" + date + '\'' + ", time='" + time + '\'' + ", tenant='" + tenant + '\'' + ", route='" + route + '\'' + '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- LctMsg lctMsg = (LctMsg) o;
- return trip.equals(lctMsg.trip) && lat.equals(lctMsg.lat) && lon.equals(lctMsg.lon) && date.equals(lctMsg.date) && time.equals(lctMsg.time) && Objects.equals(tenant, lctMsg.tenant) && Objects.equals(route, lctMsg.route);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(trip, lat, lon, date, time, tenant, route);
- }
-
- public String getTrip() {
- return trip;
- }
-
- public String getLat() {
- return lat;
- }
-
- public String getLon() {
- return lon;
- }
-
- public String getDate() {
- return date;
- }
-
- public String getTime() {
- return time;
- }
-
- public String getTenant() {
- return tenant;
- }
-
- public void setTenant(String tenant) {
- this.tenant = tenant;
- }
-
- public String getRoute() {
- return route;
- }
-
- public void setRoute(String route) {
- this.route = route;
- }
-}