The following document contains the results of PMD's CPD 4.2.2.
| File | Line |
|---|---|
| com/commsen/stopwatch/storages/MemoryHSQLInMemoryStorage.java | 42 |
| com/commsen/stopwatch/storages/MemoryHSQLStorage.java | 42 |
private static final Logger log = Logger.getLogger(MemoryHSQLStorage.class);
/**
* @see com.commsen.stopwatch.storages.AbstractDatabaseStorage#getTableName()
*/
protected String getTableName() {
return "memory_stopwatch";
}
protected String getCreateTableQuery() {
return " create table " + getTableName() + " (" + " _id INT GENERATED BY DEFAULT AS IDENTITY, " + " _group VARCHAR, " + " _label VARCHAR, " + " _start TIMESTAMP, "
+ " _end TIMESTAMP, " + " _start_mem int, " + " _end_mem int " + ")";
}
protected String getReturnColumns() {
return " count(1), " + // 3
" min (DATEDIFF('ms', _start, _end)), " + // 4
" max (DATEDIFF('ms', _start, _end)), " + // 5
" avg (DATEDIFF('ms', _start, _end)), " + // 6
" sum (DATEDIFF('ms', _start, _end)), " + // 7
" min (_end_mem - _start_mem), " + // 8
" max (_end_mem - _start_mem), " + // 9
" avg (_end_mem - _start_mem) "; // 10
}
public String getInsertQuery() {
return "insert into " + getTableName() + " (_group, _label, _start, _start_mem) values (?, ?, ?, ?)";
}
protected String getUpdateQuery() {
return "update " + getTableName() + " set _end = ?, _end_mem = ? where _id = ? and _end IS NULL";
}
/**
* @see com.commsen.stopwatch.StopwatchStorage#newRecord(java.lang.Object[])
*/
public long newRecord(Object[] parameters) throws StopwatchStorageException {
if (insertPreparedStatement == null) return -1;
try {
synchronized (insertPreparedStatement.getConnection()) {
insertPreparedStatement.setString(1, (String) parameters[0]);
insertPreparedStatement.setString(2, (String) parameters[1]);
insertPreparedStatement.setTimestamp(3, new Timestamp(((Long) parameters[2]).longValue()));
insertPreparedStatement.setLong(4, ((Long) parameters[3]).longValue());
insertPreparedStatement.executeUpdate();
ResultSet resultSet = lastIdentityStatement.executeQuery();
resultSet.next();
long result = resultSet.getLong(1);
resultSet.close();
return result;
}
} catch (SQLException e) {
throw new StopwatchStorageException("database error", e);
}
}
/**
* @see com.commsen.stopwatch.StopwatchStorage#completeRecord(long, Object[])
*/
public boolean completeRecord(long id, Object[] parameters) throws StopwatchStorageException {
if (id < 0) return false;
try {
synchronized (updatePreparedStatement.getConnection()) {
updatePreparedStatement.setTimestamp(1, new Timestamp(((Long) parameters[0]).longValue()));
updatePreparedStatement.setLong(2, ((Long) parameters[1]).longValue());
updatePreparedStatement.setLong(3, id);
updatePreparedStatement.executeUpdate();
return true;
}
} catch (SQLException e) {
throw new StopwatchStorageException("database error", e);
}
}
/**
*
* @param preparedStatement
* @return array of reports
* @throws SQLException
*/
protected Report[] prepareReports(PreparedStatement preparedStatement, Object[] params) throws SQLException {
if (preparedStatement == null) return new Report[0];
ArrayList list = new ArrayList();
synchronized (preparedStatement.getConnection()) {
if (params != null && params.length > 0) {
for (int i = 0; i < params.length; i++) {
preparedStatement.setObject(i + 1, params[i]);
}
}
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
| |