Commit 05724ecc authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Enhances JDBC Transaction performances (Joram-358).

parent 9fba1798
......@@ -118,6 +118,13 @@ public class JDBCTransaction extends DBTransaction implements JDBCTransactionMBe
*/
public final static String JDBC_DB_UPDATE_PROP = JDBC_TRANSACTION_PREFIX + ".dbupdate";
/**
* This property allows to define the SQL statement allowing to load an entry from the table used by the module,
* by default: "SELECT content FROM <table> WHERE name=?"
* This property can be set only at first launching.
*/
public final static String JDBC_DB_LOAD_PROP = JDBC_TRANSACTION_PREFIX + ".dbload";
/**
* This property allows to define the SQL statement allowing to delete an entry in the table used by the module,
* by default: "DELETE FROM <<table>> WHERE name=?"
......@@ -221,6 +228,7 @@ public class JDBCTransaction extends DBTransaction implements JDBCTransactionMBe
}
dbinsert = AgentServer.getProperty(JDBC_DB_INSERT_PROP);
dbupdate = AgentServer.getProperty(JDBC_DB_UPDATE_PROP);
dbload = AgentServer.getProperty(JDBC_DB_LOAD_PROP);
dbdelete = AgentServer.getProperty(JDBC_DB_DELETE_PROP);
dbclose = AgentServer.getProperty(JDBC_DB_CLOSE_PROP);
......
......@@ -339,15 +339,6 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
logManager = new LogManager(dir, repository, useLockFile, syncOnWrite);
}
/**
* Tests if the Transaction component is persistent.
*
* @return true.
*/
public boolean isPersistent() {
return true;
}
/**
* Returns the path of persistence directory.
*
......
......@@ -90,10 +90,6 @@ public final class ATransaction extends AbstractTransaction implements ATransact
public ATransaction() {}
public boolean isPersistent() {
return true;
}
public final void initRepository() throws IOException {
Operation.initPool(CLEANUP_THRESHOLD_OPERATION);
......
/*
* Copyright (C) 2009 - 2012 ScalAgent Distributed Technologies
* Copyright (C) 2009 - 2020 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -30,6 +30,7 @@ import java.io.ObjectOutputStream;
import java.io.ObjectStreamConstants;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Hashtable;
import org.objectweb.util.monolog.api.BasicLevel;
......@@ -39,7 +40,6 @@ import fr.dyade.aaa.common.encoding.ByteBufferEncoder;
import fr.dyade.aaa.common.encoding.Encodable;
import fr.dyade.aaa.common.encoding.EncodableFactory;
import fr.dyade.aaa.common.encoding.EncodableFactoryRepository;
import fr.dyade.aaa.common.encoding.SerializableWrapper;
/**
* The AbstractTransaction class implements the common part of the Transaction
......@@ -69,6 +69,16 @@ public abstract class AbstractTransaction extends BaseTransaction {
public AbstractTransaction() {}
/**
* Tests if the Transaction component is persistent.
*
* @return true.
*/
@Override
public final boolean isPersistent() {
return true;
}
// State of the transaction monitor.
protected int phase;
......@@ -96,7 +106,7 @@ public abstract class AbstractTransaction extends BaseTransaction {
* Changes the transaction state.
*
* @param newPhase the new transaction state.
* @throws IOException
* @throws IOException an error occurs.
*/
protected abstract void setPhase(int newPhase) throws IOException;
......@@ -407,7 +417,7 @@ public abstract class AbstractTransaction extends BaseTransaction {
* @param log the log to use.
* @param copy the byte array can be modified, copy it.
* @param first the object is a new one.
* @throws IOException
* @throws IOException an error occurs.
*/
protected abstract void saveInLog(byte[] buf,
String dirName, String name,
......@@ -437,7 +447,10 @@ public abstract class AbstractTransaction extends BaseTransaction {
* @see fr.dyade.aaa.util.Transaction#load(java.lang.String, java.lang.String)
*/
public final Object load(String dirName, String name) throws IOException, ClassNotFoundException {
byte[] buf = loadByteArray(dirName, name);
return loadFromByteArray(loadByteArray(dirName, name));
}
protected final Object loadFromByteArray(byte[] buf) throws IOException, ClassNotFoundException {
if (buf != null) {
if (onlyUseJavaSerialization) {
return deserialize(buf, 0);
......
/*
* Copyright (C) 2006 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2006 - 2020 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -89,11 +89,13 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
protected String dbinsert = null;
protected String dbupdate = null;
protected String dbload = null;
protected String dbdelete = null;
protected String dbclose = null;
private PreparedStatement insertStmt = null;
private PreparedStatement updateStmt = null;
private PreparedStatement loadStmt = null;
private PreparedStatement deleteStmt = null;
@Override
......@@ -106,6 +108,11 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
return dbupdate;
}
@Override
public String getDBLoadStatement() {
return dbload;
}
@Override
public String getDBDeleteStatement() {
return dbdelete;
......@@ -135,6 +142,10 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
updateStmt = conn.prepareStatement("UPDATE " + dbtable + " SET content=? WHERE name=?");
else
updateStmt = conn.prepareStatement(dbupdate);
if (dbload == null)
loadStmt = conn.prepareStatement("SELECT content FROM " + dbtable + " WHERE name=?");
else
loadStmt = conn.prepareStatement(dbload);
if (dbdelete == null)
deleteStmt = conn.prepareStatement("DELETE FROM " + dbtable + " WHERE name=?");
else
......@@ -244,14 +255,7 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
return null;
}
/**
* Tests if the Transaction component is persistent.
*
* @return true.
*/
public boolean isPersistent() {
return true;
}
final String fname(String dirName, String name) {
if (dirName == null) return name;
......@@ -325,16 +329,15 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
}
try {
// Creating a statement lets us issue commands against the connection.
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT content FROM " + dbtable + " WHERE name='" + fname + "'");
loadStmt.setString(1, fname);
ResultSet rs = loadStmt.executeQuery();
if (!rs.next()) return null;
byte[] content = rs.getBytes(1);
rs.close();
s.close();
return content;
} catch (SQLException sqle) {
......@@ -547,6 +550,8 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
// TODO (AF): Should throw the exception!!
}
badinserts ++;
logmon.log(BasicLevel.INFO,
"DBTransaction, dbLogCommit.create(" + op.name + ") -> needs update");
try {
nbupdates ++;
updateStmt.setBytes(1, op.value);
......@@ -576,7 +581,7 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
if (rows != 1) {
nbinserts ++;
logmon.log(BasicLevel.INFO,
"DBTransaction, dbLogCommit.save(" + op.name + ") needs to insert -> " + rows);
"DBTransaction, dbLogCommit.save(" + op.name + ") needs insert -> " + rows);
badupdates ++;
try {
......@@ -684,6 +689,7 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
try {
insertStmt.close();
updateStmt.close();
loadStmt.close();
deleteStmt.close();
if ((dbclose != null) && (dbclose.length() > 0)) {
......
......@@ -40,6 +40,7 @@ public interface DBTransactionMBean extends TransactionMBean {
String getDBInsertStatement();
String getDBUpdateStatement();
String getDBLoadStatement();
String getDBDeleteStatement();
String getDBCloseStatement();
......
......@@ -360,15 +360,6 @@ public final class NTransaction extends AbstractTransaction implements NTransact
public NTransaction() {}
/**
* Tests if the Transaction component is persistent.
*
* @return true.
*/
public boolean isPersistent() {
return true;
}
public final void initRepository() throws IOException {
LogMemoryCapacity = getInteger("NTLogMemoryCapacity", LogMemoryCapacity).intValue();
MaxLogFileSize = getInteger("NTLogFileSize", MaxLogFileSize / Mb).intValue() * Mb;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment