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/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/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 new file mode 100644 index 000000000..9d04faf6a --- /dev/null +++ b/cpo-core/src/main/java/org/synchronoss/cpo/exporter/AbstractMetaVisitor.java @@ -0,0 +1,113 @@ +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.CpoClass; +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 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; + 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..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 @@ -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(); @@ -87,6 +78,13 @@ public String getSourceCode() { 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"); source.append(properties); @@ -128,8 +126,6 @@ public String getSourceCode() { source.append(footer); source.append("\n"); - - return source.toString(); } /** The cpoClass name will be used for the name of the interface */ @@ -156,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( @@ -183,24 +176,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 +248,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..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 @@ -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) { @@ -76,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); @@ -110,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"); @@ -127,27 +111,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 +127,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..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(); @@ -51,53 +47,12 @@ 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); - 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(); } @@ -116,10 +71,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/jta/CpoBaseXaResource.java b/cpo-core/src/main/java/org/synchronoss/cpo/jta/CpoBaseXaResource.java index e62789eb0..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(); @@ -233,9 +227,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; @@ -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-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 c1913d6de..000000000 --- a/cpo-core/src/main/java/org/synchronoss/cpo/meta/bean/CpoArgumentBean.java +++ /dev/null @@ -1,97 +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() {} - - 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; - } - - /* - * 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; - 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(); - } -} 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..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 @@ -38,6 +38,9 @@ public class CpoAttributeBean implements java.io.Serializable { public CpoAttributeBean() {} + /* + * Getters and Setters + */ public String getDataName() { return dataName; } @@ -86,52 +89,37 @@ 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; - } + 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; - } + : that.getJavaName() != null) return false; + if (getJavaType() != null ? !getJavaType().equals(that.getJavaType()) - : that.getJavaType() != null) { - return false; - } + : that.getJavaType() != null) return false; + if (getDataName() != null ? !getDataName().equals(that.getDataName()) - : that.getDataName() != null) { - return false; - } + : that.getDataName() != null) return false; + if (getDataType() != null ? !getDataType().equals(that.getDataType()) - : that.getDataType() != null) { - return false; - } + : 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; + : that.getTransformClassName() != null) return false; + + return getDescription() != null + ? getDescription().equals(that.getDescription()) + : that.getDescription() == null; } @Override 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..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,29 +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; - } - if (getDescription() != null - ? !getDescription().equals(that.getDescription()) - : that.getDescription() != null) { - return false; - } - - return true; - } - @Override public int hashCode() { int result = 0; @@ -92,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..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 @@ -35,6 +35,9 @@ public class CpoFunctionBean implements java.io.Serializable { public CpoFunctionBean() {} + /* + * Getters and Setters + */ public String getName() { return name; } @@ -59,32 +62,12 @@ 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; + public String toString() { + StringBuilder str = new StringBuilder(); + str.append("expression = " + getExpression() + "\n"); + str.append("description = " + getDescription() + "\n"); + return str.toString(); } @Override @@ -97,10 +80,19 @@ public int hashCode() { } @Override - public String toString() { - StringBuilder str = new StringBuilder(); - str.append("expression = " + getExpression() + "\n"); - str.append("description = " + getDescription() + "\n"); - return str.toString(); + 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 bdb31cb54..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,35 +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() {} - 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; } @@ -59,51 +39,32 @@ 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; - } - if (getDescription() != null - ? !getDescription().equals(that.getDescription()) - : that.getDescription() != null) { - return false; - } - - return true; - } - @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(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + CpoFunctionGroupBean that = (CpoFunctionGroupBean) o; + + if (!super.equals(that)) return false; + + return getType() != null ? getType().equals(that.getType()) : that.getType() == null; + } } 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/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 24e1f0e44..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 @@ -22,19 +22,14 @@ * ]] */ -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; 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; @@ -44,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; @@ -75,6 +70,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; @@ -126,40 +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: - 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()); - break; - } + jdbcMethodMapEntry.getCsSetter().invoke(jcsf.getCallableStatement(), getIndex(), param); } catch (Exception e) { throw new CpoException( "Error Invoking Jdbc Method: " @@ -168,19 +148,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/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/JdbcPreparedStatementCpoData.java b/cpo-jdbc/src/main/java/org/synchronoss/cpo/jdbc/JdbcPreparedStatementCpoData.java index d68587a72..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 @@ -22,17 +22,11 @@ * ]] */ -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; -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; @@ -42,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; @@ -62,54 +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: - 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 - methodMapEntry - .getBsSetter() - .invoke( - cpoStatementFactory.getPreparedStatement(), getIndex(), ccar, ccar.getLength()); - 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() + ":" 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()); diff --git a/pom.xml b/pom.xml index 3b944744d..27e5636c1 100644 --- a/pom.xml +++ b/pom.xml @@ -401,7 +401,7 @@ java 21 - 20 + 55 **/*.java @@ -426,11 +426,12 @@ CPD - false + true cpd-check + compile