Update postgres and fix current problems
This commit is contained in:
parent
3cb3f3197d
commit
7ee35194be
@ -23,7 +23,7 @@ public class Database {
|
|||||||
DatabaseType.MONGODB,
|
DatabaseType.MONGODB,
|
||||||
new PostgresAuthenticationModule(
|
new PostgresAuthenticationModule(
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
3306,
|
5432,
|
||||||
"database",
|
"database",
|
||||||
"root",
|
"root",
|
||||||
"password"
|
"password"
|
||||||
|
|||||||
@ -10,7 +10,6 @@ public class PostgresDatabase extends BasicDatabase {
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private AutoReconnect autoReconnect;
|
|
||||||
|
|
||||||
public PostgresDatabase(String host, int port, String database, String user, String password) {
|
public PostgresDatabase(String host, int port, String database, String user, String password) {
|
||||||
super(host, port, database, user, password);
|
super(host, port, database, user, password);
|
||||||
@ -43,15 +42,10 @@ public class PostgresDatabase extends BasicDatabase {
|
|||||||
System.err.println("Unable to connect to Postgres database: " + e.getMessage());
|
System.err.println("Unable to connect to Postgres database: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.autoReconnect = new AutoReconnect();
|
|
||||||
this.autoReconnect.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
this.autoReconnect.interrupt();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.connection != null) {
|
if (this.connection != null) {
|
||||||
this.connection.close();
|
this.connection.close();
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public class PostgresService implements BasicService {
|
|||||||
@Override
|
@Override
|
||||||
public void table(String collection, Document document) {
|
public void table(String collection, Document document) {
|
||||||
if(!this.database().isConnected()) return;
|
if(!this.database().isConnected()) return;
|
||||||
if(!this.executeQuery("SHOW TABLES LIKE '" + collection + "'").isEmpty()) return;
|
if(!this.executeQuery("SELECT * FROM pg_catalog.pg_tables WHERE tablename = '" + collection + "';").isEmpty()) return;
|
||||||
|
|
||||||
this.execute("CREATE TABLE " + collection + " (" + this.buildString(document, " ", ", ", "") + ");");
|
this.execute("CREATE TABLE " + collection + " (" + this.buildString(document, " ", ", ", "") + ");");
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ public class PostgresService implements BasicService {
|
|||||||
public long count(String collection) {
|
public long count(String collection) {
|
||||||
if(!this.database().isConnected()) return 0;
|
if(!this.database().isConnected()) return 0;
|
||||||
List<Document> documents = this.executeQuery("SELECT COUNT(*) FROM " + collection + ";");
|
List<Document> documents = this.executeQuery("SELECT COUNT(*) FROM " + collection + ";");
|
||||||
return (long) documents.get(0).get("COUNT(*)");
|
return (long) documents.get(0).get("count");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -26,4 +26,5 @@ public interface BasicService {
|
|||||||
void deleteAll(String collection);
|
void deleteAll(String collection);
|
||||||
List<Document> top(String collection, int maxPlace, String fieldName);
|
List<Document> top(String collection, int maxPlace, String fieldName);
|
||||||
long position(String collection, Pair<String, Object> filter, String fieldName);
|
long position(String collection, Pair<String, Object> filter, String fieldName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user