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