CPD Results
The following document contains the results of PMD's CPD 7.14.0.
Duplications
| File |
Line |
| com\ibatis\sqlmap\engine\transaction\jta\JakartaTransaction.java |
72 |
| com\ibatis\sqlmap\engine\transaction\jta\JavaxTransaction.java |
71 |
public JakartaTransaction(UserTransaction utx, DataSource ds, int isolationLevel) throws TransactionException {
// Check parameters
userTransaction = utx;
dataSource = ds;
if (userTransaction == null) {
throw new TransactionException("JtaTransaction initialization failed. UserTransaction was null.");
}
if (dataSource == null) {
throw new TransactionException("JtaTransaction initialization failed. DataSource was null.");
}
this.isolationLevel.setIsolationLevel(isolationLevel);
}
/**
* Inits the.
*
* @throws TransactionException
* the transaction exception
* @throws SQLException
* the SQL exception
*/
private void init() throws TransactionException, SQLException {
// Start JTA Transaction
try {
newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION;
if (newTransaction) {
userTransaction.begin();
}
} catch (Exception e) {
throw new TransactionException("JtaTransaction could not start transaction. Cause: ", e);
}
// Open JDBC Connection
connection = dataSource.getConnection();
if (connection == null) {
throw new TransactionException(
"JtaTransaction could not start transaction. Cause: The DataSource returned a null connection.");
}
// Isolation Level
isolationLevel.applyIsolationLevel(connection);
// AutoCommit
if (connection.getAutoCommit()) {
connection.setAutoCommit(false);
}
// Debug
if (connectionLog.isDebugEnabled()) {
connection = ConnectionLogProxy.newInstance(connection);
}
}
@Override
public void commit() throws SQLException, TransactionException {
if (connection != null) {
if (commmitted) {
throw new TransactionException(
"JtaTransaction could not commit because this transaction has already been committed.");
}
try {
if (newTransaction) {
userTransaction.commit();
}
} catch (Exception e) {
throw new TransactionException("JtaTransaction could not commit. Cause: ", e);
}
commmitted = true;
}
}
@Override
public void rollback() throws SQLException, TransactionException {
if (connection != null && !commmitted) {
try {
if (userTransaction != null) {
if (newTransaction) {
userTransaction.rollback();
} else {
userTransaction.setRollbackOnly();
}
}
} catch (Exception e) {
throw new TransactionException("JtaTransaction could not rollback. Cause: ", e);
}
}
}
@Override
public void close() throws SQLException, TransactionException {
if (connection != null) {
try {
isolationLevel.restoreIsolationLevel(connection);
} finally {
connection.close();
connection = null;
}
}
}
@Override
public Connection getConnection() throws SQLException, TransactionException {
if (connection == null) {
init();
}
return connection;
}
} |
| File |
Line |
| com\ibatis\sqlmap\engine\cache\fifo\FifoCacheController.java |
45 |
| com\ibatis\sqlmap\engine\cache\lru\LruCacheController.java |
45 |
public FifoCacheController() {
this.cacheSize = 100;
this.cache = Collections.synchronizedMap(new HashMap<>());
this.keyList = Collections.synchronizedList(new LinkedList());
}
/**
* Gets the cache size.
*
* @return the cache size
*/
public int getCacheSize() {
return cacheSize;
}
/**
* Sets the cache size.
*
* @param cacheSize
* the new cache size
*/
public void setCacheSize(int cacheSize) {
this.cacheSize = cacheSize;
}
/**
* Configures the cache
*
* @param props
* Optionally can contain properties [reference-type=WEAK|SOFT|STRONG]
*/
@Override
public void setProperties(Properties props) {
String size = props.getProperty("cache-size");
if (size == null) {
size = props.getProperty("size");
}
if (size != null) {
cacheSize = Integer.parseInt(size);
}
}
/**
* Add an object to the cache
*
* @param cacheModel
* The cacheModel
* @param key
* The key of the object to be cached
* @param value
* The object to be cached
*/
@Override
public void putObject(CacheModel cacheModel, Object key, Object value) {
cache.put(key, value);
keyList.add(key);
if (keyList.size() > cacheSize) {
try {
Object oldestKey = keyList.remove(0);
cache.remove(oldestKey);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}
/**
* Get an object out of the cache.
*
* @param cacheModel
* The cache model
* @param key
* The key of the object to be returned
*
* @return The cached object (or null)
*/
@Override
public Object getObject(CacheModel cacheModel, Object key) { |
| File |
Line |
| com\ibatis\common\xml\NodeletParser.java |
209 |
| com\ibatis\common\xml\NodeletParser.java |
263 |
private Document createDocument(Reader reader)
throws ParserConfigurationException, FactoryConfigurationError, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
factory.setValidating(validation);
factory.setNamespaceAware(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(false);
factory.setCoalescing(false);
factory.setExpandEntityReferences(false);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(entityResolver);
builder.setErrorHandler(new ErrorHandler() {
@Override
public void error(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void warning(SAXParseException exception) throws SAXException {
}
});
return builder.parse(new InputSource(reader)); |
| File |
Line |
| com\ibatis\common\jdbc\logging\PreparedStatementLogProxy.java |
80 |
| com\ibatis\common\jdbc\logging\StatementLogProxy.java |
63 |
}
return method.invoke(statement, params);
}
if ("getResultSet".equals(method.getName())) {
ResultSet rs = (ResultSet) method.invoke(statement, params);
if (rs != null) {
return ResultSetLogProxy.newInstance(rs);
}
return null;
}
if ("equals".equals(method.getName())) {
Object ps = params[0];
if (ps instanceof Proxy) {
return Boolean.valueOf(proxy == ps);
}
return Boolean.valueOf(false);
}
if ("hashCode".equals(method.getName())) {
return Integer.valueOf(proxy.hashCode());
}
return method.invoke(statement, params);
} catch (Throwable t) {
throw ClassInfo.unwrapThrowable(t);
}
}
/**
* Creates a logging version of a PreparedStatement.
*
* @param stmt
* - the statement
* @param sql
* - the sql statement
*
* @return - the proxy
*/
public static PreparedStatement newInstance(PreparedStatement stmt, String sql) { |
| File |
Line |
| com\ibatis\sqlmap\engine\type\ObjectTypeHandler.java |
30 |
| com\ibatis\sqlmap\engine\type\UnknownTypeHandler.java |
48 |
ps.setObject(i, parameter);
}
@Override
public Object getResult(ResultSet rs, String columnName) throws SQLException {
Object object = rs.getObject(columnName);
if (rs.wasNull()) {
return null;
}
return object;
}
@Override
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
Object object = rs.getObject(columnIndex);
if (rs.wasNull()) {
return null;
}
return object;
}
@Override
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
Object object = cs.getObject(columnIndex);
if (cs.wasNull()) {
return null;
}
return object;
}
@Override
public Object valueOf(String s) {
return s;
} |
| File |
Line |
| com\ibatis\sqlmap\engine\builder\xml\SqlMapParser.java |
314 |
| com\ibatis\sqlmap\engine\builder\xml\SqlMapParser.java |
367 |
+ "' (must be a TypeHandler or TypeHandlerCallback implementation).");
Object typeHandlerImpl = null;
try {
if (callback != null && !callback.isEmpty()) {
callback = state.getConfig().getTypeHandlerFactory().resolveAlias(callback);
typeHandlerImpl = Resources.instantiate(callback);
}
} catch (Exception e) {
throw new RuntimeException("Error occurred during custom type handler configuration. Cause: " + e, e);
}
Integer columnIndex = null;
if (columnIndexProp != null) {
try {
columnIndex = Integer.valueOf(columnIndexProp);
} catch (Exception e) {
throw new RuntimeException("Error parsing column index. Cause: " + e, e);
}
}
state.getResultConfig().addResultMapping(propertyName, columnName, columnIndex, javaClass, jdbcType, nullValue, |
| File |
Line |
| com\ibatis\sqlmap\engine\mapping\statement\MappedStatement.java |
123 |
| com\ibatis\sqlmap\engine\mapping\statement\MappedStatement.java |
293 |
statementScope.getSession().setCommitRequired(true);
try {
parameterObject = validateParameter(parameterObject);
Sql sql = getSql();
errorContext.setMoreInfo("Check the parameter map.");
ParameterMap parameterMap = sql.getParameterMap(statementScope, parameterObject);
errorContext.setMoreInfo("Check the result map.");
ResultMap resultMap = sql.getResultMap(statementScope, parameterObject);
statementScope.setResultMap(resultMap);
statementScope.setParameterMap(parameterMap);
errorContext.setMoreInfo("Check the parameter map.");
Object[] parameters = parameterMap.getParameterObjectValues(statementScope, parameterObject);
errorContext.setMoreInfo("Check the SQL statement.");
String sqlString = sql.getSql(statementScope, parameterObject);
errorContext.setActivity("executing mapped statement");
errorContext.setMoreInfo("Check the statement or the result map."); |
| File |
Line |
| com\ibatis\common\beans\ComplexBeanProbe.java |
85 |
| com\ibatis\common\beans\ComplexBeanProbe.java |
122 |
type = getClassPropertyTypeForSetter((Class) object, name);
} else if (object instanceof Map) {
Map map = (Map) object;
Object value = map.get(name);
if (value == null) {
type = Object.class;
} else {
type = value.getClass();
}
} else if (name.indexOf('.') > -1) {
StringTokenizer parser = new StringTokenizer(name, ".");
while (parser.hasMoreTokens()) {
name = parser.nextToken();
type = ClassInfo.getInstance(type).getSetterType(name); |
| File |
Line |
| com\ibatis\sqlmap\engine\transaction\jta\JakartaTransactionConfig.java |
41 |
| com\ibatis\sqlmap\engine\transaction\jta\JavaxTransactionConfig.java |
40 |
return new JakartaTransaction(userTransaction, dataSource, transactionIsolation);
}
/**
* Gets the user transaction.
*
* @return the user transaction
*/
public UserTransaction getUserTransaction() {
return userTransaction;
}
/**
* Sets the user transaction.
*
* @param userTransaction
* the new user transaction
*/
public void setUserTransaction(UserTransaction userTransaction) {
this.userTransaction = userTransaction;
}
@Override
public void setProperties(Properties props) throws SQLException, TransactionException {
String utxName = null;
try {
utxName = (String) props.get("UserTransaction");
InitialContext initCtx = new InitialContext();
userTransaction = (UserTransaction) initCtx.lookup(utxName);
} catch (NamingException e) {
throw new SqlMapException(
"Error initializing JtaTransactionConfig while looking up UserTransaction (" + utxName + "). Cause: " + e);
}
}
} |