From ba8569bbc782fc094041343adf73001f18f3e6f3 Mon Sep 17 00:00:00 2001 From: Eddie Carpenter Date: Wed, 12 Jun 2024 13:30:05 +1200 Subject: [PATCH] Fixed warnings --- .../java/io/jpalite/EntityMetaDataManager.java | 4 ---- .../io/jpalite/impl/EntityLifecycleImpl.java | 6 +++--- .../io/jpalite/impl/db/DatabasePoolImpl.java | 2 +- .../impl/db/PreparedStatementWrapper.java | 16 ---------------- .../jpalite/impl/queries/JPALiteQueryImpl.java | 2 +- .../io/jpalite/impl/queries/NamedQueryImpl.java | 3 +-- .../impl/serializers/JPAEntityMarshaller.java | 4 ---- .../src/main/java/io/jpalite/JPALiteMojo.java | 2 +- .../TransactionScopedEntityManagerImpl.java | 1 + .../main/java/io/jpalite/repository/Filter.java | 16 ++++++++-------- .../repository/JPALiteRepositoryProcessor.java | 16 ++++++++++++---- pom.xml | 7 ++++--- 12 files changed, 32 insertions(+), 47 deletions(-) diff --git a/jpalite-core/src/main/java/io/jpalite/EntityMetaDataManager.java b/jpalite-core/src/main/java/io/jpalite/EntityMetaDataManager.java index 5283a38..3edfcba 100644 --- a/jpalite-core/src/main/java/io/jpalite/EntityMetaDataManager.java +++ b/jpalite-core/src/main/java/io/jpalite/EntityMetaDataManager.java @@ -133,10 +133,6 @@ public static EntityMetaData getMetaData(Class entityName) public static void register(@Nonnull EntityMetaData metaData) { - if (metaData == null) { - throw new IllegalArgumentException("EntityMetaData cannot be null"); - }//if - if (REGISTRY_ENTITY_NAMES.containsKey(metaData.getName())) { throw new IllegalArgumentException("EntityMetaData already registered for " + metaData.getName()); }//if diff --git a/jpalite-core/src/main/java/io/jpalite/impl/EntityLifecycleImpl.java b/jpalite-core/src/main/java/io/jpalite/impl/EntityLifecycleImpl.java index 2e8a0e4..e0c5fe3 100644 --- a/jpalite-core/src/main/java/io/jpalite/impl/EntityLifecycleImpl.java +++ b/jpalite-core/src/main/java/io/jpalite/impl/EntityLifecycleImpl.java @@ -29,11 +29,11 @@ @SuppressWarnings("java:S3011")//Changing accessibility mode is needed public class EntityLifecycleImpl implements EntityLifecycle { - private List listeners; + private final List listeners; - private class Methods + private static class Methods { - private Class listenerClass; + private final Class listenerClass; private Method postLoad; private Method prePersist; private Method postPersist; diff --git a/jpalite-core/src/main/java/io/jpalite/impl/db/DatabasePoolImpl.java b/jpalite-core/src/main/java/io/jpalite/impl/db/DatabasePoolImpl.java index 565f369..f983629 100644 --- a/jpalite-core/src/main/java/io/jpalite/impl/db/DatabasePoolImpl.java +++ b/jpalite-core/src/main/java/io/jpalite/impl/db/DatabasePoolImpl.java @@ -100,7 +100,7 @@ public PersistenceContext getPersistenceContext(@Nonnull JPALitePersistenceUnit }//if Map connectionList = connections.get(); - PersistenceContext manager = null; + PersistenceContext manager; if (connectionList == null || connectionList.get(persistenceUnit.getPersistenceUnitName()) == null) { LOG.trace("Creating a new Persistence Context for thread {}", Thread.currentThread().getName()); manager = new PersistenceContextImpl(this, persistenceUnit); diff --git a/jpalite-core/src/main/java/io/jpalite/impl/db/PreparedStatementWrapper.java b/jpalite-core/src/main/java/io/jpalite/impl/db/PreparedStatementWrapper.java index f9f7365..8ca00ac 100644 --- a/jpalite-core/src/main/java/io/jpalite/impl/db/PreparedStatementWrapper.java +++ b/jpalite-core/src/main/java/io/jpalite/impl/db/PreparedStatementWrapper.java @@ -87,22 +87,6 @@ protected void logError(String pmethod, String queryStr, Throwable exception) protected void logExecution(String method, String queryStr, long executeTime, boolean update) { if (connection.isEnableLogging() || connection.getAuditWriter() != null) { - StringBuilder paramsStr = new StringBuilder(); - if (params.isEmpty()) { - paramsStr.append(","); - }//if - else { - for (Iterator iterator = params.keySet().iterator(); iterator.hasNext(); ) { - Integer key = iterator.next(); - Object value = params.get(key); - if (value == null) { - value = NULL_STR; - }//if - - paramsStr.append(",:").append(key).append("=").append(value); - } - }//else - super.logExecution(method, queryStr + " - (" + buildParamList() + ")", executeTime, update); }//if } diff --git a/jpalite-core/src/main/java/io/jpalite/impl/queries/JPALiteQueryImpl.java b/jpalite-core/src/main/java/io/jpalite/impl/queries/JPALiteQueryImpl.java index 4c80fd0..bf7aac4 100644 --- a/jpalite-core/src/main/java/io/jpalite/impl/queries/JPALiteQueryImpl.java +++ b/jpalite-core/src/main/java/io/jpalite/impl/queries/JPALiteQueryImpl.java @@ -91,7 +91,7 @@ public class JPALiteQueryImpl implements Query /** * The lock mode of the returned item */ - private LockModeType lockMode = LockModeType.NONE; + private LockModeType lockMode; /** * The expected return type */ diff --git a/jpalite-core/src/main/java/io/jpalite/impl/queries/NamedQueryImpl.java b/jpalite-core/src/main/java/io/jpalite/impl/queries/NamedQueryImpl.java index 56ac734..28ed138 100644 --- a/jpalite-core/src/main/java/io/jpalite/impl/queries/NamedQueryImpl.java +++ b/jpalite-core/src/main/java/io/jpalite/impl/queries/NamedQueryImpl.java @@ -30,8 +30,7 @@ public class NamedQueryImpl extends TypedQueryImpl { public static final @Nonnull Map buildHints(Map hints, QueryHint[] namedHints) { - Map newHints = new HashMap<>(); - newHints.putAll(hints); + Map newHints = new HashMap<>(hints); for (QueryHint hint : namedHints) { newHints.put(hint.name(), hint.value()); }//for diff --git a/jpalite-core/src/main/java/io/jpalite/impl/serializers/JPAEntityMarshaller.java b/jpalite-core/src/main/java/io/jpalite/impl/serializers/JPAEntityMarshaller.java index d813777..5ccc64c 100644 --- a/jpalite-core/src/main/java/io/jpalite/impl/serializers/JPAEntityMarshaller.java +++ b/jpalite-core/src/main/java/io/jpalite/impl/serializers/JPAEntityMarshaller.java @@ -134,10 +134,6 @@ private Object readField(ReadContext context, TagReader reader, EntityMetaData subMetaData = EntityMetaDataManager.getMetaData(field.getType()); - if (subMetaData == null) { - throw new IOException(field.getType() + " is not an entity"); - }//if - Object primaryKey; //If we have multiple keys then that primary key will be stored in an embedded object if (metaData.hasMultipleIdFields()) { diff --git a/jpalite-maven-plugin/src/main/java/io/jpalite/JPALiteMojo.java b/jpalite-maven-plugin/src/main/java/io/jpalite/JPALiteMojo.java index eda2938..1b33618 100644 --- a/jpalite-maven-plugin/src/main/java/io/jpalite/JPALiteMojo.java +++ b/jpalite-maven-plugin/src/main/java/io/jpalite/JPALiteMojo.java @@ -97,7 +97,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO return vClassList; } - @SuppressWarnings("java:S2112") //We need URLs here + @SuppressWarnings({"java:S2112", "UrlHashCode"}) //We need URLs here public void execute() throws MojoExecutionException { if (skip) { diff --git a/jpalite-quarkus-extension/runtime/src/main/java/io/jpalite/extension/TransactionScopedEntityManagerImpl.java b/jpalite-quarkus-extension/runtime/src/main/java/io/jpalite/extension/TransactionScopedEntityManagerImpl.java index f6f2fd6..88559d7 100644 --- a/jpalite-quarkus-extension/runtime/src/main/java/io/jpalite/extension/TransactionScopedEntityManagerImpl.java +++ b/jpalite-quarkus-extension/runtime/src/main/java/io/jpalite/extension/TransactionScopedEntityManagerImpl.java @@ -43,6 +43,7 @@ import java.util.List; import java.util.Map; +@SuppressWarnings("SqlSourceToSinkFlow") public class TransactionScopedEntityManagerImpl implements JPALiteEntityManager { private static final Logger LOG = LoggerFactory.getLogger(TransactionScopedEntityManagerImpl.class); diff --git a/jpalite-repository/src/main/java/io/jpalite/repository/Filter.java b/jpalite-repository/src/main/java/io/jpalite/repository/Filter.java index e82642f..65ffbad 100644 --- a/jpalite-repository/src/main/java/io/jpalite/repository/Filter.java +++ b/jpalite-repository/src/main/java/io/jpalite/repository/Filter.java @@ -25,15 +25,15 @@ public class Filter public static final String AND = " AND "; public static final String OR = " OR "; - private List filters; + private final List filters; private FilterExpression filterExpressions; private String condOper; - public class FilterExpression + public static class FilterExpression { - private String field; - private Operators operator; - private Object[] parameter; + private final String field; + private final Operators operator; + private final Object[] parameter; public FilterExpression(String field, Operators operator, Object... parameters) { @@ -68,7 +68,7 @@ public String getExpression(Map params) if (paramNr > 1) { expr.append(","); }//if - expr.append(":" + paramName + paramNr); + expr.append(":").append(paramName).append(paramNr); paramNr++; }//for expr.append(")"); @@ -82,7 +82,7 @@ public String getExpression(Map params) int paramNr = 1; for (Object param : parameter) { params.put(paramName + paramNr, operator.getPrefix() + param + operator.getPostfix()); - expr.append(" :" + paramName + paramNr); + expr.append(" :").append(paramName).append(paramNr); paramNr++; }//for yield expr.toString(); @@ -98,7 +98,7 @@ public String getExpression(Map params) if (paramNr > 1) { expr.append(","); }//if - expr.append(" :" + paramName + paramNr); + expr.append(" :").append(paramName).append(paramNr); paramNr++; }//for yield expr.toString(); diff --git a/jpalite-repository/src/main/java/io/jpalite/repository/JPALiteRepositoryProcessor.java b/jpalite-repository/src/main/java/io/jpalite/repository/JPALiteRepositoryProcessor.java index f37b404..861dfb6 100644 --- a/jpalite-repository/src/main/java/io/jpalite/repository/JPALiteRepositoryProcessor.java +++ b/jpalite-repository/src/main/java/io/jpalite/repository/JPALiteRepositoryProcessor.java @@ -263,8 +263,12 @@ private void createMethod(PrintWriter out, ExecutableElement method) method.getParameters() .stream() .filter(p -> p.asType().toString().equals(Pageable.class.getName())) - .forEach(p -> pageAndSort.append("query.setFirstResult(" + p.getSimpleName() + ".getPageIndex())\n") - .append(".setMaxResults(" + p.getSimpleName() + ".getPageSize());\n")); + .forEach(p -> pageAndSort.append("query.setFirstResult(") + .append(p.getSimpleName()) + .append(".getPageIndex())\n") + .append(".setMaxResults(") + .append(p.getSimpleName()) + .append(".getPageSize());\n")); }//if else { out.println("String queryStr = \"" + query.value() + "\";"); @@ -277,8 +281,12 @@ private void createMethod(PrintWriter out, ExecutableElement method) .filter(p -> p.asType().toString().equals(Pageable.class.getName())) .forEach(p -> { - pageAndSort.append("query.setFirstResult(" + p.getSimpleName() + ".getPageIndex())\n") - .append(".setMaxResults(" + p.getSimpleName() + ".getPageSize());\n"); + pageAndSort.append("query.setFirstResult(") + .append(p.getSimpleName()) + .append(".getPageIndex())\n") + .append(".setMaxResults(") + .append(p.getSimpleName()) + .append(".getPageSize());\n"); out.println("queryStr += " + p.getSimpleName() + ".getSort().getOrderBy();"); }); method.getParameters() diff --git a/pom.xml b/pom.xml index 2f6a25c..ead2d7c 100644 --- a/pom.xml +++ b/pom.xml @@ -165,9 +165,10 @@ - TradeSwitch - Internal TradeSwitch Release Repository - https://nexus.frei.dev/repository/tradeswitch.dev/ + devrepo + Dev Repo + http://localhost:8046/artifactory/devrepo/ + default