document-store-lib-postgresql/src/main/java/org/gcube/documentstore/persistence/PersistencePostgreSQL.java

63 lines
1.4 KiB
Java
Raw Normal View History

2021-03-10 16:28:08 +01:00
/**
*
*/
package org.gcube.documentstore.persistence;
2021-03-10 17:59:25 +01:00
import java.sql.Statement;
2021-03-18 15:24:36 +01:00
import org.gcube.accounting.utility.postgresql.PostgreSQLQuery;
2021-03-10 16:28:08 +01:00
import org.gcube.documentstore.records.Record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class PersistencePostgreSQL extends PersistenceBackend {
2021-03-18 11:24:46 +01:00
protected static final Logger logger = LoggerFactory.getLogger(PersistencePostgreSQL.class);
2021-03-10 16:28:08 +01:00
2021-03-18 11:24:46 +01:00
protected StatementMap statementMap;
2021-03-10 17:59:25 +01:00
2021-03-10 16:28:08 +01:00
@Override
2021-03-26 10:26:42 +01:00
public void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception {
this.statementMap = new StatementMap(configuration);
2021-03-10 16:28:08 +01:00
}
@Override
protected void openConnection() throws Exception {
2021-03-18 11:24:46 +01:00
2021-03-12 11:22:32 +01:00
}
2021-03-18 11:24:46 +01:00
2021-03-10 16:28:08 +01:00
@Override
2021-03-10 17:59:25 +01:00
protected void reallyAccount(Record record) throws Exception {
2021-03-18 11:24:46 +01:00
Statement statement = statementMap.getStatement(record);
2021-03-18 15:24:36 +01:00
PostgreSQLQuery postgreSQLQuery = new PostgreSQLQuery();
String sqlCommand = postgreSQLQuery.getSQLInsertCommand(record);
2021-03-10 17:59:25 +01:00
statement.executeUpdate(sqlCommand);
2021-03-10 16:28:08 +01:00
}
2021-03-12 11:22:32 +01:00
public void insert(Record record) throws Exception {
reallyAccount(record);
}
2021-03-10 16:28:08 +01:00
@Override
2021-03-18 11:24:46 +01:00
protected void clean() throws Exception {
statementMap.close();
}
2021-03-10 16:28:08 +01:00
@Override
protected void closeConnection() throws Exception {
2021-03-18 11:24:46 +01:00
statementMap.close();
2021-03-10 16:28:08 +01:00
}
2021-03-12 11:22:32 +01:00
public void commitAndClose() throws Exception {
2021-03-18 11:24:46 +01:00
statementMap.close();
2021-03-12 11:22:32 +01:00
}
2021-03-10 16:28:08 +01:00
@Override
public boolean isConnectionActive() throws Exception {
2021-03-18 11:24:46 +01:00
return true;
2021-03-10 16:28:08 +01:00
};
2021-03-15 11:56:13 +01:00
}