diff --git a/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/ConditionalTagHandler.java b/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/ConditionalTagHandler.java index 8f02af7f..23cf1612 100644 --- a/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/ConditionalTagHandler.java +++ b/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/ConditionalTagHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -138,7 +138,7 @@ protected long compare(SqlTagContext ctx, SqlTag tag, Object parameterObject) { * @return the long */ protected long compareValues(Class type, Object value1, Object value2) { - long result = NOT_COMPARABLE; + long result; if (value1 == null || value2 == null) { result = value1 == value2 ? 0 : NOT_COMPARABLE; @@ -224,10 +224,8 @@ protected String getResolvedProperty(SqlTagContext ctx, SqlTag tag) { } } - if (prop.indexOf(START_INDEX) > -1) { - if (itCtx != null) { - prop = itCtx.addIndexToTagProperty(prop); - } + if (prop.indexOf(START_INDEX) > -1 && itCtx != null) { + prop = itCtx.addIndexToTagProperty(prop); } } diff --git a/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/DynamicTagHandler.java b/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/DynamicTagHandler.java index e6bd5fd3..95b548a7 100644 --- a/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/DynamicTagHandler.java +++ b/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/DynamicTagHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ public class DynamicTagHandler extends BaseTagHandler { @Override public int doStartFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject) { ctx.pushRemoveFirstPrependMarker(tag); - return BaseTagHandler.INCLUDE_BODY; + return SqlTagHandler.INCLUDE_BODY; } } diff --git a/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IsEmptyTagHandler.java b/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IsEmptyTagHandler.java index da586104..1cda978e 100644 --- a/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IsEmptyTagHandler.java +++ b/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IsEmptyTagHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ public boolean isCondition(SqlTagContext ctx, SqlTag tag, Object parameterObject value = parameterObject; } if (value instanceof Collection) { - return value == null || ((Collection) value).size() < 1; + return ((Collection) value).isEmpty(); } else if (value != null && value.getClass().isArray()) { return Array.getLength(value) == 0; } else { diff --git a/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IterateTagHandler.java b/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IterateTagHandler.java index d6c13415..8728832a 100644 --- a/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IterateTagHandler.java +++ b/src/main/java/com/ibatis/sqlmap/engine/mapping/sql/dynamic/elements/IterateTagHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ public int doStartFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject ctx.reEnableRemoveFirstPrependMarker(); } - if (iterate != null && iterate.hasNext()) { + if (iterate.hasNext()) { return INCLUDE_BODY; } else { return SKIP_BODY; @@ -80,7 +80,7 @@ public int doEndFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject, iterate.next(); } - if (bodyContent.toString().trim().length() > 0) { + if (!bodyContent.toString().trim().isEmpty()) { // the sub element produced a result. If it is the first one // to produce a result, then we need to add the open // text. If it is not the first to produce a result then @@ -102,10 +102,8 @@ public int doEndFragment(SqlTagContext ctx, SqlTag tag, Object parameterObject, iterate.setSomeSubElementsHaveContent(true); } - if (iterate.isLast() && iterate.someSubElementsHaveContent()) { - if (tag.isCloseAvailable()) { - bodyContent.append(tag.getCloseAttr()); - } + if (iterate.isLast() && iterate.someSubElementsHaveContent() && tag.isCloseAvailable()) { + bodyContent.append(tag.getCloseAttr()); } iterate.setAllowNext(true); diff --git a/src/main/java/com/ibatis/sqlmap/engine/transaction/TransactionManager.java b/src/main/java/com/ibatis/sqlmap/engine/transaction/TransactionManager.java index 4ba493b9..20490459 100644 --- a/src/main/java/com/ibatis/sqlmap/engine/transaction/TransactionManager.java +++ b/src/main/java/com/ibatis/sqlmap/engine/transaction/TransactionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,6 @@ public void begin(SessionScope sessionScope) throws SQLException, TransactionExc * the transaction exception */ public void begin(SessionScope sessionScope, int transactionIsolation) throws SQLException, TransactionException { - Transaction trans = sessionScope.getTransaction(); TransactionState state = sessionScope.getTransactionState(); if (state == TransactionState.STATE_STARTED) { throw new TransactionException( @@ -77,7 +76,7 @@ public void begin(SessionScope sessionScope, int transactionIsolation) throws SQ + "The calling .setUserConnection (null) will clear the user provided transaction."); } - trans = config.newTransaction(transactionIsolation); + Transaction trans = config.newTransaction(transactionIsolation); sessionScope.setCommitRequired(false); sessionScope.setTransaction(trans); @@ -138,11 +137,10 @@ public void end(SessionScope sessionScope) throws SQLException, TransactionExcep try { if (trans != null) { try { - if (state != TransactionState.STATE_COMMITTED) { - if (sessionScope.isCommitRequired() || config.isForceCommit()) { - trans.rollback(); - sessionScope.setCommitRequired(false); - } + if (state != TransactionState.STATE_COMMITTED + && (sessionScope.isCommitRequired() || config.isForceCommit())) { + trans.rollback(); + sessionScope.setCommitRequired(false); } } finally { sessionScope.closePreparedStatements(); diff --git a/src/main/java/com/ibatis/sqlmap/engine/transaction/jta/JtaTransaction.java b/src/main/java/com/ibatis/sqlmap/engine/transaction/jta/JtaTransaction.java index 3ebda4a0..9f3a5d6f 100644 --- a/src/main/java/com/ibatis/sqlmap/engine/transaction/jta/JtaTransaction.java +++ b/src/main/java/com/ibatis/sqlmap/engine/transaction/jta/JtaTransaction.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2024 the original author or authors. + * Copyright 2004-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -137,19 +137,17 @@ public void commit() throws SQLException, TransactionException { } public void rollback() throws SQLException, TransactionException { - if (connection != null) { - if (!commmitted) { - try { - if (userTransaction != null) { - if (newTransaction) { - userTransaction.rollback(); - } else { - userTransaction.setRollbackOnly(); - } + 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); } + } catch (Exception e) { + throw new TransactionException("JtaTransaction could not rollback. Cause: ", e); } } }