CPD Results

The following document contains the results of PMD's CPD

Duplications

FileLine
com/commsen/stopwatch/storages/LoadHSQLInMemoryStorage.java51
com/commsen/stopwatch/storages/LoadHSQLStorage.java51
	protected String getCreateTableQuery() { 
		return 
		" create table " + getTableName() + " (" +
		"   _id INT GENERATED BY DEFAULT AS IDENTITY," +
		"   _group VARCHAR," +
		"   _label VARCHAR," +
		"   _start TIMESTAMP," +
		"   _end TIMESTAMP," +
		"   _load INT" +
		")";
	}

	protected String getReturnColumns() { 
		return  
		"  count(1), " +
		"   min (DATEDIFF('ms', _start, _end)) as minTime," +
		"   max (DATEDIFF('ms', _start, _end)) as maxTime," +
		"   avg (DATEDIFF('ms', _start, _end)) as avgTime," +
		"   sum (DATEDIFF('ms', _start, _end)) as totalTime, " +
		"   min(_load) as minLoad,  " +
		"   max(_load) as maxLoad,  " +
		"	avg(_load) as avgLoad ";
	}	
	
	public String getInsertQuery() { 
		return "insert into " + getTableName() + " (_group, _label, _start, _load) values (?, ?, ?, ?)";
	}
	
	
	private Map byLabelCount = new HashMap();
	private Map byIdCount = new HashMap();
	
	
	/**
	 * @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()) {
				// increase load counter
				String group = (String)parameters[0];
				String name = (String)parameters[1];
				String key = group + "|" + name;
				int count;
				if (byLabelCount.containsKey(key)) count = ((Integer)byLabelCount.get(key)).intValue() + 1;
				else count = 1;
				byLabelCount.put(key, new Integer(count));
				
				insertPreparedStatement.setString(1, group);
				insertPreparedStatement.setString(2, name);
				insertPreparedStatement.setTimestamp(3, new Timestamp(((Long)parameters[2]).longValue()));
				insertPreparedStatement.setInt(4, count);
				insertPreparedStatement.executeUpdate();
				ResultSet resultSet = lastIdentityStatement.executeQuery();
				resultSet.next();
				long result = resultSet.getLong(1);
				resultSet.close();
				byIdCount.put(new Long(result), key);
				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, id);
				updatePreparedStatement.executeUpdate();
				
				// decrease load counter
				Long longId = new Long(id);
				if (byIdCount.containsKey(longId)) {
					String key = (String)byIdCount.get(longId);
					if (byLabelCount.containsKey(key)) {
						int count = ((Integer)byLabelCount.get(key)).intValue() - 1;
						byLabelCount.put(key, new Integer(count));
					}
				}
				
				return true;
			}
		} catch (SQLException e) {
	        throw new StopwatchStorageException("database error", e);
		}

	}	
	

	/**
	 * 
	 * @see com.commsen.stopwatch.StopwatchStorage#removeRecord(long)
	 */
	public boolean removeRecord(long id) throws StopwatchStorageException {
		if (id < 0) return false;
		try {
			synchronized (deletePreparedStatement.getConnection()) {
				deletePreparedStatement.setLong(1, id);
				deletePreparedStatement.executeUpdate();
				
				// decrease load counter
				Long longId = new Long(id);
				if (byIdCount.containsKey(longId)) {
					String key = (String)byIdCount.get(longId);
					if (byLabelCount.containsKey(key)) {
						int count = ((Integer)byLabelCount.get(key)).intValue() - 1;
						byLabelCount.put(key, new Integer(count));
					}
				}
				
				return true;
			}
		} catch (SQLException e) {
	        throw new StopwatchStorageException("database error", e);
		}
	}
	
	
	/**
	 * 
	 * @see com.commsen.stopwatch.storages.AbstractDatabaseStorage#prepareReports(java.sql.PreparedStatement, java.lang.Object[])
	 */
	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()) {
				list.add(new LoadStopwatchReport( 
					resultSet.getString(1),
					resultSet.getString(2),
					resultSet.getLong(3),
					resultSet.getLong(4),
					resultSet.getLong(5),
					resultSet.getLong(6),
					resultSet.getLong(7),
					resultSet.getLong(8),
					resultSet.getLong(9),
					resultSet.getLong(10)
					)
				);
			}
		}
		return (Report[])list.toArray(new Report[list.size()]);
	}
	
	protected Logger getLogger () {
		return log;
	}		
	
}

FileLine
com/commsen/stopwatch/storages/MemoryHSQLInMemoryStorage.java42
com/commsen/stopwatch/storages/MemoryHSQLStorage.java42
	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()) {
				list.add(new MemoryStopwatchReport( 
						resultSet.getString(1),
						resultSet.getString(2),
						resultSet.getLong(3),
						resultSet.getLong(4),
						resultSet.getLong(5),
						resultSet.getLong(6),
						resultSet.getLong(7),
						resultSet.getLong(8),
						resultSet.getLong(9),
						resultSet.getLong(10)
						
						));
			}
		}
		return (Report[])list.toArray(new Report[list.size()]);
	}
	
	protected Logger getLogger () {
		return log;
	}	
}

FileLine
com/commsen/stopwatch/storages/MemoryHSQLInMemoryStorage.java119
com/commsen/stopwatch/storages/LoadHSQLInMemoryStorage.java168
				return true;
			}
		} catch (SQLException e) {
	        throw new StopwatchStorageException("database error", e);
		}
	}
	
	
	/**
	 * 
	 * @see com.commsen.stopwatch.storages.AbstractDatabaseStorage#prepareReports(java.sql.PreparedStatement, java.lang.Object[])
	 */
	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()) {
				list.add(new LoadStopwatchReport( 

FileLine
com/commsen/stopwatch/storages/MemoryHSQLInMemoryStorage.java146
com/commsen/stopwatch/storages/LoadHSQLStorage.java193
				list.add(new LoadStopwatchReport( 
					resultSet.getString(1),
					resultSet.getString(2),
					resultSet.getLong(3),
					resultSet.getLong(4),
					resultSet.getLong(5),
					resultSet.getLong(6),
					resultSet.getLong(7),
					resultSet.getLong(8),
					resultSet.getLong(9),
					resultSet.getLong(10)
					)
				);
			}
		}
		return (Report[])list.toArray(new Report[list.size()]);
	}
	
	protected Logger getLogger () {
		return log;
	}		
	
}