You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by jg...@apache.org on 2009/11/08 05:06:28 UTC
svn commit: r833819 [3/4] - in /ibatis/java/ibator/trunk/core/ibator-core:
doc/ src/main/java/org/apache/ibatis/ibator/generator/ibatis3/
src/main/java/org/apache/ibatis/ibator/generator/ibatis3/javamapper/
src/main/java/org/apache/ibatis/ibator/genera...
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/CountByExampleElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/CountByExampleElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/CountByExampleElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/CountByExampleElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class CountByExampleElementGenerator extends AbstractXmlElementGenerator {
+
+ public CountByExampleElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("select"); //$NON-NLS-1$
+
+ String fqjt = introspectedTable.getExampleType();
+
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getCountByExampleStatementId())); //$NON-NLS-1$
+ answer.addAttribute(new Attribute(
+ "parameterType", fqjt)); //$NON-NLS-1$
+ answer.addAttribute(new Attribute(
+ "resultType", "java.lang.Integer")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("select count(*) from "); //$NON-NLS-1$
+ sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+ answer.addElement(getExampleIncludeElement());
+
+ if (ibatorContext.getPlugins().sqlMapCountByExampleElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/DeleteByExampleElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/DeleteByExampleElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/DeleteByExampleElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/DeleteByExampleElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class DeleteByExampleElementGenerator extends AbstractXmlElementGenerator {
+
+ public DeleteByExampleElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$
+
+ String fqjt = introspectedTable.getExampleType();
+
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getDeleteByExampleStatementId())); //$NON-NLS-1$
+ answer.addAttribute(new Attribute(
+ "parameterType", fqjt)); //$NON-NLS-1$
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("delete from "); //$NON-NLS-1$
+ sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+ answer.addElement(getExampleIncludeElement());
+
+ if (ibatorContext.getPlugins().sqlMapDeleteByExampleElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/DeleteByPrimaryKeyElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/DeleteByPrimaryKeyElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/DeleteByPrimaryKeyElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/DeleteByPrimaryKeyElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class DeleteByPrimaryKeyElementGenerator extends AbstractXmlElementGenerator {
+
+ public DeleteByPrimaryKeyElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getDeleteByPrimaryKeyStatementId())); //$NON-NLS-1$
+ String parameterClass;
+ if (introspectedTable.getRules().generatePrimaryKeyClass()) {
+ parameterClass = introspectedTable.getPrimaryKeyType();
+ } else {
+ parameterClass = introspectedTable.getBaseRecordType();
+ }
+ answer.addAttribute(new Attribute("parameterType", //$NON-NLS-1$
+ parameterClass));
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("delete from "); //$NON-NLS-1$
+ sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ boolean and = false;
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
+ sb.setLength(0);
+ if (and) {
+ sb.append(" and "); //$NON-NLS-1$
+ } else {
+ sb.append("where "); //$NON-NLS-1$
+ and = true;
+ }
+
+ sb.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+ answer.addElement(new TextElement(sb.toString()));
+ }
+
+ if (ibatorContext.getPlugins().sqlMapDeleteByPrimaryKeyElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ExampleWhereClauseElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ExampleWhereClauseElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ExampleWhereClauseElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ExampleWhereClauseElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.internal.util.StringUtility;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+<where>
+ <foreach collection="oredCriteria" item="criteria" separator="or">
+ <if test="criteria.valid">
+ (
+ <foreach collection="criteria.criteria" item="criterion" separator="and">
+ <choose>
+ <when test="criterion.noValue">
+ ${criterion.condition}
+ </when>
+ <when test="criterion.singleValue">
+ ${criterion.condition} #{criterion.value}
+ </when>
+ <when test="criterion.betweenValue">
+ ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
+ </when>
+ <when test="criterion.listValue">
+ ${criterion.condition}
+ <foreach collection="criterion.value" item="listItem" open="(" close=")" separator=",">
+ #{listItem}
+ </foreach>
+ </when>
+ </choose>
+ </foreach>
+ )
+ </if>
+ </foreach>
+</where>
+ *
+ */
+public class ExampleWhereClauseElementGenerator extends AbstractXmlElementGenerator {
+
+ public ExampleWhereClauseElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute("id", introspectedTable.getExampleWhereClauseId())); //$NON-NLS-1$
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ XmlElement whereElement = new XmlElement("where"); //$NON-NLS-1$
+ answer.addElement(whereElement);
+
+ XmlElement outerForEachElement = new XmlElement("foreach");
+ outerForEachElement.addAttribute(new Attribute("collection", "oredCriteria"));
+ outerForEachElement.addAttribute(new Attribute("item", "criteria"));
+ outerForEachElement.addAttribute(new Attribute("separator", "or"));
+ whereElement.addElement(outerForEachElement);
+
+ XmlElement ifElement = new XmlElement("if");
+ ifElement.addAttribute(new Attribute("test", "criteria.valid"));
+ outerForEachElement.addElement(ifElement);
+
+ XmlElement trimElement = new XmlElement("trim");
+ trimElement.addAttribute(new Attribute("prefix", "("));
+ trimElement.addAttribute(new Attribute("suffix", ")"));
+ trimElement.addAttribute(new Attribute("prefixOverrides", "and"));
+
+ ifElement.addElement(trimElement);
+
+ trimElement.addElement(getMiddleForEachElement(null));
+
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
+ if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
+ trimElement.addElement(getMiddleForEachElement(introspectedColumn));
+ }
+ }
+
+ if (ibatorContext.getPlugins().sqlMapExampleWhereClauseElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+
+ private XmlElement getMiddleForEachElement(IntrospectedColumn introspectedColumn) {
+ StringBuilder sb = new StringBuilder();
+ String criteriaAttribute;
+ boolean typeHandled;
+ String typeHandlerString;
+ if (introspectedColumn == null) {
+ criteriaAttribute = "criteria.criteria";
+ typeHandled = false;
+ typeHandlerString = null;
+ } else {
+ sb.setLength(0);
+ sb.append("criteria."); //$NON-NLS-1$
+ sb.append(introspectedColumn.getJavaProperty());
+ sb.append("Criteria"); //$NON-NLS-1$
+ criteriaAttribute = sb.toString();
+
+ typeHandled = true;
+
+ sb.setLength(0);
+ sb.append(",typeHandler=");
+ sb.append(introspectedColumn.getTypeHandler());
+ typeHandlerString = sb.toString();
+ }
+
+ XmlElement middleForEachElement = new XmlElement("foreach");
+ middleForEachElement.addAttribute(new Attribute("collection", criteriaAttribute));
+ middleForEachElement.addAttribute(new Attribute("item", "criterion"));
+
+ XmlElement chooseElement = new XmlElement("choose");
+ middleForEachElement.addElement(chooseElement);
+
+ XmlElement when = new XmlElement("when");
+ when.addAttribute(new Attribute("test", "criterion.noValue"));
+ when.addElement(new TextElement("and ${criterion.condition}"));
+ chooseElement.addElement(when);
+
+ when = new XmlElement("when");
+ when.addAttribute(new Attribute("test", "criterion.singleValue"));
+ sb.setLength(0);
+ sb.append("and ${criterion.condition} #{criterion.value");
+ if (typeHandled) {
+ sb.append(typeHandlerString);
+ }
+ sb.append('}');
+ when.addElement(new TextElement(sb.toString()));
+ chooseElement.addElement(when);
+
+ when = new XmlElement("when");
+ when.addAttribute(new Attribute("test", "criterion.betweenValue"));
+ sb.setLength(0);
+ sb.append("and ${criterion.condition} #{criterion.value");
+ if (typeHandled) {
+ sb.append(typeHandlerString);
+ }
+ sb.append("} and #{criterion.secondValue");
+ if (typeHandled) {
+ sb.append(typeHandlerString);
+ }
+ sb.append("}");
+ when.addElement(new TextElement(sb.toString()));
+ chooseElement.addElement(when);
+
+ when = new XmlElement("when");
+ when.addAttribute(new Attribute("test", "criterion.listValue"));
+ when.addElement(new TextElement("and ${criterion.condition}"));
+ XmlElement innerForEach = new XmlElement("foreach");
+ innerForEach.addAttribute(new Attribute("collection", "criterion.value"));
+ innerForEach.addAttribute(new Attribute("item", "listItem"));
+ innerForEach.addAttribute(new Attribute("open", "("));
+ innerForEach.addAttribute(new Attribute("close", ")"));
+ innerForEach.addAttribute(new Attribute("separator", ","));
+ sb.setLength(0);
+ sb.append("#{listItem");
+ if (typeHandled) {
+ sb.append(typeHandlerString);
+ }
+ sb.append('}');
+ innerForEach.addElement(new TextElement(sb.toString()));
+ when.addElement(innerForEach);
+ chooseElement.addElement(when);
+
+ return middleForEachElement;
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/InsertElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/InsertElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/InsertElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/InsertElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.OutputUtilities;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.config.GeneratedKey;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class InsertElementGenerator extends AbstractXmlElementGenerator {
+
+ public InsertElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("insert"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute("id", introspectedTable.getInsertStatementId())); //$NON-NLS-1$
+
+ FullyQualifiedJavaType parameterType =
+ introspectedTable.getRules().calculateAllFieldsClass();
+
+ answer.addAttribute(new Attribute("parameterType", //$NON-NLS-1$
+ parameterType.getFullyQualifiedName()));
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ GeneratedKey gk = introspectedTable.getGeneratedKey();
+
+ if (gk != null && gk.isBeforeInsert()) {
+ IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
+ // if the column is null, then it's a configuration error. The
+ // warning has already been reported
+ if (introspectedColumn != null) {
+ // pre-generated key
+ answer.addElement(getSelectKey(introspectedColumn, gk));
+ }
+ }
+
+ StringBuilder insertClause = new StringBuilder();
+ StringBuilder valuesClause = new StringBuilder();
+
+ insertClause.append("insert into "); //$NON-NLS-1$
+ insertClause.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
+ insertClause.append(" ("); //$NON-NLS-1$
+
+ valuesClause.append("values ("); //$NON-NLS-1$
+
+ List<String> valuesClauses = new ArrayList<String>();
+ Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns().iterator();
+ while (iter.hasNext()) {
+ IntrospectedColumn introspectedColumn = iter.next();
+ if (introspectedColumn.isIdentity()) {
+ // cannot set values on identity fields
+ continue;
+ }
+
+ insertClause.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ valuesClause.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+ if (iter.hasNext()) {
+ insertClause.append(", "); //$NON-NLS-1$
+ valuesClause.append(", "); //$NON-NLS-1$
+ }
+
+ if (valuesClause.length() > 80) {
+ answer.addElement(new TextElement(insertClause.toString()));
+ insertClause.setLength(0);
+ OutputUtilities.xmlIndent(insertClause, 1);
+
+ valuesClauses.add(valuesClause.toString());
+ valuesClause.setLength(0);
+ OutputUtilities.xmlIndent(valuesClause, 1);
+ }
+ }
+
+ insertClause.append(')');
+ answer.addElement(new TextElement(insertClause.toString()));
+
+ valuesClause.append(')');
+ valuesClauses.add(valuesClause.toString());
+
+ for (String clause : valuesClauses) {
+ answer.addElement(new TextElement(clause));
+ }
+
+ if (gk != null && !gk.isBeforeInsert()) {
+ IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
+ // if the column is null, then it's a configuration error. The
+ // warning has already been reported
+ if (introspectedColumn != null) {
+ // pre-generated key
+ answer.addElement(getSelectKey(introspectedColumn, gk));
+ }
+ }
+
+ if (ibatorContext.getPlugins().sqlMapInsertElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/InsertSelectiveElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/InsertSelectiveElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/InsertSelectiveElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/InsertSelectiveElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.config.GeneratedKey;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class InsertSelectiveElementGenerator extends AbstractXmlElementGenerator {
+
+ public InsertSelectiveElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("insert"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute("id", introspectedTable.getInsertSelectiveStatementId())); //$NON-NLS-1$
+
+ FullyQualifiedJavaType parameterType =
+ introspectedTable.getRules().calculateAllFieldsClass();
+
+ answer.addAttribute(new Attribute("parameterType", //$NON-NLS-1$
+ parameterType.getFullyQualifiedName()));
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ GeneratedKey gk = introspectedTable.getGeneratedKey();
+
+ if (gk != null && gk.isBeforeInsert()) {
+ IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
+ // if the column is null, then it's a configuration error. The
+ // warning has already been reported
+ if (introspectedColumn != null) {
+ // pre-generated key
+ answer.addElement(getSelectKey(introspectedColumn, gk));
+ }
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("insert into "); //$NON-NLS-1$
+ sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ XmlElement insertElement = new XmlElement("trim"); //$NON-NLS-1$
+ insertElement.addAttribute(new Attribute("prefix", "(")); //$NON-NLS-1$ //$NON-NLS-2$
+ insertElement.addAttribute(new Attribute("suffix", ")")); //$NON-NLS-1$ //$NON-NLS-2$
+ insertElement.addAttribute(new Attribute("suffixOverrides", ",")); //$NON-NLS-1$ //$NON-NLS-2$
+ answer.addElement(insertElement);
+
+ XmlElement valuesElement = new XmlElement("trim"); //$NON-NLS-1$
+ valuesElement.addAttribute(new Attribute("prefix", "values (")); //$NON-NLS-1$ //$NON-NLS-2$
+ valuesElement.addAttribute(new Attribute("suffix", ")")); //$NON-NLS-1$ //$NON-NLS-2$
+ valuesElement.addAttribute(new Attribute("suffixOverrides", ",")); //$NON-NLS-1$ //$NON-NLS-2$
+ answer.addElement(valuesElement);
+
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
+ if (introspectedColumn.isIdentity()) {
+ // cannot set values on identity fields
+ continue;
+ }
+
+ XmlElement insertNotNullElement = new XmlElement("if"); //$NON-NLS-1$
+ sb.setLength(0);
+ sb.append(introspectedColumn.getJavaProperty());
+ sb.append(" != null");
+ insertNotNullElement.addAttribute(new Attribute("test", sb.toString())); //$NON-NLS-1$
+
+ sb.setLength(0);
+ sb.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ sb.append(',');
+ insertNotNullElement.addElement(new TextElement(sb.toString()));
+ insertElement.addElement(insertNotNullElement);
+
+ XmlElement valuesNotNullElement = new XmlElement("if"); //$NON-NLS-1$
+ sb.setLength(0);
+ sb.append(introspectedColumn.getJavaProperty());
+ sb.append(" != null");
+ valuesNotNullElement.addAttribute(new Attribute("test", sb.toString())); //$NON-NLS-1$
+
+ sb.setLength(0);
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+ sb.append(',');
+ valuesNotNullElement.addElement(new TextElement(sb.toString()));
+ valuesElement.addElement(valuesNotNullElement);
+ }
+
+ if (gk != null && !gk.isBeforeInsert()) {
+ IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
+ // if the column is null, then it's a configuration error. The
+ // warning has already been reported
+ if (introspectedColumn != null) {
+ // pre-generated key
+ answer.addElement(getSelectKey(introspectedColumn, gk));
+ }
+ }
+
+ if (ibatorContext.getPlugins().sqlMapInsertSelectiveElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ResultMapWithBLOBsElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ResultMapWithBLOBsElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ResultMapWithBLOBsElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ResultMapWithBLOBsElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+import org.apache.ibatis.ibator.internal.util.StringUtility;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class ResultMapWithBLOBsElementGenerator extends AbstractXmlElementGenerator {
+
+ public ResultMapWithBLOBsElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute("id", //$NON-NLS-1$
+ introspectedTable.getResultMapWithBLOBsId()));
+
+ String returnType;
+ if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
+ returnType = introspectedTable.getRecordWithBLOBsType();
+ } else {
+ // table has BLOBs, but no BLOB class - BLOB fields must be
+ // in the base class
+ returnType = introspectedTable.getBaseRecordType();
+ }
+
+ answer.addAttribute(new Attribute("type", //$NON-NLS-1$
+ returnType));
+
+ StringBuilder sb = new StringBuilder();
+// TODO - what do we need to do here for iBATIS3?
+// sb.append(introspectedTable.getSqlMapNamespace());
+// sb.append('.');
+ sb.append(introspectedTable.getBaseResultMapId());
+ answer.addAttribute(new Attribute("extends", sb.toString())); //$NON-NLS-1$
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ int i = introspectedTable.getNonBLOBColumnCount() + 1;
+ if (StringUtility.stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())
+ || StringUtility.stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
+ i++;
+ }
+
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getBLOBColumns()) {
+ XmlElement resultElement = new XmlElement("result"); //$NON-NLS-1$
+
+ resultElement.addAttribute(new Attribute(
+ "column", Ibatis3FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn))); //$NON-NLS-1$
+ resultElement.addAttribute(new Attribute(
+ "property", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
+ resultElement.addAttribute(new Attribute(
+ "jdbcType", introspectedColumn.getJdbcTypeName())); //$NON-NLS-1$
+
+ if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
+ resultElement.addAttribute(new Attribute(
+ "typeHandler", introspectedColumn.getTypeHandler())); //$NON-NLS-1$
+ }
+
+ answer.addElement(resultElement);
+ }
+
+ if (ibatorContext.getPlugins().sqlMapResultMapWithBLOBsElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ResultMapWithoutBLOBsElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ResultMapWithoutBLOBsElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ResultMapWithoutBLOBsElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/ResultMapWithoutBLOBsElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+import org.apache.ibatis.ibator.internal.util.StringUtility;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class ResultMapWithoutBLOBsElementGenerator extends AbstractXmlElementGenerator {
+
+ public ResultMapWithoutBLOBsElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$
+ answer.addAttribute(new Attribute("id", //$NON-NLS-1$
+ introspectedTable.getBaseResultMapId()));
+
+ String returnType;
+ if (introspectedTable.getRules().generateBaseRecordClass()) {
+ returnType = introspectedTable.getBaseRecordType();
+ } else {
+ returnType = introspectedTable.getPrimaryKeyType();
+ }
+
+ answer.addAttribute(new Attribute("type", //$NON-NLS-1$
+ returnType));
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ int i = 1;
+ if (StringUtility.stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())
+ || StringUtility.stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
+ i++;
+ }
+
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
+ XmlElement resultElement = new XmlElement("id"); //$NON-NLS-1$
+
+ resultElement.addAttribute(new Attribute(
+ "column", Ibatis3FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn))); //$NON-NLS-1$
+ resultElement.addAttribute(new Attribute(
+ "property", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
+ resultElement.addAttribute(new Attribute("jdbcType", //$NON-NLS-1$
+ introspectedColumn.getJdbcTypeName()));
+
+ if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
+ resultElement.addAttribute(new Attribute(
+ "typeHandler", introspectedColumn.getTypeHandler())); //$NON-NLS-1$
+ }
+
+ answer.addElement(resultElement);
+ }
+
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getBaseColumns()) {
+ XmlElement resultElement = new XmlElement("result"); //$NON-NLS-1$
+
+ resultElement.addAttribute(new Attribute(
+ "column", Ibatis3FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn))); //$NON-NLS-1$
+ resultElement.addAttribute(new Attribute(
+ "property", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
+ resultElement.addAttribute(new Attribute("jdbcType", //$NON-NLS-1$
+ introspectedColumn.getJdbcTypeName()));
+
+ if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
+ resultElement.addAttribute(new Attribute(
+ "typeHandler", introspectedColumn.getTypeHandler())); //$NON-NLS-1$
+ }
+
+ answer.addElement(resultElement);
+ }
+
+ if (ibatorContext.getPlugins().sqlMapResultMapWithoutBLOBsElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByExampleWithBLOBsElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByExampleWithBLOBsElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByExampleWithBLOBsElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByExampleWithBLOBsElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.internal.util.StringUtility;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class SelectByExampleWithBLOBsElementGenerator extends
+ AbstractXmlElementGenerator {
+
+ public SelectByExampleWithBLOBsElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ String fqjt = introspectedTable.getExampleType();
+
+ XmlElement answer = new XmlElement("select"); //$NON-NLS-1$
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getSelectByExampleWithBLOBsStatementId())); //$NON-NLS-1$
+ answer.addAttribute(new Attribute(
+ "resultMap", introspectedTable.getResultMapWithBLOBsId())); //$NON-NLS-1$
+ answer.addAttribute(new Attribute(
+ "parameterType", fqjt)); //$NON-NLS-1$
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("select "); //$NON-NLS-1$
+
+ if (StringUtility.stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
+ sb.append('\'');
+ sb.append(introspectedTable.getSelectByExampleQueryId());
+ sb.append("' as QUERYID,"); //$NON-NLS-1$
+ }
+ answer.addElement(new TextElement(sb.toString()));
+ answer.addElement(getBaseColumnListElement());
+ answer.addElement(new TextElement(",")); //$NON-NLS-1$
+ answer.addElement(getBlobColumnListElement());
+
+ sb.setLength(0);
+ sb.append("from "); //$NON-NLS-1$
+ sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+ answer.addElement(getExampleIncludeElement());
+
+ XmlElement ifElement = new XmlElement("if"); //$NON-NLS-1$
+ ifElement.addAttribute(new Attribute("test", "orderByClause != null"));
+ ifElement
+ .addElement(new TextElement("order by $orderByClause$")); //$NON-NLS-1$
+ answer.addElement(ifElement);
+
+ if (ibatorContext.getPlugins().sqlMapSelectByExampleWithBLOBsElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByExampleWithoutBLOBsElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByExampleWithoutBLOBsElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByExampleWithoutBLOBsElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByExampleWithoutBLOBsElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.internal.util.StringUtility;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class SelectByExampleWithoutBLOBsElementGenerator extends AbstractXmlElementGenerator {
+
+ public SelectByExampleWithoutBLOBsElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ String fqjt = introspectedTable.getExampleType();
+
+ XmlElement answer = new XmlElement("select"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute("id", //$NON-NLS-1$
+ introspectedTable.getSelectByExampleStatementId()));
+ answer.addAttribute(new Attribute(
+ "resultMap", introspectedTable.getBaseResultMapId())); //$NON-NLS-1$
+ answer.addAttribute(new Attribute(
+ "parameterType", fqjt)); //$NON-NLS-1$
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("select "); //$NON-NLS-1$
+
+ if (StringUtility.stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
+ sb.append('\'');
+ sb.append(introspectedTable.getSelectByExampleQueryId());
+ sb.append("' as QUERYID,"); //$NON-NLS-1$
+ }
+ answer.addElement(new TextElement(sb.toString()));
+ answer.addElement(getBaseColumnListElement());
+
+ sb.setLength(0);
+ sb.append("from "); //$NON-NLS-1$
+ sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
+ answer.addElement((new TextElement(sb.toString())));
+ answer.addElement(getExampleIncludeElement());
+
+ XmlElement ifElement = new XmlElement("if"); //$NON-NLS-1$
+ ifElement
+ .addAttribute(new Attribute("test", "orderByClause != null")); //$NON-NLS-1$ //$NON-NLS-2$
+ ifElement
+ .addElement(new TextElement("order by ${orderByClause}")); //$NON-NLS-1$
+ answer.addElement(ifElement);
+
+ if (ibatorContext.getPlugins().sqlMapSelectByExampleWithoutBLOBsElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByPrimaryKeyElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByPrimaryKeyElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByPrimaryKeyElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/SelectByPrimaryKeyElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+import org.apache.ibatis.ibator.internal.util.StringUtility;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class SelectByPrimaryKeyElementGenerator extends AbstractXmlElementGenerator {
+
+ public SelectByPrimaryKeyElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("select"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getSelectByPrimaryKeyStatementId())); //$NON-NLS-1$
+ if (introspectedTable.getRules().generateResultMapWithBLOBs()) {
+ answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
+ introspectedTable.getResultMapWithBLOBsId()));
+ } else {
+ answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
+ introspectedTable.getBaseResultMapId()));
+ }
+
+ String parameterType;
+ if (introspectedTable.getRules().generatePrimaryKeyClass()) {
+ parameterType = introspectedTable.getPrimaryKeyType();
+ } else {
+ // select by primary key, but no primary key class. Fields
+ // must be in the base record
+ parameterType = introspectedTable.getBaseRecordType();
+ }
+
+ answer.addAttribute(new Attribute("parameterType", //$NON-NLS-1$
+ parameterType));
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("select "); //$NON-NLS-1$
+
+ if (StringUtility.stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
+ sb.append('\'');
+ sb.append(introspectedTable.getSelectByPrimaryKeyQueryId());
+ sb.append("' as QUERYID,"); //$NON-NLS-1$
+ }
+ answer.addElement(new TextElement(sb.toString()));
+ answer.addElement(getBaseColumnListElement());
+ if (introspectedTable.hasBLOBColumns()) {
+ answer.addElement(new TextElement(",")); //$NON-NLS-1$
+ answer.addElement(getBlobColumnListElement());
+ }
+
+ sb.setLength(0);
+ sb.append("from "); //$NON-NLS-1$
+ sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ boolean and = false;
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
+ sb.setLength(0);
+ if (and) {
+ sb.append(" and "); //$NON-NLS-1$
+ } else {
+ sb.append("where "); //$NON-NLS-1$
+ and = true;
+ }
+
+ sb.append(Ibatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+ answer.addElement(new TextElement(sb.toString()));
+ }
+
+ if (ibatorContext.getPlugins().sqlMapSelectByPrimaryKeyElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleSelectiveElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleSelectiveElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleSelectiveElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleSelectiveElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class UpdateByExampleSelectiveElementGenerator extends
+ AbstractXmlElementGenerator {
+
+ public UpdateByExampleSelectiveElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getUpdateByExampleSelectiveStatementId())); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("update "); //$NON-NLS-1$
+ sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ XmlElement dynamicElement = new XmlElement("set"); //$NON-NLS-1$
+ answer.addElement(dynamicElement);
+
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
+ XmlElement isNotNullElement = new XmlElement("if"); //$NON-NLS-1$
+ sb.setLength(0);
+ sb.append(introspectedColumn.getJavaProperty("record.")); //$NON-NLS-1$
+ sb.append(" != null"); //$NON-NLS-1$
+ isNotNullElement.addAttribute(new Attribute("test", sb.toString())); //$NON-NLS-1$
+ dynamicElement.addElement(isNotNullElement);
+
+ sb.setLength(0);
+ sb.append(Ibatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn, "record.")); //$NON-NLS-1$
+ sb.append(',');
+
+ isNotNullElement.addElement(new TextElement(sb.toString()));
+ }
+
+ answer.addElement(getExampleIncludeElement());
+
+ if (ibatorContext.getPlugins().sqlMapUpdateByExampleSelectiveElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleWithBLOBsElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleWithBLOBsElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleWithBLOBsElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleWithBLOBsElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import java.util.Iterator;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.OutputUtilities;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class UpdateByExampleWithBLOBsElementGenerator extends
+ AbstractXmlElementGenerator {
+
+ public UpdateByExampleWithBLOBsElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute("id", //$NON-NLS-1$
+ introspectedTable.getUpdateByExampleWithBLOBsStatementId()));
+
+ answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("update "); //$NON-NLS-1$
+ sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ // set up for first column
+ sb.setLength(0);
+ sb.append("set "); //$NON-NLS-1$
+
+ Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns().iterator();
+ while (iter.hasNext()) {
+ IntrospectedColumn introspectedColumn = iter.next();
+
+ sb.append(Ibatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn, "record.")); //$NON-NLS-1$
+
+ if (iter.hasNext()) {
+ sb.append(',');
+ }
+
+ answer.addElement(new TextElement(sb.toString()));
+
+ // set up for the next column
+ if (iter.hasNext()) {
+ sb.setLength(0);
+ OutputUtilities.xmlIndent(sb, 1);
+ }
+ }
+
+ answer.addElement(getExampleIncludeElement());
+
+ if (ibatorContext.getPlugins().sqlMapUpdateByExampleWithBLOBsElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleWithoutBLOBsElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleWithoutBLOBsElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleWithoutBLOBsElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByExampleWithoutBLOBsElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import java.util.Iterator;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.OutputUtilities;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class UpdateByExampleWithoutBLOBsElementGenerator extends
+ AbstractXmlElementGenerator {
+
+ public UpdateByExampleWithoutBLOBsElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute("id", //$NON-NLS-1$
+ introspectedTable.getUpdateByExampleStatementId()));
+
+ answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("update "); //$NON-NLS-1$
+ sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ // set up for first column
+ sb.setLength(0);
+ sb.append("set "); //$NON-NLS-1$
+
+ Iterator<IntrospectedColumn> iter = introspectedTable.getNonBLOBColumns().iterator();
+ while (iter.hasNext()) {
+ IntrospectedColumn introspectedColumn = iter.next();
+
+ sb.append(Ibatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn, "record.")); //$NON-NLS-1$
+
+ if (iter.hasNext()) {
+ sb.append(',');
+ }
+
+ answer.addElement(new TextElement(sb.toString()));
+
+ // set up for the next column
+ if (iter.hasNext()) {
+ sb.setLength(0);
+ OutputUtilities.xmlIndent(sb, 1);
+ }
+ }
+
+ answer.addElement(getExampleIncludeElement());
+
+ if (ibatorContext.getPlugins().sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeySelectiveElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeySelectiveElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeySelectiveElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeySelectiveElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class UpdateByPrimaryKeySelectiveElementGenerator extends
+ AbstractXmlElementGenerator {
+
+ public UpdateByPrimaryKeySelectiveElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getUpdateByPrimaryKeySelectiveStatementId())); //$NON-NLS-1$
+
+ String parameterType;
+
+ if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
+ parameterType = introspectedTable.getRecordWithBLOBsType();
+ } else {
+ parameterType = introspectedTable.getBaseRecordType();
+ }
+
+ answer.addAttribute(new Attribute("parameterType", //$NON-NLS-1$
+ parameterType));
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("update "); //$NON-NLS-1$
+ sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ XmlElement dynamicElement = new XmlElement("set"); //$NON-NLS-1$
+ answer.addElement(dynamicElement);
+
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getNonPrimaryKeyColumns()) {
+ XmlElement isNotNullElement = new XmlElement("if"); //$NON-NLS-1$
+ sb.setLength(0);
+ sb.append(introspectedColumn.getJavaProperty());
+ sb.append(" != null"); //$NON-NLS-1$
+ isNotNullElement.addAttribute(new Attribute("test", sb.toString()));
+ dynamicElement.addElement(isNotNullElement);
+
+ sb.setLength(0);
+ sb.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+ sb.append(',');
+
+ isNotNullElement.addElement(new TextElement(sb.toString()));
+ }
+
+ boolean and = false;
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
+ sb.setLength(0);
+ if (and) {
+ sb.append(" and "); //$NON-NLS-1$
+ } else {
+ sb.append("where "); //$NON-NLS-1$
+ and = true;
+ }
+
+ sb.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+ answer.addElement(new TextElement(sb.toString()));
+ }
+
+
+ if (ibatorContext.getPlugins().sqlMapUpdateByPrimaryKeySelectiveElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeyWithBLOBsElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeyWithBLOBsElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeyWithBLOBsElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeyWithBLOBsElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import java.util.Iterator;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.OutputUtilities;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class UpdateByPrimaryKeyWithBLOBsElementGenerator extends
+ AbstractXmlElementGenerator {
+
+ public UpdateByPrimaryKeyWithBLOBsElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getUpdateByPrimaryKeyWithBLOBsStatementId())); //$NON-NLS-1$
+
+ String parameterType;
+ if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
+ parameterType = introspectedTable.getRecordWithBLOBsType();
+ } else {
+ parameterType = introspectedTable.getBaseRecordType();
+ }
+
+ answer.addAttribute(new Attribute("parameterType", //$NON-NLS-1$
+ parameterType));
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("update "); //$NON-NLS-1$
+ sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ // set up for first column
+ sb.setLength(0);
+ sb.append("set "); //$NON-NLS-1$
+
+ Iterator<IntrospectedColumn> iter = introspectedTable.getNonPrimaryKeyColumns().iterator();
+ while (iter.hasNext()) {
+ IntrospectedColumn introspectedColumn = iter.next();
+
+ sb.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+
+ if (iter.hasNext()) {
+ sb.append(',');
+ }
+
+ answer.addElement(new TextElement(sb.toString()));
+
+ // set up for the next column
+ if (iter.hasNext()) {
+ sb.setLength(0);
+ OutputUtilities.xmlIndent(sb, 1);
+ }
+ }
+
+ boolean and = false;
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
+ sb.setLength(0);
+ if (and) {
+ sb.append(" and "); //$NON-NLS-1$
+ } else {
+ sb.append("where "); //$NON-NLS-1$
+ and = true;
+ }
+
+ sb.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+ answer.addElement(new TextElement(sb.toString()));
+ }
+
+
+ if (ibatorContext.getPlugins().sqlMapUpdateByPrimaryKeyWithBLOBsElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/generator/ibatis3/xmlmapper/elements/UpdateByPrimaryKeyWithoutBLOBsElementGenerator.java Sun Nov 8 04:06:27 2009
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements;
+
+import java.util.Iterator;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.OutputUtilities;
+import org.apache.ibatis.ibator.api.dom.xml.Attribute;
+import org.apache.ibatis.ibator.api.dom.xml.TextElement;
+import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
+import org.apache.ibatis.ibator.generator.ibatis3.Ibatis3FormattingUtilities;
+
+/**
+ *
+ * @author Jeff Butler
+ *
+ */
+public class UpdateByPrimaryKeyWithoutBLOBsElementGenerator extends
+ AbstractXmlElementGenerator {
+
+ public UpdateByPrimaryKeyWithoutBLOBsElementGenerator() {
+ super();
+ }
+
+ @Override
+ public void addElements(XmlElement parentElement) {
+ XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
+
+ answer.addAttribute(new Attribute(
+ "id", introspectedTable.getUpdateByPrimaryKeyStatementId())); //$NON-NLS-1$
+ answer.addAttribute(new Attribute("parameterType", //$NON-NLS-1$
+ introspectedTable.getBaseRecordType()));
+
+ ibatorContext.getCommentGenerator().addComment(answer);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("update "); //$NON-NLS-1$
+ sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
+ answer.addElement(new TextElement(sb.toString()));
+
+ // set up for first column
+ sb.setLength(0);
+ sb.append("set "); //$NON-NLS-1$
+
+ Iterator<IntrospectedColumn> iter = introspectedTable.getBaseColumns().iterator();
+ while (iter.hasNext()) {
+ IntrospectedColumn introspectedColumn = iter.next();
+
+ sb.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+
+ if (iter.hasNext()) {
+ sb.append(',');
+ }
+
+ answer.addElement(new TextElement(sb.toString()));
+
+ // set up for the next column
+ if (iter.hasNext()) {
+ sb.setLength(0);
+ OutputUtilities.xmlIndent(sb, 1);
+ }
+ }
+
+ boolean and = false;
+ for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
+ sb.setLength(0);
+ if (and) {
+ sb.append(" and "); //$NON-NLS-1$
+ } else {
+ sb.append("where "); //$NON-NLS-1$
+ and = true;
+ }
+
+ sb.append(Ibatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
+ sb.append(" = "); //$NON-NLS-1$
+ sb.append(Ibatis3FormattingUtilities.getParameterClause(introspectedColumn));
+ answer.addElement(new TextElement(sb.toString()));
+ }
+
+ if (ibatorContext.getPlugins().sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(answer, introspectedTable)) {
+ parentElement.addElement(answer);
+ }
+ }
+}
Modified: ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/internal/IbatorObjectFactory.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/internal/IbatorObjectFactory.java?rev=833819&r1=833818&r2=833819&view=diff
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/internal/IbatorObjectFactory.java (original)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/main/java/org/apache/ibatis/ibator/internal/IbatorObjectFactory.java Sun Nov 8 04:06:27 2009
@@ -30,6 +30,7 @@
import org.apache.ibatis.ibator.config.TableConfiguration;
import org.apache.ibatis.ibator.generator.ibatis2.IntrospectedTableIbatis2Java2Impl;
import org.apache.ibatis.ibator.generator.ibatis2.IntrospectedTableIbatis2Java5Impl;
+import org.apache.ibatis.ibator.generator.ibatis3.IntrospectedTableIbatis3Impl;
import org.apache.ibatis.ibator.internal.types.JavaTypeResolverDefaultImpl;
import org.apache.ibatis.ibator.internal.util.StringUtility;
import org.apache.ibatis.ibator.internal.util.messages.Messages;
@@ -202,6 +203,8 @@
type = IntrospectedTableIbatis2Java2Impl.class.getName();
} else if ("Ibatis2Java5".equalsIgnoreCase(type)) { //$NON-NLS-1$
type = IntrospectedTableIbatis2Java5Impl.class.getName();
+ } else if ("Ibatis3".equalsIgnoreCase(type)) { //$NON-NLS-1$
+ type = IntrospectedTableIbatis3Impl.class.getName();
}
IntrospectedTable answer = (IntrospectedTable) createInternalObject(type);
Modified: ibatis/java/ibator/trunk/core/ibator-core/src/test/java/org/apache/ibatis/ibator/IbatisGenerationTest.java
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/test/java/org/apache/ibatis/ibator/IbatisGenerationTest.java?rev=833819&r1=833818&r2=833819&view=diff
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/test/java/org/apache/ibatis/ibator/IbatisGenerationTest.java (original)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/test/java/org/apache/ibatis/ibator/IbatisGenerationTest.java Sun Nov 8 04:06:27 2009
@@ -69,4 +69,32 @@
ibator.generate(progressCallback, null, null);
}
+
+ @Test
+ public void testGenerateIbatis3() throws Exception {
+ SqlScriptRunner scriptRunner = new SqlScriptRunner(
+ this.getClass().getClassLoader().getResourceAsStream("CreateDbIbatis3.sql"),
+ "org.hsqldb.jdbcDriver",
+ "jdbc:hsqldb:mem:aname",
+ "sa",
+ "");
+
+ scriptRunner.executeScript();
+
+ File file = new File("target/generated-sources/ibator/ibatis3");
+ file.mkdirs();
+
+ List<String> warnings = new ArrayList<String>();
+ IbatorConfigurationParser cp = new IbatorConfigurationParser(
+ warnings);
+ IbatorConfiguration config = cp.parseIbatorConfiguration(this.getClass().getClassLoader().getResourceAsStream("ibatorConfigIbatis3.xml"));
+
+ DefaultShellCallback shellCallback = new DefaultShellCallback(true);
+
+ Ibator ibator = new Ibator(config, shellCallback, warnings);
+
+ ProgressCallback progressCallback = new VerboseProgressCallback();
+
+ ibator.generate(progressCallback, null, null);
+ }
}
Added: ibatis/java/ibator/trunk/core/ibator-core/src/test/resources/CreateDBIbatis3.sql
URL: http://svn.apache.org/viewvc/ibatis/java/ibator/trunk/core/ibator-core/src/test/resources/CreateDBIbatis3.sql?rev=833819&view=auto
==============================================================================
--- ibatis/java/ibator/trunk/core/ibator-core/src/test/resources/CreateDBIbatis3.sql (added)
+++ ibatis/java/ibator/trunk/core/ibator-core/src/test/resources/CreateDBIbatis3.sql Sun Nov 8 04:06:27 2009
@@ -0,0 +1,103 @@
+drop table FieldsOnly if exists;
+drop table PKOnly if exists;
+drop table PKFields if exists;
+drop table PKBlobs if exists;
+drop table PKFieldsBlobs if exists;
+drop table FieldsBlobs if exists;
+drop table "awful table" if exists;
+drop table BlobsOnly if exists;
+drop table RegexRename if exists;
+drop table AnotherAwfulTable if exists;
+
+create table FieldsOnly (
+ IntegerField int,
+ DoubleField double,
+ FloatField float
+);
+
+create table PKOnly (
+ id int not null,
+ seq_num int not null,
+ primary key(id, seq_num)
+);
+
+create table PKFields (
+ id1 int not null,
+ id2 int not null,
+ firstName varchar(20),
+ lastName varchar(20),
+ dateField date,
+ timeField time,
+ timestampField timestamp,
+ decimal30Field decimal(3, 0),
+ decimal60Field decimal(6, 0),
+ decimal100Field decimal(10, 0),
+ decimal155Field decimal(15, 5),
+ wierd$Field int,
+ primary key (id1, id2)
+);
+
+create table PKBlobs (
+ id int not null,
+ blob1 longvarbinary,
+ blob2 longvarbinary,
+ primary key (id)
+);
+
+create table PKFieldsBlobs (
+ id1 int not null,
+ id2 int not null,
+ firstName varchar(20),
+ lastName varchar(20),
+ blob1 longvarbinary,
+ primary key (id1, id2)
+);
+
+create table FieldsBlobs (
+ firstName varchar(20),
+ lastName varchar(20),
+ blob1 longvarbinary,
+ blob2 longvarbinary,
+ blob3 binary
+);
+
+create table "awful table" (
+ "CuStOmEr iD" int generated by default as identity (start with 57) not null,
+ "first name" varchar(20) default 'Mabel',
+ first_name varchar(20),
+ firstName varchar(20),
+ "last name" varchar(20),
+ E_MAIL varchar(20),
+ _id1 int not null,
+ $id2 int not null,
+ id5_ int not null,
+ id6$ int not null,
+ id7$$ int not null,
+ EmailAddress varchar(30),
+ "from" varchar(30),
+ active bit not null,
+ primary key("CuStOmEr iD")
+);
+
+-- this table should be ignored, nothing generated
+create table BlobsOnly (
+ blob1 longvarbinary,
+ blob2 longvarbinary
+);
+
+create table RegexRename (
+ CUST_ID integer,
+ CUST_NAME varchar(30),
+ CUST_ADDRESS varchar(30),
+ ZIP_CODE char(5),
+ primary key(CUST_ID)
+);
+
+create table AnotherAwfulTable (
+ id int not null,
+ "select" varchar(30),
+ "insert" varchar(30),
+ "update" varchar(30),
+ "delete" varchar(30),
+ primary key(id)
+);