From a04a00ae7ca73184936d77b3a8a8e10702ec6231 Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 14:10:55 -0500 Subject: [PATCH 01/10] remove dupe code to 100 tokens on CPD. Get rid of inputstream and reader wrappers --- .../cpo/CpoByteArrayInputStream.java | 127 ------------------ .../synchronoss/cpo/CpoCharArrayReader.java | 125 ----------------- .../cpo/exporter/AbstractMetaVisitor.java | 102 ++++++++++++++ .../cpo/exporter/CpoClassSourceGenerator.java | 80 +++-------- .../exporter/CpoInterfaceSourceGenerator.java | 66 +-------- .../CpoLegacyClassSourceGenerator.java | 43 +----- .../cpo/jta/CpoBaseXaResource.java | 6 +- .../cpo/meta/bean/CpoClassBean.java | 21 +-- .../cpo/meta/bean/CpoFunctionGroupBean.java | 25 ++-- .../cpo/jdbc/CallableStatementCpoData.java | 20 +-- .../jdbc/JdbcPreparedStatementCpoData.java | 22 +-- pom.xml | 5 +- 12 files changed, 150 insertions(+), 492 deletions(-) delete mode 100644 cpo-core/src/main/java/org/synchronoss/cpo/CpoByteArrayInputStream.java delete mode 100644 cpo-core/src/main/java/org/synchronoss/cpo/CpoCharArrayReader.java create mode 100644 cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/CpoByteArrayInputStream.java b/cpo-core/src/main/java/org/synchronoss/cpo/CpoByteArrayInputStream.java deleted file mode 100644 index a4c24c0ce..000000000 --- a/cpo-core/src/main/java/org/synchronoss/cpo/CpoByteArrayInputStream.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.synchronoss.cpo; - -/*- - * [[ - * core - * == - * Copyright (C) 2003 - 2025 David E. Berry - * == - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ]] - */ - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * CpoByteArrayInputStream is a utility class to help process ByteArrayInputStreams - * - * @author david berry - */ -public class CpoByteArrayInputStream extends ByteArrayInputStream - implements java.io.Serializable, Cloneable { - - /** Version Id for this class. */ - private static final long serialVersionUID = 1L; - - private static final Logger logger = LoggerFactory.getLogger(CpoByteArrayInputStream.class); - private byte[] buffer_ = null; // The buffer for the byte Array - private int offset_ = 0; - private int size_ = 0; - - public CpoByteArrayInputStream(byte[] buffer) { - super(buffer); - buffer_ = buffer; - } - - public CpoByteArrayInputStream(byte[] buffer, int offset, int length) { - super(buffer, offset, length); - buffer_ = buffer; - offset_ = offset; - size_ = length; - } - - protected void setBuffer(byte[] buffer) { - buffer_ = buffer; - } - - protected byte[] getBuffer() { - return buffer_; - } - - protected void setOffset(int offset) { - offset_ = offset; - } - - protected int getOffset() { - return offset_; - } - - protected void setSize(int size) { - size_ = size; - } - - protected int getSize() { - return size_; - } - - public int getLength() { - int l; - - if (getOffset() == 0) { - l = getBuffer().length; - } else { - l = - getSize() < getBuffer().length - getOffset() - ? getSize() - : getBuffer().length - getOffset(); - } - return l; - } - - public static CpoByteArrayInputStream getCpoStream(InputStream is) { - CpoByteArrayInputStream cbais = null; - - if (is instanceof CpoByteArrayInputStream) { - cbais = ((CpoByteArrayInputStream) is); - } else { - // Need to determine the length of the InputStream - int b; - try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - while ((b = is.read()) != -1) { - baos.write(b); - } - cbais = new CpoByteArrayInputStream(baos.toByteArray()); - } catch (IOException ioe) { - logger.error( - "Error processing input stream", - ioe); // do nothing for now. The null should get someone's attention. - } finally { - try { - is.close(); - } catch (IOException ioe) { - logger.error("Error closing input stream", ioe); - } - } - } - - return cbais; - } -} diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/CpoCharArrayReader.java b/cpo-core/src/main/java/org/synchronoss/cpo/CpoCharArrayReader.java deleted file mode 100644 index f72d88919..000000000 --- a/cpo-core/src/main/java/org/synchronoss/cpo/CpoCharArrayReader.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.synchronoss.cpo; - -/*- - * [[ - * core - * == - * Copyright (C) 2003 - 2025 David E. Berry - * == - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ]] - */ - -import java.io.CharArrayReader; -import java.io.CharArrayWriter; -import java.io.IOException; -import java.io.Reader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * CpoCharArrayReader is a utility class to help process CharArrayReader - * - * @author david berry - */ -public class CpoCharArrayReader extends CharArrayReader implements java.io.Serializable, Cloneable { - - /** Version Id for this class. */ - private static final long serialVersionUID = 1L; - - private static final Logger logger = LoggerFactory.getLogger(CpoCharArrayReader.class); - private char[] buffer_ = null; // The buffer for the byte Array - private int offset_ = 0; - private int size_ = 0; - - public CpoCharArrayReader(char[] buffer) { - super(buffer); - buffer_ = buffer; - } - - public CpoCharArrayReader(char[] buffer, int offset, int length) { - super(buffer, offset, length); - buffer_ = buffer; - offset_ = offset; - size_ = length; - } - - protected void setBuffer(char[] buffer) { - buffer_ = buffer; - } - - protected char[] getBuffer() { - return buffer_; - } - - protected void setOffset(int offset) { - offset_ = offset; - } - - protected int getOffset() { - return offset_; - } - - protected void setSize(int size) { - size_ = size; - } - - protected int getSize() { - return size_; - } - - public int getLength() { - int l; - - if (getOffset() == 0) { - l = getBuffer().length; - } else { - l = - getSize() < getBuffer().length - getOffset() - ? getSize() - : getBuffer().length - getOffset(); - } - return l; - } - - public static CpoCharArrayReader getCpoReader(Reader r) { - CpoCharArrayReader ccar = null; - if (r instanceof CpoCharArrayReader) { - ccar = ((CpoCharArrayReader) r); - } else { - // Need to determine the length of the Reader - // Need to determine the length of the InputStream - int b; - try { - CharArrayWriter caw = new CharArrayWriter(); - while ((b = r.read()) != -1) { - caw.write(b); - } - ccar = new CpoCharArrayReader(caw.toCharArray()); - } catch (IOException ioe) { - // do nothing for now. The null should get someone's attention. - logger.warn("Problem reading cpo reader", ioe); - } finally { - try { - r.close(); - } catch (IOException ioe) { - logger.warn("Problem closing cpo reader", ioe); - } - } - } - - return ccar; - } -} diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java new file mode 100644 index 000000000..df7db2d41 --- /dev/null +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java @@ -0,0 +1,102 @@ +package org.synchronoss.cpo.exporter; + +/*- + * [[ + * core + * == + * Copyright (C) 2003 - 2025 David E. Berry + * == + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * ]] + */ + +import org.synchronoss.cpo.MetaVisitor; +import org.synchronoss.cpo.meta.domain.CpoArgument; +import org.synchronoss.cpo.meta.domain.CpoFunction; +import org.synchronoss.cpo.meta.domain.CpoFunctionGroup; + +public abstract class AbstractMetaVisitor implements MetaVisitor { + protected static final String ATTR_PREFIX = "ATTR_"; + protected static final String FG_PREFIX = "FG_"; + + protected StringBuilder attributeStatics = new StringBuilder(); + protected StringBuilder functionGroupStatics = new StringBuilder(); + protected StringBuilder gettersSetters = new StringBuilder(); + + protected String buildGetterName(String attName) { + // the getter name is get concatenated with the camel case of the attribute name + String getterName; + if (attName.length() > 1) { + getterName = ("get" + attName.substring(0, 1).toUpperCase() + attName.substring(1) + "()"); + } else { + getterName = ("get" + attName.toUpperCase() + "()"); + } + return getterName; + } + + protected String buildSetterName(String attName) { + // the setter name is get concatenated with the camel case of the attribute name + String setterName; + if (attName.length() > 1) { + setterName = ("set" + attName.substring(0, 1).toUpperCase() + attName.substring(1)); + } else { + setterName = ("set" + attName.toUpperCase()); + } + return setterName; + } + + protected String buildAttributeStatic(String attName) { + return " public final static String " + + ATTR_PREFIX + + attName.toUpperCase() + + " = \"" + + attName + + "\";\n"; + } + + @Override + public void visit(CpoFunctionGroup cpoFunctionGroup) { + + // generate statics for function group + String fgName = cpoFunctionGroup.getName(); + if (fgName == null) { + fgName = "NULL"; + } + fgName = scrubName(fgName); + + String staticName = FG_PREFIX + cpoFunctionGroup.getType() + "_" + fgName.toUpperCase(); + + if (cpoFunctionGroup.getName() == null) { + functionGroupStatics.append(" public final static String " + staticName + " = null;\n"); + } else { + functionGroupStatics.append( + " public final static String " + staticName + " = \"" + fgName + "\";\n"); + } + } + + @Override + public void visit(CpoFunction cpoFunction) { + // nothing to do + } + + @Override + public void visit(CpoArgument cpoArgument) { + // nothing to do + } + + protected String scrubName(String name) { + return name.replaceAll("[^0-9a-zA-Z_]", "_"); + } +} diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java index 4b82353a8..aece98f7a 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java @@ -22,13 +22,9 @@ * ]] */ -import org.synchronoss.cpo.MetaVisitor; import org.synchronoss.cpo.meta.CpoMetaDescriptor; -import org.synchronoss.cpo.meta.domain.CpoArgument; import org.synchronoss.cpo.meta.domain.CpoAttribute; import org.synchronoss.cpo.meta.domain.CpoClass; -import org.synchronoss.cpo.meta.domain.CpoFunction; -import org.synchronoss.cpo.meta.domain.CpoFunctionGroup; /** * The CpoClassSourceGenerator generates java source code to define the cpo classes. @@ -36,20 +32,15 @@ * @author Michael Bellomo * @since 4/17/12 */ -public class CpoClassSourceGenerator implements MetaVisitor { +public class CpoClassSourceGenerator extends AbstractMetaVisitor { - private static final String ATTR_PREFIX = "ATTR_"; - private static final String FG_PREFIX = "FG_"; private static final String CLASS_SUFFIX = "Bean"; protected CpoMetaDescriptor metaDescriptor; protected String className = null; protected StringBuilder header = new StringBuilder(); - protected StringBuilder attributeStatics = new StringBuilder(); - protected StringBuilder functionGroupStatics = new StringBuilder(); protected StringBuilder properties = new StringBuilder(); protected StringBuilder constructor = new StringBuilder(); - protected StringBuilder gettersSetters = new StringBuilder(); protected StringBuilder equals = new StringBuilder(); protected StringBuilder hashCode = new StringBuilder(); protected StringBuilder toString = new StringBuilder(); @@ -80,13 +71,7 @@ public String getClassName() { return className; } - public String getSourceCode() { - StringBuilder source = new StringBuilder(); - - source.append("/* \n"); - source.append(" * This class auto-generated by " + this.getClass().getName() + "\n"); - source.append(" */\n"); - source.append(header); + protected void appendClassBody(StringBuilder source) { source.append("\n"); source.append(" /* Properties */\n"); source.append(properties); @@ -128,6 +113,17 @@ public String getSourceCode() { source.append(footer); source.append("\n"); + } + + public String getSourceCode() { + StringBuilder source = new StringBuilder(); + + source.append("/* \n"); + source.append(" * This class auto-generated by " + this.getClass().getName() + "\n"); + source.append(" */\n"); + source.append(header); + + appendClassBody(source); return source.toString(); } @@ -183,24 +179,14 @@ public void visit(CpoAttribute cpoAttribute) { String attName = scrubName(cpoAttribute.getJavaName()); - // the getter name is get concatenated with the camel case of the attribute name - String getterName; - String setterName; - if (attName.length() > 1) { - getterName = ("get" + attName.substring(0, 1).toUpperCase() + attName.substring(1) + "()"); - setterName = ("set" + attName.substring(0, 1).toUpperCase() + attName.substring(1)); - } else { - getterName = ("get" + attName.toUpperCase() + "()"); - setterName = ("set" + attName.toUpperCase()); - } + String getterName = buildGetterName(attName); + String setterName = buildSetterName(attName); String attClassName = cpoAttribute.getJavaType(); Class attClass = getAttributeClass(attClassName); // generate attribute statics - String staticName = ATTR_PREFIX + attName.toUpperCase(); - attributeStatics.append( - " public final static String " + staticName + " = \"" + attName + "\";\n"); + attributeStatics.append(buildAttributeStatic(attName)); // generate property declarations properties.append(" protected " + attClassName + " " + attName + ";\n"); @@ -265,40 +251,6 @@ public void visit(CpoAttribute cpoAttribute) { toString.append(" str.append(\"" + attName + " = \" + " + getterName + " + \"\\n\");\n"); } - @Override - public void visit(CpoFunctionGroup cpoFunctionGroup) { - - // generate statics for function group - String fgName = cpoFunctionGroup.getName(); - if (fgName == null) { - fgName = "NULL"; - } - fgName = scrubName(fgName); - - String staticName = FG_PREFIX + cpoFunctionGroup.getType() + "_" + fgName.toUpperCase(); - - if (cpoFunctionGroup.getName() == null) { - functionGroupStatics.append(" public final static String " + staticName + " = null;\n"); - } else { - functionGroupStatics.append( - " public final static String " + staticName + " = \"" + fgName + "\";\n"); - } - } - - @Override - public void visit(CpoFunction cpoFunction) { - // nothing to do - } - - @Override - public void visit(CpoArgument cpoArgument) { - // nothing to do - } - - protected String scrubName(String name) { - return name.replaceAll("[^0-9a-zA-Z_]", "_"); - } - private Class getAttributeClass(String className) { Class clazz = String.class; diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoInterfaceSourceGenerator.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoInterfaceSourceGenerator.java index f2d80eabe..931a4aa2d 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoInterfaceSourceGenerator.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoInterfaceSourceGenerator.java @@ -22,13 +22,9 @@ * ]] */ -import org.synchronoss.cpo.MetaVisitor; import org.synchronoss.cpo.meta.CpoMetaDescriptor; -import org.synchronoss.cpo.meta.domain.CpoArgument; import org.synchronoss.cpo.meta.domain.CpoAttribute; import org.synchronoss.cpo.meta.domain.CpoClass; -import org.synchronoss.cpo.meta.domain.CpoFunction; -import org.synchronoss.cpo.meta.domain.CpoFunctionGroup; /** * The CpoInterfaceSourceGenerator generates java source code to define the cpo interfaces. @@ -36,17 +32,11 @@ * @author Michael Bellomo * @since 4/17/12 */ -public class CpoInterfaceSourceGenerator implements MetaVisitor { - - private static final String ATTR_PREFIX = "ATTR_"; - private static final String FG_PREFIX = "FG_"; +public class CpoInterfaceSourceGenerator extends AbstractMetaVisitor { protected CpoMetaDescriptor metaDescriptor; protected String interfaceName = null; protected StringBuilder header = new StringBuilder(); - protected StringBuilder attributeStatics = new StringBuilder(); - protected StringBuilder functionGroupStatics = new StringBuilder(); - protected StringBuilder gettersSetters = new StringBuilder(); protected StringBuilder footer = new StringBuilder(); public CpoInterfaceSourceGenerator(CpoMetaDescriptor metaDescriptor) { @@ -127,27 +117,13 @@ public void visit(CpoAttribute cpoAttribute) { String attName = scrubName(cpoAttribute.getJavaName()); - // the getter name is get concatenated with the camel case of the attribute name - String getterName; - String setterName; - if (attName.length() > 1) { - getterName = ("get" + attName.substring(0, 1).toUpperCase() + attName.substring(1) + "()"); - setterName = ("set" + attName.substring(0, 1).toUpperCase() + attName.substring(1)); - } else { - getterName = ("get" + attName.toUpperCase() + "()"); - setterName = ("set" + attName.toUpperCase()); - } + String getterName = buildGetterName(attName); + String setterName = buildSetterName(attName); String attClassName = cpoAttribute.getJavaType(); // generate attribute statics - attributeStatics.append( - " public final static String " - + ATTR_PREFIX - + attName.toUpperCase() - + " = \"" - + attName - + "\";\n"); + attributeStatics.append(buildAttributeStatic(attName)); // generate getter gettersSetters.append(" public " + attClassName + " " + getterName + ";\n"); @@ -157,38 +133,4 @@ public void visit(CpoAttribute cpoAttribute) { " public void " + setterName + "(" + attClassName + " " + attName + ");\n"); gettersSetters.append("\n"); } - - @Override - public void visit(CpoFunctionGroup cpoFunctionGroup) { - - // generate statics for function group - String fgName = cpoFunctionGroup.getName(); - if (fgName == null) { - fgName = "NULL"; - } - fgName = scrubName(fgName); - - String staticName = FG_PREFIX + cpoFunctionGroup.getType() + "_" + fgName.toUpperCase(); - - if (cpoFunctionGroup.getName() == null) { - functionGroupStatics.append(" public final static String " + staticName + " = null;\n"); - } else { - functionGroupStatics.append( - " public final static String " + staticName + " = \"" + fgName + "\";\n"); - } - } - - @Override - public void visit(CpoFunction cpoFunction) { - // nothing to do - } - - @Override - public void visit(CpoArgument cpoArgument) { - // nothing to do - } - - protected String scrubName(String name) { - return name.replaceAll("[^0-9a-zA-Z_]", "_"); - } } diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java index 2699bfe13..a3600c291 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java @@ -57,47 +57,8 @@ public String getSourceCode() { source.append("\n"); source.append(" /* Function group statics */\n"); source.append(functionGroupStatics); - source.append("\n"); - source.append(" /* Properties */\n"); - source.append(properties); - source.append("\n"); - source.append(" /* Constructor */\n"); - source.append(constructor); - source.append("\n"); - source.append(" /* Getters and Setters */\n"); - source.append(gettersSetters); - - // generate equals() - source.append(" public boolean equals(Object o) {\n"); - source.append(" if (this == o)\n"); - source.append(" return true;\n"); - source.append(" if (o == null || getClass() != o.getClass())\n"); - source.append(" return false;\n"); - source.append("\n"); - source.append(" " + className + " that = (" + className + ")o;\n"); - source.append("\n"); - source.append(equals); - source.append("\n"); - source.append(" return true;\n"); - source.append(" }\n\n"); - - // generate hashCode() - source.append(" public int hashCode() {\n"); - source.append(" int result = 0;\n"); - source.append(" result = 31 * result + getClass().getName().hashCode();\n"); - source.append(hashCode); - source.append(" return result;\n"); - source.append(" }\n\n"); - - // generate toString() - source.append(" public String toString() {\n"); - source.append(" StringBuilder str = new StringBuilder();\n"); - source.append(toString); - source.append(" return str.toString();\n"); - source.append(" }\n"); - - source.append(footer); - source.append("\n"); + + appendClassBody(source); return source.toString(); } diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java b/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java index e62789eb0..2f0a7fdff 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java @@ -233,9 +233,9 @@ public void end(Xid xid, int flags) throws XAException { case TMSUSPEND: // You can only suspend an associated transaction if (cpoXaState.getAssociation() != CpoXaState.XA_ASSOCIATED) - throw new RuntimeException( - CpoXaError.createXAException( - CpoXaError.XAER_PROTO, "You can only suspend an associated XID")); + throw new RuntimeException( + CpoXaError.createXAException( + CpoXaError.XAER_PROTO, "You can only suspend an associated XID")); cpoXaState.setAssociation(CpoXaState.XA_SUSPENDED); break; diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoClassBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoClassBean.java index 9b4d9c1bd..95053d6d2 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoClassBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoClassBean.java @@ -55,25 +55,18 @@ public void setDescription(String description) { @Override public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; CpoClassBean that = (CpoClassBean) o; - if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) { - return false; - } - if (getDescription() != null - ? !getDescription().equals(that.getDescription()) - : that.getDescription() != null) { + if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false; - } - return true; + return getDescription() != null + ? getDescription().equals(that.getDescription()) + : that.getDescription() == null; } @Override diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java index bdb31cb54..7449ceb83 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java @@ -64,28 +64,21 @@ public void setType(String type) { */ @Override public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; CpoFunctionGroupBean that = (CpoFunctionGroupBean) o; - if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) { + if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false; - } - if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) { - return false; - } - if (getDescription() != null - ? !getDescription().equals(that.getDescription()) - : that.getDescription() != null) { + + if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) return false; - } - return true; + return getDescription() != null + ? getDescription().equals(that.getDescription()) + : that.getDescription() == null; } @Override diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java index 24e1f0e44..96948a1cd 100644 --- a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java @@ -22,14 +22,10 @@ * ]] */ -import java.io.InputStream; -import java.io.Reader; import java.lang.reflect.InvocationTargetException; import java.sql.CallableStatement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.synchronoss.cpo.CpoByteArrayInputStream; -import org.synchronoss.cpo.CpoCharArrayReader; import org.synchronoss.cpo.CpoException; import org.synchronoss.cpo.helper.ExceptionHelper; import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapEntry; @@ -142,22 +138,10 @@ public void invokeSetter(Object instanceObject) throws CpoException { switch (jdbcMethodMapEntry.getMethodType()) { case JdbcMethodMapEntry.METHOD_TYPE_BASIC: case JdbcMethodMapEntry.METHOD_TYPE_OBJECT: - default: - jdbcMethodMapEntry.getCsSetter().invoke(jcsf.getCallableStatement(), getIndex(), param); - break; case JdbcMethodMapEntry.METHOD_TYPE_STREAM: - CpoByteArrayInputStream cbais = CpoByteArrayInputStream.getCpoStream((InputStream) param); - // Get the length of the InputStream in param - jdbcMethodMapEntry - .getCsSetter() - .invoke(jcsf.getCallableStatement(), getIndex(), cbais, cbais.getLength()); - break; case JdbcMethodMapEntry.METHOD_TYPE_READER: - CpoCharArrayReader ccar = CpoCharArrayReader.getCpoReader((Reader) param); - // Get the length of the Reader in param - jdbcMethodMapEntry - .getCsSetter() - .invoke(jcsf.getCallableStatement(), getIndex(), ccar, ccar.getLength()); + default: + jdbcMethodMapEntry.getCsSetter().invoke(jcsf.getCallableStatement(), getIndex(), param); break; } } catch (Exception e) { diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java index d68587a72..a84169d37 100644 --- a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java @@ -22,12 +22,8 @@ * ]] */ -import java.io.InputStream; -import java.io.Reader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.synchronoss.cpo.CpoByteArrayInputStream; -import org.synchronoss.cpo.CpoCharArrayReader; import org.synchronoss.cpo.CpoException; import org.synchronoss.cpo.helper.ExceptionHelper; import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapEntry; @@ -82,26 +78,12 @@ public void invokeSetter(Object instanceObject) throws CpoException { switch (methodMapEntry.getMethodType()) { case JdbcMethodMapEntry.METHOD_TYPE_BASIC: case JdbcMethodMapEntry.METHOD_TYPE_OBJECT: - default: - methodMapEntry - .getBsSetter() - .invoke(cpoStatementFactory.getPreparedStatement(), getIndex(), param); - break; case JdbcMethodMapEntry.METHOD_TYPE_STREAM: - CpoByteArrayInputStream cbais = CpoByteArrayInputStream.getCpoStream((InputStream) param); - // Get the length of the InputStream in param - methodMapEntry - .getBsSetter() - .invoke( - cpoStatementFactory.getPreparedStatement(), getIndex(), cbais, cbais.getLength()); - break; case JdbcMethodMapEntry.METHOD_TYPE_READER: - CpoCharArrayReader ccar = CpoCharArrayReader.getCpoReader((Reader) param); - // Get the length of the Reader in param + default: methodMapEntry .getBsSetter() - .invoke( - cpoStatementFactory.getPreparedStatement(), getIndex(), ccar, ccar.getLength()); + .invoke(cpoStatementFactory.getPreparedStatement(), getIndex(), param); break; } } catch (Exception e) { diff --git a/pom.xml b/pom.xml index 3b944744d..9a4e1422f 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 20 + 100 **/*.java @@ -426,11 +426,12 @@ CPD - false + true cpd-check + compile From 2fd6a39f0913cd6c3c4bdde19463af30c34f5f12 Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 14:41:49 -0500 Subject: [PATCH 02/10] remove dupe code to 75 tokens on CPD. --- .../cpo/meta/bean/CpoArgumentBean.java | 48 +++++------ .../cpo/meta/bean/CpoAttributeBean.java | 84 ++++++++----------- .../cpo/meta/bean/CpoClassBean.java | 32 +++---- .../cpo/meta/bean/CpoFunctionBean.java | 48 +++++------ .../cpo/meta/bean/CpoFunctionGroupBean.java | 44 +++++----- pom.xml | 2 +- 6 files changed, 115 insertions(+), 143 deletions(-) diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java index c1913d6de..93bf8ad2f 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java @@ -34,6 +34,9 @@ public class CpoArgumentBean implements java.io.Serializable { public CpoArgumentBean() {} + /* + * Getters and Setters + */ public String getAttributeName() { return attributeName; } @@ -50,34 +53,6 @@ public void setDescription(String description) { this.description = description; } - /* - * Getters and Setters - */ - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - CpoArgumentBean that = (CpoArgumentBean) o; - - if (getAttributeName() != null - ? !getAttributeName().equals(that.getAttributeName()) - : that.getAttributeName() != null) { - return false; - } - if (getDescription() != null - ? !getDescription().equals(that.getDescription()) - : that.getDescription() != null) { - return false; - } - - return true; - } - @Override public int hashCode() { int result = 0; @@ -94,4 +69,21 @@ public String toString() { str.append("description = " + getDescription() + "\n"); return str.toString(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + CpoArgumentBean that = (CpoArgumentBean) o; + + if (getAttributeName() != null + ? !getAttributeName().equals(that.getAttributeName()) + : that.getAttributeName() != null) return false; + + return getDescription() != null + ? getDescription().equals(that.getDescription()) + : that.getDescription() == null; + } } diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoAttributeBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoAttributeBean.java index 6ceee932d..934d9970c 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoAttributeBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoAttributeBean.java @@ -38,6 +38,9 @@ public class CpoAttributeBean implements java.io.Serializable { public CpoAttributeBean() {} + /* + * Getters and Setters + */ public String getDataName() { return dataName; } @@ -86,54 +89,6 @@ public void setTransformClassName(String transformClassName) { this.transformClassName = transformClassName; } - /* - * Getters and Setters - */ - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - CpoAttributeBean that = (CpoAttributeBean) o; - - if (getJavaName() != null - ? !getJavaName().equals(that.getJavaName()) - : that.getJavaName() != null) { - return false; - } - if (getJavaType() != null - ? !getJavaType().equals(that.getJavaType()) - : that.getJavaType() != null) { - return false; - } - if (getDataName() != null - ? !getDataName().equals(that.getDataName()) - : that.getDataName() != null) { - return false; - } - if (getDataType() != null - ? !getDataType().equals(that.getDataType()) - : that.getDataType() != null) { - return false; - } - if (getTransformClassName() != null - ? !getTransformClassName().equals(that.getTransformClassName()) - : that.getTransformClassName() != null) { - return false; - } - if (getDescription() != null - ? !getDescription().equals(that.getDescription()) - : that.getDescription() != null) { - return false; - } - - return true; - } - @Override public int hashCode() { int result = 0; @@ -159,4 +114,37 @@ public String toString() { str.append("description = " + getDescription() + "\n"); return str.toString(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + CpoAttributeBean that = (CpoAttributeBean) o; + + if (getJavaName() != null + ? !getJavaName().equals(that.getJavaName()) + : that.getJavaName() != null) return false; + + if (getJavaType() != null + ? !getJavaType().equals(that.getJavaType()) + : that.getJavaType() != null) return false; + + if (getDataName() != null + ? !getDataName().equals(that.getDataName()) + : that.getDataName() != null) return false; + + if (getDataType() != null + ? !getDataType().equals(that.getDataType()) + : that.getDataType() != null) return false; + + if (getTransformClassName() != null + ? !getTransformClassName().equals(that.getTransformClassName()) + : that.getTransformClassName() != null) return false; + + return getDescription() != null + ? getDescription().equals(that.getDescription()) + : that.getDescription() == null; + } } diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoClassBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoClassBean.java index 95053d6d2..0403e3ce7 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoClassBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoClassBean.java @@ -53,22 +53,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - CpoClassBean that = (CpoClassBean) o; - - if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) - return false; - - return getDescription() != null - ? getDescription().equals(that.getDescription()) - : that.getDescription() == null; - } - @Override public int hashCode() { int result = 0; @@ -85,4 +69,20 @@ public String toString() { str.append("description = " + getDescription() + "\n"); return str.toString(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + CpoClassBean that = (CpoClassBean) o; + + if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) + return false; + + return getDescription() != null + ? getDescription().equals(that.getDescription()) + : that.getDescription() == null; + } } diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionBean.java index 0e103228c..a3efeeef4 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionBean.java @@ -35,6 +35,9 @@ public class CpoFunctionBean implements java.io.Serializable { public CpoFunctionBean() {} + /* + * Getters and Setters + */ public String getName() { return name; } @@ -59,34 +62,6 @@ public void setExpression(String expression) { this.expression = expression; } - /* - * Getters and Setters - */ - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - CpoFunctionBean that = (CpoFunctionBean) o; - - if (getExpression() != null - ? !getExpression().equals(that.getExpression()) - : that.getExpression() != null) { - return false; - } - if (getDescription() != null - ? !getDescription().equals(that.getDescription()) - : that.getDescription() != null) { - return false; - } - - return true; - } - @Override public int hashCode() { int result = 0; @@ -103,4 +78,21 @@ public String toString() { str.append("description = " + getDescription() + "\n"); return str.toString(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + CpoFunctionBean that = (CpoFunctionBean) o; + + if (getExpression() != null + ? !getExpression().equals(that.getExpression()) + : that.getExpression() != null) return false; + + return getDescription() != null + ? getDescription().equals(that.getDescription()) + : that.getDescription() == null; + } } diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java index 7449ceb83..0d136e82c 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java @@ -35,6 +35,9 @@ public class CpoFunctionGroupBean implements java.io.Serializable { public CpoFunctionGroupBean() {} + /* + * Getters and Setters + */ public String getDescription() { return description; } @@ -59,28 +62,6 @@ public void setType(String type) { this.type = type; } - /* - * Getters and Setters - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - CpoFunctionGroupBean that = (CpoFunctionGroupBean) o; - - if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) - return false; - - if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) - return false; - - return getDescription() != null - ? getDescription().equals(that.getDescription()) - : that.getDescription() == null; - } - @Override public int hashCode() { int result = 0; @@ -99,4 +80,23 @@ public String toString() { str.append("description = " + getDescription() + "\n"); return str.toString(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + CpoFunctionGroupBean that = (CpoFunctionGroupBean) o; + + if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) + return false; + + if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) + return false; + + return getDescription() != null + ? getDescription().equals(that.getDescription()) + : that.getDescription() == null; + } } diff --git a/pom.xml b/pom.xml index 9a4e1422f..b65200cdd 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 100 + 75 **/*.java From f82b89f55cb044a5a957e64d9a4b7979e2613d27 Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 15:28:34 -0500 Subject: [PATCH 03/10] remove dupe code to 70 tokens on CPD. --- .../cpo/jta/CpoBaseXaResource.java | 40 +++++++------------ .../cpo/jdbc/CallableStatementCpoData.java | 30 +++++++------- pom.xml | 2 +- 3 files changed, 31 insertions(+), 41 deletions(-) diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java b/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java index 2f0a7fdff..3bccdb2a3 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java @@ -162,13 +162,7 @@ public void commit(Xid xid, boolean onePhase) throws XAException { xidStateMap.compute( xid, (k, cpoXaState) -> { - if (cpoXaState == null) - throw new RuntimeException( - CpoXaError.createXAException(CpoXaError.XAER_NOTA, "Unknown XID")); - if (cpoXaState.getAssociation() != CpoXaState.XA_UNASSOCIATED) - throw new RuntimeException( - CpoXaError.createXAException( - CpoXaError.XAER_PROTO, "Commit can only be called on an unassociated XID")); + checkXidAndUnassociated("Commit", (CpoXaState) cpoXaState); try { if (onePhase) { if (!cpoXaState.isSuccess()) { @@ -183,10 +177,10 @@ public void commit(Xid xid, boolean onePhase) throws XAException { } commitResource((T) cpoXaState.getResource()); cpoXaState.setPrepared(false); + return cpoXaState; } catch (XAException e) { throw new RuntimeException(e); } - return cpoXaState; }); } catch (RuntimeException e) { if (e.getCause() instanceof XAException) throw (XAException) e.getCause(); @@ -315,13 +309,7 @@ public int prepare(Xid xid) throws XAException { xidStateMap.compute( xid, (k, cpoXaState) -> { - if (cpoXaState == null) - throw new RuntimeException( - CpoXaError.createXAException(CpoXaError.XAER_NOTA, "Unknown XID")); - if (cpoXaState.getAssociation() != CpoXaState.XA_UNASSOCIATED) - throw new RuntimeException( - CpoXaError.createXAException( - CpoXaError.XAER_PROTO, "Prepare can only be called on an unassociated XID")); + checkXidAndUnassociated("Prepare", (CpoXaState) cpoXaState); try { if (!cpoXaState.isSuccess()) { rollbackResource((T) cpoXaState.getResource()); @@ -334,11 +322,10 @@ public int prepare(Xid xid) throws XAException { } prepareResource((T) cpoXaState.getResource()); cpoXaState.setPrepared(true); + return cpoXaState; } catch (XAException e) { throw new RuntimeException(e); } - - return cpoXaState; }); } catch (RuntimeException e) { if (e.getCause() instanceof XAException) throw (XAException) e.getCause(); @@ -391,22 +378,16 @@ public void rollback(Xid xid) throws XAException { xidStateMap.compute( xid, (k, cpoXaState) -> { - if (cpoXaState == null) - throw new RuntimeException( - CpoXaError.createXAException(CpoXaError.XAER_NOTA, "Unknown XID")); - if (cpoXaState.getAssociation() != CpoXaState.XA_UNASSOCIATED) - throw new RuntimeException( - CpoXaError.createXAException( - CpoXaError.XAER_PROTO, "Rollback can only be called on an unassociated XID")); + checkXidAndUnassociated("Rollback", (CpoXaState) cpoXaState); try { rollbackResource((T) cpoXaState.getResource()); cpoXaState.setPrepared(false); cpoXaState.setSuccess(true); + return cpoXaState; } catch (XAException e) { throw new RuntimeException(e); } - return cpoXaState; }); } catch (RuntimeException e) { @@ -520,4 +501,13 @@ private ConcurrentHashMap> getXidStateMap() { return cpoXaResourceStateMap.computeIfAbsent( this.getClass().getName(), (k) -> new ConcurrentHashMap<>()); } + + private void checkXidAndUnassociated(String action, CpoXaState cpoXaState) { + if (cpoXaState == null) + throw new RuntimeException(CpoXaError.createXAException(CpoXaError.XAER_NOTA, "Unknown XID")); + if (cpoXaState.getAssociation() != CpoXaState.XA_UNASSOCIATED) + throw new RuntimeException( + CpoXaError.createXAException( + CpoXaError.XAER_PROTO, action + " can only be called on an unassociated XID")); + } } diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java index 96948a1cd..635bb94e8 100644 --- a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java @@ -71,6 +71,21 @@ public CallableStatementCpoData( this.jcsf = jcsf; } + @Override + public Object transformOut(Object attributeObject) throws CpoException { + Object retObj = attributeObject; + CpoTransform cpoTransform = getCpoAttribute().getCpoTransform(); + + if (cpoTransform != null) { + if (cpoTransform instanceof JdbcCpoTransform) { + retObj = ((JdbcCpoTransform) cpoTransform).transformOut(jcsf, attributeObject); + } else { + retObj = cpoTransform.transformOut(attributeObject); + } + } + return retObj; + } + @Override public Object invokeGetter() throws CpoException { Object javaObject = null; @@ -152,19 +167,4 @@ public void invokeSetter(Object instanceObject) throws CpoException { + ExceptionHelper.getLocalizedMessage(e)); } } - - @Override - public Object transformOut(Object attributeObject) throws CpoException { - Object retObj = attributeObject; - CpoTransform cpoTransform = getCpoAttribute().getCpoTransform(); - - if (cpoTransform != null) { - if (cpoTransform instanceof JdbcCpoTransform) { - retObj = ((JdbcCpoTransform) cpoTransform).transformOut(jcsf, attributeObject); - } else { - retObj = cpoTransform.transformOut(attributeObject); - } - } - return retObj; - } } diff --git a/pom.xml b/pom.xml index b65200cdd..6f4eaa3dc 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 75 + 70 **/*.java From 7c53629fd52c5e91e34619838bd8086a6d269f2b Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 15:45:06 -0500 Subject: [PATCH 04/10] remove dupe code to 65 tokens on CPD. --- .../cpo/meta/bean/CpoFunctionGroupBean.java | 42 +++---------------- pom.xml | 2 +- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java index 0d136e82c..64d243c9f 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionGroupBean.java @@ -22,38 +22,15 @@ * ]] */ -public class CpoFunctionGroupBean implements java.io.Serializable { - - private static final long serialVersionUID = 1L; +public class CpoFunctionGroupBean extends CpoClassBean { /* * Properties */ - private String name; private String type; - private String description; public CpoFunctionGroupBean() {} - /* - * Getters and Setters - */ - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public String getType() { return type; } @@ -65,19 +42,16 @@ public void setType(String type) { @Override public int hashCode() { int result = 0; - result = 31 * result + getClass().getName().hashCode(); - result = 31 * result + (getName() != null ? getName().hashCode() : 0); + result = 31 * result + super.hashCode(); result = 31 * result + (getType() != null ? getType().hashCode() : 0); - result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0); return result; } @Override public String toString() { StringBuilder str = new StringBuilder(); - str.append("name = " + getName() + "\n"); + str.append(super.toString()); str.append("type = " + getType() + "\n"); - str.append("description = " + getDescription() + "\n"); return str.toString(); } @@ -89,14 +63,8 @@ public boolean equals(Object o) { CpoFunctionGroupBean that = (CpoFunctionGroupBean) o; - if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) - return false; - - if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) - return false; + if (!super.equals(that)) return false; - return getDescription() != null - ? getDescription().equals(that.getDescription()) - : that.getDescription() == null; + return getType() != null ? getType().equals(that.getType()) : that.getType() == null; } } diff --git a/pom.xml b/pom.xml index 6f4eaa3dc..c7fd43a1e 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 70 + 65 **/*.java From d72da22426b9a469d2b4aaed352c52f4cd515699 Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 15:45:30 -0500 Subject: [PATCH 05/10] remove dupe code to 65 tokens on CPD. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c7fd43a1e..f3f382fce 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 65 + 60 **/*.java From 6d097b99be54d813e24f1967c388d483c1e8a39b Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 16:43:58 -0500 Subject: [PATCH 06/10] remove dupe code to 60 tokens on CPD. --- .../CassandraMetaXmlObjectExporter.java | 2 +- .../synchronoss/cpo/CpoStatementFactory.java | 39 +------- .../cpo/exporter/AbstractMetaVisitor.java | 11 +++ .../cpo/exporter/CpoClassSourceGenerator.java | 5 +- .../exporter/CpoInterfaceSourceGenerator.java | 14 +-- .../CpoLegacyClassSourceGenerator.java | 11 +-- .../cpo/meta/AbstractCpoMetaAdapter.java | 2 +- .../cpo/meta/bean/CpoArgumentBean.java | 89 ------------------- .../cpo/meta/bean/CpoAttributeBean.java | 52 +++++------ .../cpo/meta/bean/CpoFunctionBean.java | 16 ++-- .../cpo/meta/domain/CpoArgument.java | 6 +- .../cpo/parser/BoundExpressionParser.java | 48 +++++----- .../jdbc/JdbcCallableStatementFactory.java | 5 +- .../synchronoss/cpo/jdbc/JdbcCpoAdapter.java | 4 +- .../exporter/JdbcMetaXmlObjectExporter.java | 2 +- 15 files changed, 91 insertions(+), 215 deletions(-) delete mode 100644 cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java diff --git a/cpo-cassandra/src/main/java/org/synchronoss/cpo/cassandra/exporter/CassandraMetaXmlObjectExporter.java b/cpo-cassandra/src/main/java/org/synchronoss/cpo/cassandra/exporter/CassandraMetaXmlObjectExporter.java index 5fd2c5383..187c53ca4 100644 --- a/cpo-cassandra/src/main/java/org/synchronoss/cpo/cassandra/exporter/CassandraMetaXmlObjectExporter.java +++ b/cpo-cassandra/src/main/java/org/synchronoss/cpo/cassandra/exporter/CassandraMetaXmlObjectExporter.java @@ -103,7 +103,7 @@ public void visit(CpoArgument cpoArgument) { // ctCassandraArgument CtCassandraArgument ctCassandraArgument = CtCassandraArgument.Factory.newInstance(); - ctCassandraArgument.setAttributeName(cpoArgument.getAttributeName()); + ctCassandraArgument.setAttributeName(cpoArgument.getName()); if (cpoArgument.getDescription() != null && cpoArgument.getDescription().length() > 0) { ctCassandraArgument.setDescription(cpoArgument.getDescription()); diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/CpoStatementFactory.java b/cpo-core/src/main/java/org/synchronoss/cpo/CpoStatementFactory.java index 514bf3bd4..dc6045a64 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/CpoStatementFactory.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/CpoStatementFactory.java @@ -22,12 +22,10 @@ * ]] */ -import java.io.StringReader; import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.Map.Entry; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.synchronoss.cpo.helper.ExceptionHelper; import org.synchronoss.cpo.meta.MethodMapEntry; import org.synchronoss.cpo.meta.MethodMapper; @@ -35,6 +33,7 @@ import org.synchronoss.cpo.meta.domain.CpoAttribute; import org.synchronoss.cpo.meta.domain.CpoClass; import org.synchronoss.cpo.meta.domain.CpoFunction; +import org.synchronoss.cpo.parser.BoundExpressionParser; /** * JdbcPreparedStatementFactory is the object that encapsulates the creation of the actual @@ -47,9 +46,6 @@ public abstract class CpoStatementFactory implements CpoReleasable { /** Version Id for this class. */ private static final long serialVersionUID = 1L; - /** DOCUMENT ME! */ - private static final Logger logger = LoggerFactory.getLogger(CpoStatementFactory.class); - private Logger localLogger = null; private List releasables = new ArrayList<>(); @@ -201,7 +197,9 @@ private StringBuilder replaceMarker( while ((attrOffset = source.indexOf(marker, fromIndex)) != -1) { source.replace(attrOffset, attrOffset + mLength, replace); fromIndex = attrOffset + rLength; - bindValues.addAll(countBindMarkers(source.substring(0, attrOffset)), jwbBindValues); + bindValues.addAll( + BoundExpressionParser.getBindMarkerIndexes(source.substring(0, attrOffset)).size(), + jwbBindValues); } } // OUT.debug("ending string <"+source.toString()+">"); @@ -209,35 +207,6 @@ private StringBuilder replaceMarker( return source; } - private int countBindMarkers(String source) { - StringReader reader; - int rc; - int qMarks = 0; - boolean inDoubleQuotes = false; - boolean inSingleQuotes = false; - - if (source != null) { - reader = new StringReader(source); - - try { - do { - rc = reader.read(); - if (((char) rc) == '\'') { - inSingleQuotes = !inSingleQuotes; - } else if (((char) rc) == '"') { - inDoubleQuotes = !inDoubleQuotes; - } else if (!inSingleQuotes && !inDoubleQuotes && ((char) rc) == '?') { - qMarks++; - } - } while (rc != -1); - } catch (Exception e) { - logger.error("error counting bind markers"); - } - } - - return qMarks; - } - /** * Adds a releasable object to this object. The release method on the releasable will be called * when the PreparedStatement is executed. diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java index df7db2d41..9d04faf6a 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java @@ -24,6 +24,7 @@ import org.synchronoss.cpo.MetaVisitor; import org.synchronoss.cpo.meta.domain.CpoArgument; +import org.synchronoss.cpo.meta.domain.CpoClass; import org.synchronoss.cpo.meta.domain.CpoFunction; import org.synchronoss.cpo.meta.domain.CpoFunctionGroup; @@ -35,6 +36,16 @@ public abstract class AbstractMetaVisitor implements MetaVisitor { protected StringBuilder functionGroupStatics = new StringBuilder(); protected StringBuilder gettersSetters = new StringBuilder(); + protected String buildPackageName(CpoClass cpoClass) { + StringBuilder header = new StringBuilder(); + // generate class header + if (cpoClass.getName().lastIndexOf(".") != -1) { + String packageName = cpoClass.getName().substring(0, cpoClass.getName().lastIndexOf(".")); + header.append("package ").append(packageName).append(";\n\n"); + } + return header.toString(); + } + protected String buildGetterName(String attName) { // the getter name is get concatenated with the camel case of the attribute name String getterName; diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java index aece98f7a..d5858817d 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java @@ -152,10 +152,7 @@ public void visit(CpoClass cpoClass) { String interfaceName = generateInterfaceName(cpoClass); // generate class header - if (cpoClass.getName().lastIndexOf(".") != -1) { - String packageName = cpoClass.getName().substring(0, cpoClass.getName().lastIndexOf(".")); - header.append("package " + packageName + ";\n\n"); - } + header.append(buildPackageName(cpoClass)); // generate class declaration header.append( diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoInterfaceSourceGenerator.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoInterfaceSourceGenerator.java index 931a4aa2d..04e50a360 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoInterfaceSourceGenerator.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoInterfaceSourceGenerator.java @@ -66,14 +66,11 @@ public String getSourceCode() { source.append(" * This interface auto-generated by " + this.getClass().getName() + "\n"); source.append(" */\n"); source.append(header); - source.append("\n"); - source.append(" /* Attribute name statics */\n"); + source.append("\n /* Attribute name statics */\n"); source.append(attributeStatics); - source.append("\n"); - source.append(" /* Function group statics */\n"); + source.append("\n /* Function group statics */\n"); source.append(functionGroupStatics); - source.append("\n"); - source.append(" /* Getters and Setters */\n"); + source.append("\n /* Getters and Setters */\n"); source.append(gettersSetters); source.append(footer); @@ -100,10 +97,7 @@ public void visit(CpoClass cpoClass) { interfaceName = generateInterfaceName(cpoClass); // generate class header - if (cpoClass.getName().lastIndexOf(".") != -1) { - String packageName = cpoClass.getName().substring(0, cpoClass.getName().lastIndexOf(".")); - header.append("package " + packageName + ";\n\n"); - } + header.append(buildPackageName(cpoClass)); // generate interface declaration header.append("public interface " + interfaceName + " {\n"); diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java index a3600c291..2ec15d320 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java @@ -51,11 +51,9 @@ public String getSourceCode() { source.append(" * This class auto-generated by " + this.getClass().getName() + "\n"); source.append(" */\n"); source.append(header); - source.append("\n"); - source.append(" /* Attribute name statics */\n"); + source.append("\n /* Attribute name statics */\n"); source.append(attributeStatics); - source.append("\n"); - source.append(" /* Function group statics */\n"); + source.append("\n /* Function group statics */\n"); source.append(functionGroupStatics); appendClassBody(source); @@ -77,10 +75,7 @@ public void visit(CpoClass cpoClass) { className = generateClassName(cpoClass); // generate class header - if (cpoClass.getName().lastIndexOf(".") != -1) { - String packageName = cpoClass.getName().substring(0, cpoClass.getName().lastIndexOf(".")); - header.append("package " + packageName + ";\n\n"); - } + header.append(buildPackageName(cpoClass)); // generate class declaration header.append("public class " + className + " implements java.io.Serializable {\n"); diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/AbstractCpoMetaAdapter.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/AbstractCpoMetaAdapter.java index 148de355d..367d47a5c 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/AbstractCpoMetaAdapter.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/AbstractCpoMetaAdapter.java @@ -260,7 +260,7 @@ protected void loadCpoFunction(CpoFunction cpoFunction, CtFunction ctFunction) { } protected void loadCpoArgument(CpoArgument cpoArgument, CtArgument ctArgument) { - cpoArgument.setAttributeName(ctArgument.getAttributeName()); + cpoArgument.setName(ctArgument.getAttributeName()); cpoArgument.setDescription(ctArgument.getDescription()); cpoArgument.setAttribute(currentClass.getAttributeJava(ctArgument.getAttributeName())); diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java deleted file mode 100644 index 93bf8ad2f..000000000 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.synchronoss.cpo.meta.bean; - -/*- - * [[ - * core - * == - * Copyright (C) 2003 - 2025 David E. Berry - * == - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * ]] - */ - -public class CpoArgumentBean implements java.io.Serializable { - - private static final long serialVersionUID = 1L; - - /* - * Properties - */ - private String attributeName; - private String description; - - public CpoArgumentBean() {} - - /* - * Getters and Setters - */ - public String getAttributeName() { - return attributeName; - } - - public void setAttributeName(String attributeName) { - this.attributeName = attributeName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @Override - public int hashCode() { - int result = 0; - result = 31 * result + getClass().getName().hashCode(); - result = 31 * result + (getAttributeName() != null ? getAttributeName().hashCode() : 0); - result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0); - return result; - } - - @Override - public String toString() { - StringBuilder str = new StringBuilder(); - str.append("attributeName = " + getAttributeName() + "\n"); - str.append("description = " + getDescription() + "\n"); - return str.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - CpoArgumentBean that = (CpoArgumentBean) o; - - if (getAttributeName() != null - ? !getAttributeName().equals(that.getAttributeName()) - : that.getAttributeName() != null) return false; - - return getDescription() != null - ? getDescription().equals(that.getDescription()) - : that.getDescription() == null; - } -} diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoAttributeBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoAttributeBean.java index 934d9970c..c4e624cf4 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoAttributeBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoAttributeBean.java @@ -89,32 +89,6 @@ public void setTransformClassName(String transformClassName) { this.transformClassName = transformClassName; } - @Override - public int hashCode() { - int result = 0; - result = 31 * result + getClass().getName().hashCode(); - result = 31 * result + (getJavaName() != null ? getJavaName().hashCode() : 0); - result = 31 * result + (getJavaType() != null ? getJavaType().hashCode() : 0); - result = 31 * result + (getDataName() != null ? getDataName().hashCode() : 0); - result = 31 * result + (getDataType() != null ? getDataType().hashCode() : 0); - result = - 31 * result + (getTransformClassName() != null ? getTransformClassName().hashCode() : 0); - result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0); - return result; - } - - @Override - public String toString() { - StringBuilder str = new StringBuilder(); - str.append("javaName = " + getJavaName() + "\n"); - str.append("javaType = " + getJavaType() + "\n"); - str.append("dataName = " + getDataName() + "\n"); - str.append("dataType = " + getDataType() + "\n"); - str.append("transformClass = " + getTransformClassName() + "\n"); - str.append("description = " + getDescription() + "\n"); - return str.toString(); - } - @Override public boolean equals(Object o) { if (this == o) return true; @@ -147,4 +121,30 @@ public boolean equals(Object o) { ? getDescription().equals(that.getDescription()) : that.getDescription() == null; } + + @Override + public int hashCode() { + int result = 0; + result = 31 * result + getClass().getName().hashCode(); + result = 31 * result + (getJavaName() != null ? getJavaName().hashCode() : 0); + result = 31 * result + (getJavaType() != null ? getJavaType().hashCode() : 0); + result = 31 * result + (getDataName() != null ? getDataName().hashCode() : 0); + result = 31 * result + (getDataType() != null ? getDataType().hashCode() : 0); + result = + 31 * result + (getTransformClassName() != null ? getTransformClassName().hashCode() : 0); + result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0); + return result; + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + str.append("javaName = " + getJavaName() + "\n"); + str.append("javaType = " + getJavaType() + "\n"); + str.append("dataName = " + getDataName() + "\n"); + str.append("dataType = " + getDataType() + "\n"); + str.append("transformClass = " + getTransformClassName() + "\n"); + str.append("description = " + getDescription() + "\n"); + return str.toString(); + } } diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionBean.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionBean.java index a3efeeef4..8233c01e5 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionBean.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoFunctionBean.java @@ -62,6 +62,14 @@ public void setExpression(String expression) { this.expression = expression; } + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + str.append("expression = " + getExpression() + "\n"); + str.append("description = " + getDescription() + "\n"); + return str.toString(); + } + @Override public int hashCode() { int result = 0; @@ -71,14 +79,6 @@ public int hashCode() { return result; } - @Override - public String toString() { - StringBuilder str = new StringBuilder(); - str.append("expression = " + getExpression() + "\n"); - str.append("description = " + getDescription() + "\n"); - return str.toString(); - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/meta/domain/CpoArgument.java b/cpo-core/src/main/java/org/synchronoss/cpo/meta/domain/CpoArgument.java index 8679b33de..dcd6d51cc 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/domain/CpoArgument.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/meta/domain/CpoArgument.java @@ -22,9 +22,9 @@ * ]] */ -import org.synchronoss.cpo.meta.bean.CpoArgumentBean; +import org.synchronoss.cpo.meta.bean.CpoClassBean; -public class CpoArgument extends CpoArgumentBean { +public class CpoArgument extends CpoClassBean { private static final long serialVersionUID = 1L; @@ -38,7 +38,7 @@ public CpoAttribute getAttribute() { public void setAttribute(CpoAttribute attribute) { this.attribute = attribute; - if (attribute != null) setAttributeName(attribute.getJavaName()); + if (attribute != null) setName(attribute.getJavaName()); } @Override diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/parser/BoundExpressionParser.java b/cpo-core/src/main/java/org/synchronoss/cpo/parser/BoundExpressionParser.java index 5d85266f0..1cc0cb1e0 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/parser/BoundExpressionParser.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/parser/BoundExpressionParser.java @@ -61,36 +61,36 @@ public void setExpression(String expression) { */ @Override public int countArguments() { - return getArgumentIndexes().size(); + return getBindMarkerIndexes(expression).size(); } - private Collection getArgumentIndexes() { + public static Collection getBindMarkerIndexes(String source) { Collection indexes = new ArrayList<>(); - if (expression != null) { - StringReader reader = new StringReader(expression); + if (source == null || source.length() == 0) return indexes; - try { + StringReader reader = new StringReader(source); - int idx = 0; - int rc = -1; - boolean inDoubleQuotes = false; - boolean inSingleQuotes = false; + try { - do { - rc = reader.read(); - if (((char) rc) == '\'') { - inSingleQuotes = !inSingleQuotes; - } else if (((char) rc) == '"') { - inDoubleQuotes = !inDoubleQuotes; - } else if (!inSingleQuotes && !inDoubleQuotes && ((char) rc) == '?') { - indexes.add(idx); - } - idx++; - } while (rc != -1); - } catch (Exception e) { - logger.error("error counting bind markers"); - } + int idx = 0; + int rc; + boolean inDoubleQuotes = false; + boolean inSingleQuotes = false; + + do { + rc = reader.read(); + if (((char) rc) == '\'') { + inSingleQuotes = !inSingleQuotes; + } else if (((char) rc) == '"') { + inDoubleQuotes = !inDoubleQuotes; + } else if (!inSingleQuotes && !inDoubleQuotes && ((char) rc) == '?') { + indexes.add(idx); + } + idx++; + } while (rc != -1); + } catch (Exception e) { + logger.error("error counting bind markers"); } return indexes; } @@ -182,7 +182,7 @@ public List parse() throws ParseException { // so we'll have to move left to right from the ? looking for the field name int startIdx = 0; - Collection indexes = getArgumentIndexes(); + Collection indexes = getBindMarkerIndexes(expression); for (int qIdx : indexes) { String chunk = expression.substring(startIdx, qIdx); diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcCallableStatementFactory.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcCallableStatementFactory.java index 60bd2d82e..8a54d2b60 100644 --- a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcCallableStatementFactory.java +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcCallableStatementFactory.java @@ -100,12 +100,11 @@ public JdbcCallableStatementFactory( // The function will not know the type of the attribute on the result object, so look it // up now if (attribute == null) { - attribute = - (JdbcCpoAttribute) resultClass.getAttributeJava(argument.getAttributeName()); + attribute = (JdbcCpoAttribute) resultClass.getAttributeJava(argument.getName()); if (attribute == null) { throw new CpoException( "Attribute <" - + argument.getAttributeName() + + argument.getName() + "> does not exist on class <" + resultClass.getName() + ">"); diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcCpoAdapter.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcCpoAdapter.java index 605c0739d..af8bf12b4 100644 --- a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcCpoAdapter.java +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcCpoAdapter.java @@ -587,11 +587,11 @@ protected T processExecuteGroup(String groupName, C criteria, T result, C JdbcCpoAttribute jdbcAttribute = jdbcArgument.getAttribute(); if (jdbcAttribute == null) { jdbcAttribute = - (JdbcCpoAttribute) resultClass.getAttributeJava(jdbcArgument.getAttributeName()); + (JdbcCpoAttribute) resultClass.getAttributeJava(jdbcArgument.getName()); if (jdbcAttribute == null) { throw new CpoException( "Attribute <" - + jdbcArgument.getAttributeName() + + jdbcArgument.getName() + "> does not exist on class <" + resultClass.getName() + ">"); diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/exporter/JdbcMetaXmlObjectExporter.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/exporter/JdbcMetaXmlObjectExporter.java index 376e8e88f..575237789 100644 --- a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/exporter/JdbcMetaXmlObjectExporter.java +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/exporter/JdbcMetaXmlObjectExporter.java @@ -114,7 +114,7 @@ public void visit(CpoArgument cpoArgument) { // CtJdbcArgument CtJdbcArgument ctJdbcArgument = CtJdbcArgument.Factory.newInstance(); - ctJdbcArgument.setAttributeName(jdbcArgument.getAttributeName()); + ctJdbcArgument.setAttributeName(jdbcArgument.getName()); if (jdbcArgument.getDescription() != null && jdbcArgument.getDescription().length() > 0) { ctJdbcArgument.setDescription(jdbcArgument.getDescription()); From 0ed873256fd701380a5cabaf1113c65b3bf802f6 Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 16:44:14 -0500 Subject: [PATCH 07/10] remove dupe code to 60 tokens on CPD. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f3f382fce..27e5636c1 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 60 + 55 **/*.java From da51edaded50b7b06b788e4082a6bb65dc23e4e8 Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 17:48:40 -0500 Subject: [PATCH 08/10] remove dupe code to 55 tokens on CPD. --- .../cpo/exporter/CpoClassSourceGenerator.java | 26 ++++---- .../CpoLegacyClassSourceGenerator.java | 4 -- .../cpo/jdbc/AbstractStatementCpoData.java | 59 +++++++++++++++++++ .../cpo/jdbc/CallableStatementCpoData.java | 25 +------- .../jdbc/JdbcPreparedStatementCpoData.java | 39 +++--------- 5 files changed, 84 insertions(+), 69 deletions(-) create mode 100644 cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/AbstractStatementCpoData.java diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java index d5858817d..7d5671ac2 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoClassSourceGenerator.java @@ -71,6 +71,19 @@ public String getClassName() { return className; } + public String getSourceCode() { + StringBuilder source = new StringBuilder(); + + source.append("/* \n"); + source.append(" * This class auto-generated by " + this.getClass().getName() + "\n"); + source.append(" */\n"); + source.append(header); + + appendClassBody(source); + + return source.toString(); + } + protected void appendClassBody(StringBuilder source) { source.append("\n"); source.append(" /* Properties */\n"); @@ -115,19 +128,6 @@ protected void appendClassBody(StringBuilder source) { source.append("\n"); } - public String getSourceCode() { - StringBuilder source = new StringBuilder(); - - source.append("/* \n"); - source.append(" * This class auto-generated by " + this.getClass().getName() + "\n"); - source.append(" */\n"); - source.append(header); - - appendClassBody(source); - - return source.toString(); - } - /** The cpoClass name will be used for the name of the interface */ protected String generateInterfaceName(CpoClass cpoClass) { String className = cpoClass.getName(); diff --git a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java index 2ec15d320..1c6e872bd 100644 --- a/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/CpoLegacyClassSourceGenerator.java @@ -40,10 +40,6 @@ public CpoLegacyClassSourceGenerator(CpoMetaDescriptor metaDescriptor) { super(metaDescriptor); } - public String getClassName() { - return className; - } - public String getSourceCode() { StringBuilder source = new StringBuilder(); diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/AbstractStatementCpoData.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/AbstractStatementCpoData.java new file mode 100644 index 000000000..06e01a281 --- /dev/null +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/AbstractStatementCpoData.java @@ -0,0 +1,59 @@ +package org.synchronoss.cpo.jdbc; + +/*- + * [[ + * jdbc + * == + * Copyright (C) 2003 - 2025 David E. Berry + * == + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * ]] + */ + +import org.synchronoss.cpo.CpoException; +import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapEntry; +import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapper; +import org.synchronoss.cpo.meta.AbstractBindableCpoData; +import org.synchronoss.cpo.meta.domain.CpoAttribute; + +public abstract class AbstractStatementCpoData extends AbstractBindableCpoData { + + public AbstractStatementCpoData(CpoAttribute cpoAttribute, int index) { + super(cpoAttribute, index); + } + + protected JdbcMethodMapEntry getJdbcMethodMapEntry(Object instanceObject) + throws CpoException { + JdbcMethodMapEntry methodMapEntry = + JdbcMethodMapper.getJavaSqlMethod(getDataSetterParamType()); + if (methodMapEntry == null) { + if (Object.class.isAssignableFrom(getDataSetterParamType())) { + methodMapEntry = JdbcMethodMapper.getJavaSqlMethod(Object.class); + } + if (methodMapEntry == null) { + throw new CpoException( + "Error Retrieving Jdbc Method for type: " + getDataSetterParamType().getName()); + } + } + switch (methodMapEntry.getMethodType()) { + case JdbcMethodMapEntry.METHOD_TYPE_BASIC: + case JdbcMethodMapEntry.METHOD_TYPE_OBJECT: + case JdbcMethodMapEntry.METHOD_TYPE_STREAM: + case JdbcMethodMapEntry.METHOD_TYPE_READER: + default: + return methodMapEntry; + } + } +} diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java index 635bb94e8..563b2c7af 100644 --- a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/CallableStatementCpoData.java @@ -30,7 +30,6 @@ import org.synchronoss.cpo.helper.ExceptionHelper; import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapEntry; import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapper; -import org.synchronoss.cpo.meta.AbstractBindableCpoData; import org.synchronoss.cpo.meta.domain.CpoAttribute; import org.synchronoss.cpo.transform.CpoTransform; import org.synchronoss.cpo.transform.jdbc.JdbcCpoTransform; @@ -40,7 +39,7 @@ * * @author dberry */ -public class CallableStatementCpoData extends AbstractBindableCpoData { +public class CallableStatementCpoData extends AbstractStatementCpoData { private static final Logger logger = LoggerFactory.getLogger(CallableStatementCpoData.class); private CallableStatement cs = null; @@ -137,28 +136,10 @@ public void invokeSetter(Object instanceObject) throws CpoException { instanceObject == null ? logger : LoggerFactory.getLogger(instanceObject.getClass()); CpoAttribute cpoAttribute = getCpoAttribute(); Object param = transformOut(cpoAttribute.invokeGetter(instanceObject)); - JdbcMethodMapEntry jdbcMethodMapEntry = - JdbcMethodMapper.getJavaSqlMethod(getDataSetterParamType()); - if (jdbcMethodMapEntry == null) { - if (Object.class.isAssignableFrom(getDataSetterParamType())) { - jdbcMethodMapEntry = JdbcMethodMapper.getJavaSqlMethod(Object.class); - } - if (jdbcMethodMapEntry == null) { - throw new CpoException( - "Error Retrieving Jdbc Method for type: " + getDataSetterParamType().getName()); - } - } localLogger.info(cpoAttribute.getDataName() + "=" + param); + JdbcMethodMapEntry jdbcMethodMapEntry = getJdbcMethodMapEntry(instanceObject); try { - switch (jdbcMethodMapEntry.getMethodType()) { - case JdbcMethodMapEntry.METHOD_TYPE_BASIC: - case JdbcMethodMapEntry.METHOD_TYPE_OBJECT: - case JdbcMethodMapEntry.METHOD_TYPE_STREAM: - case JdbcMethodMapEntry.METHOD_TYPE_READER: - default: - jdbcMethodMapEntry.getCsSetter().invoke(jcsf.getCallableStatement(), getIndex(), param); - break; - } + jdbcMethodMapEntry.getCsSetter().invoke(jcsf.getCallableStatement(), getIndex(), param); } catch (Exception e) { throw new CpoException( "Error Invoking Jdbc Method: " diff --git a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java index a84169d37..33f6ce552 100644 --- a/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java +++ b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java @@ -27,8 +27,6 @@ import org.synchronoss.cpo.CpoException; import org.synchronoss.cpo.helper.ExceptionHelper; import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapEntry; -import org.synchronoss.cpo.jdbc.meta.JdbcMethodMapper; -import org.synchronoss.cpo.meta.AbstractBindableCpoData; import org.synchronoss.cpo.meta.domain.CpoAttribute; import org.synchronoss.cpo.transform.CpoTransform; import org.synchronoss.cpo.transform.jdbc.JdbcCpoTransform; @@ -38,7 +36,7 @@ * * @author dberry */ -public class JdbcPreparedStatementCpoData extends AbstractBindableCpoData { +public class JdbcPreparedStatementCpoData extends AbstractStatementCpoData { private static final Logger logger = LoggerFactory.getLogger(JdbcPreparedStatementCpoData.class); private JdbcPreparedStatementFactory cpoStatementFactory = null; @@ -58,40 +56,21 @@ public JdbcPreparedStatementCpoData( @Override public void invokeSetter(Object instanceObject) throws CpoException { + JdbcMethodMapEntry methodMapEntry = getJdbcMethodMapEntry(instanceObject); Logger localLogger = instanceObject == null ? logger : LoggerFactory.getLogger(instanceObject.getClass()); - CpoAttribute cpoAttribute = getCpoAttribute(); - Object param = transformOut(cpoAttribute.invokeGetter(instanceObject)); - JdbcMethodMapEntry methodMapEntry = - JdbcMethodMapper.getJavaSqlMethod(getDataSetterParamType()); - if (methodMapEntry == null) { - if (Object.class.isAssignableFrom(getDataSetterParamType())) { - methodMapEntry = JdbcMethodMapper.getJavaSqlMethod(Object.class); - } - if (methodMapEntry == null) { - throw new CpoException( - "Error Retrieving Jdbc Method for type: " + getDataSetterParamType().getName()); - } - } - localLogger.debug(cpoAttribute.getDataName() + "=" + param); try { - switch (methodMapEntry.getMethodType()) { - case JdbcMethodMapEntry.METHOD_TYPE_BASIC: - case JdbcMethodMapEntry.METHOD_TYPE_OBJECT: - case JdbcMethodMapEntry.METHOD_TYPE_STREAM: - case JdbcMethodMapEntry.METHOD_TYPE_READER: - default: - methodMapEntry - .getBsSetter() - .invoke(cpoStatementFactory.getPreparedStatement(), getIndex(), param); - break; - } + Object param = transformOut(getCpoAttribute().invokeGetter(instanceObject)); + localLogger.debug(getCpoAttribute().getDataName() + "=" + param); + methodMapEntry + .getBsSetter() + .invoke(cpoStatementFactory.getPreparedStatement(), getIndex(), param); } catch (Exception e) { throw new CpoException( "Error Invoking Jdbc Method: " - + cpoAttribute.getDataName() + + getCpoAttribute().getDataName() + ":" - + cpoAttribute.getJavaName() + + getCpoAttribute().getJavaName() + ":" + methodMapEntry.getBsSetter().getName() + ":" From a6d83907986b1225e568dd9fad60388118c6f904 Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 17:50:10 -0500 Subject: [PATCH 09/10] remove dupe code to 55 tokens on CPD. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 27e5636c1..b02c317e7 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 55 + 50 **/*.java From bd61f95879d9d2ff777fadd9372e56ccf55c24a2 Mon Sep 17 00:00:00 2001 From: berryware Date: Thu, 4 Dec 2025 18:39:58 -0500 Subject: [PATCH 10/10] remove dupe code to 55 tokens on CPD. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b02c317e7..27e5636c1 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 50 + 55 **/*.java