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 2006/08/05 07:19:15 UTC
svn commit: r428963 [3/3] - in
/ibatis/trunk/java/mapper/mapper2/tools/abator/core: htmldoc/
htmldoc/reference/ src/org/apache/ibatis/abator/api/
src/org/apache/ibatis/abator/config/
src/org/apache/ibatis/abator/config/xml/ src/org/apache/ibatis/abator...
Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/sqlmap/SqlMapGeneratorDefaultImpl.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/sqlmap/SqlMapGeneratorDefaultImpl.java?rev=428963&r1=428962&r2=428963&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/sqlmap/SqlMapGeneratorDefaultImpl.java (original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/sqlmap/SqlMapGeneratorDefaultImpl.java Fri Aug 4 22:19:13 2006
@@ -15,642 +15,32 @@
*/
package org.apache.ibatis.abator.internal.sqlmap;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
import org.apache.ibatis.abator.api.FullyQualifiedTable;
-import org.apache.ibatis.abator.api.GeneratedXmlFile;
import org.apache.ibatis.abator.api.IntrospectedTable;
-import org.apache.ibatis.abator.api.JavaModelGenerator;
-import org.apache.ibatis.abator.api.ProgressCallback;
import org.apache.ibatis.abator.api.SqlMapGenerator;
-import org.apache.ibatis.abator.api.dom.OutputUtilities;
import org.apache.ibatis.abator.api.dom.xml.Attribute;
-import org.apache.ibatis.abator.api.dom.xml.Document;
import org.apache.ibatis.abator.api.dom.xml.TextElement;
import org.apache.ibatis.abator.api.dom.xml.XmlElement;
-import org.apache.ibatis.abator.config.GeneratedKey;
import org.apache.ibatis.abator.internal.db.ColumnDefinition;
-import org.apache.ibatis.abator.internal.rules.AbatorRules;
import org.apache.ibatis.abator.internal.util.StringUtility;
-import org.apache.ibatis.abator.internal.util.messages.Messages;
/**
+ * This class overrides the iterate implementation to provide the legacy
+ * "by example" methods.
+ *
+ * This class can be removed when we remove the Legacy generator set.
+ *
* @author Jeff Butler
*/
-public class SqlMapGeneratorDefaultImpl implements SqlMapGenerator {
-
- protected List warnings;
-
- /**
- * Contains any properties passed in from the SqlMap configuration element.
- */
- protected Map properties;
-
- /**
- * This is the target package from the SqlMap configuration element
- */
- protected String targetPackage;
-
- /**
- * This is the target project from the SqlMap configuration element
- */
- protected String targetProject;
-
- /**
- * This is the java model generator associated with the current generation
- * context. Methods in this interface can be used to determine the
- * appropriate result and parameter class names.
- */
- protected JavaModelGenerator javaModelGenerator;
-
- /**
- * This is a map of maps. The map is keyed by a FullyQualifiedTable object.
- * The inner map holds generated strings keyed by the String name. This Map
- * is used to cache generated Strings.
- */
- private Map tableStringMaps;
+public class SqlMapGeneratorDefaultImpl extends SqlMapGeneratorIterateImpl implements SqlMapGenerator {
/**
* Constructs an instance of SqlMapGeneratorDefaultImpl
*/
public SqlMapGeneratorDefaultImpl() {
super();
- tableStringMaps = new HashMap();
- }
-
- private Map getTableStringMap(FullyQualifiedTable table) {
- Map map = (Map) tableStringMaps.get(table);
- if (map == null) {
- map = new HashMap();
- tableStringMaps.put(table, map);
- }
-
- return map;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#setProperties(java.util.Map)
- */
- public void setProperties(Map properties) {
- this.properties = properties;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#setTargetPackage(java.lang.String)
- */
- public void setTargetPackage(String targetPackage) {
- this.targetPackage = targetPackage;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#setJavaModelGenerator(org.apache.ibatis.abator.api.JavaModelGenerator)
- */
- public void setJavaModelGenerator(JavaModelGenerator javaModelGenerator) {
- this.javaModelGenerator = javaModelGenerator;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getGeneratedXMLFiles(org.apache.ibatis.abator.internal.db.IntrospectedTable, org.apache.ibatis.abator.api.ProgressCallback)
- */
- public List getGeneratedXMLFiles(IntrospectedTable introspectedTable, ProgressCallback callback) {
- ArrayList list = new ArrayList();
-
- callback.startSubTask(Messages.getString(
- "Progress.12", //$NON-NLS-1$
- introspectedTable.getTable().getFullyQualifiedTableName()));
- list.add(getSqlMap(introspectedTable));
-
- return list;
- }
-
- /**
- * Creates the default implementation of the Sql Map
- *
- * @param introspectedTable
- * introspected table
- * @return A GeneratedXMLFile for the current table
- */
- protected GeneratedXmlFile getSqlMap(IntrospectedTable introspectedTable) {
-
- Document document = new Document(XmlConstants.SQL_MAP_PUBLIC_ID,
- XmlConstants.SQL_MAP_SYSTEM_ID);
- document.setRootElement(getSqlMapElement(introspectedTable));
-
- GeneratedXmlFile answer = new GeneratedXmlFile(document,
- getSqlMapFileName(introspectedTable.getTable()),
- getSqlMapPackage(introspectedTable.getTable()), targetProject);
-
- return answer;
- }
-
- /**
- * Creates the sqlMap element (the root element, and all child elements).
- *
- * @param introspectedTable
- * introspected table
- * @return the sqlMap element including all child elements
- */
- protected XmlElement getSqlMapElement(IntrospectedTable introspectedTable) {
-
- XmlElement answer = new XmlElement("sqlMap"); //$NON-NLS-1$
- answer.addAttribute(new Attribute("namespace", //$NON-NLS-1$
- getSqlMapNamespace(introspectedTable.getTable())));
-
- XmlElement element;
- if (AbatorRules.generateResultMapWithoutBLOBs(introspectedTable)) {
- element = getBaseResultMapElement(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateResultMapWithBLOBs(introspectedTable)) {
- element = getResultMapWithBLOBsElement(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateSQLExampleWhereClause(introspectedTable)) {
- element = getByExampleWhereClauseFragment(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateSelectByPrimaryKey(introspectedTable)) {
- element = getSelectByPrimaryKey(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateSelectByExampleWithoutBLOBs(introspectedTable)) {
- element = getSelectByExample(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateSelectByExampleWithBLOBs(introspectedTable)) {
- element = getSelectByExampleWithBLOBs(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateDeleteByPrimaryKey(introspectedTable)) {
- element = getDeleteByPrimaryKey(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateDeleteByExample(introspectedTable)) {
- element = getDeleteByExample(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateInsert(introspectedTable)) {
- element = getInsertElement(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateUpdateByPrimaryKeyWithBLOBs(introspectedTable)) {
- element = getUpdateByPrimaryKeyWithBLOBs(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- if (AbatorRules.generateUpdateByPrimaryKeyWithoutBLOBs(introspectedTable)) {
- element = getUpdateByPrimaryKey(introspectedTable);
- if (element != null) {
- answer.addElement(element);
- }
- }
-
- return answer;
- }
-
- /**
- * This method should return an XmlElement for the result map (without any
- * BLOBs if they exist in the table).
- *
- * @param introspectedTable
- * introspected table
- * @return the resultMap element
- */
- protected XmlElement getBaseResultMapElement(IntrospectedTable introspectedTable) {
- XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$
-
- FullyQualifiedTable table = introspectedTable.getTable();
- answer.addAttribute(new Attribute(
- "id", getResultMapName(table))); //$NON-NLS-1$
-
- if (AbatorRules.generateBaseRecordWithNoSuperclass(introspectedTable)
- || AbatorRules
- .generateBaseRecordExtendingPrimaryKey(introspectedTable)) {
- answer.addAttribute(new Attribute("class", javaModelGenerator //$NON-NLS-1$
- .getRecordType(table)
- .getFullyQualifiedName()));
- } else {
- answer.addAttribute(new Attribute("class", javaModelGenerator //$NON-NLS-1$
- .getPrimaryKeyType(table)
- .getFullyQualifiedName()));
- }
-
- answer.addComment();
-
- Iterator iter = introspectedTable.getAllColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (cd.isBLOBColumn()) {
- continue;
- }
-
- XmlElement resultElement = new XmlElement("result"); //$NON-NLS-1$
-
- resultElement.addAttribute(new Attribute(
- "column", cd.getRenamedColumnName())); //$NON-NLS-1$
- resultElement.addAttribute(new Attribute(
- "property", cd.getJavaProperty())); //$NON-NLS-1$
- resultElement.addAttribute(new Attribute("jdbcType", //$NON-NLS-1$
- cd.getResolvedJavaType().getJdbcTypeName()));
-
- if (StringUtility.stringHasValue(cd.getTypeHandler())) {
- resultElement.addAttribute(new Attribute(
- "typeHandler", cd.getTypeHandler())); //$NON-NLS-1$
- }
-
- answer.addElement(resultElement);
- }
-
- return answer;
- }
-
- /**
- * This method should return an XmlElement which is the result map (with any
- * BLOBs if they exist in the table). Typically this result map extends the
- * base result map.
- *
- * @param introspectedTable
- * introspected table
- * @return the resultMap element
- */
- protected XmlElement getResultMapWithBLOBsElement(IntrospectedTable introspectedTable) {
-
- XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$
-
- FullyQualifiedTable table = introspectedTable.getTable();
-
- StringBuffer sb = new StringBuffer();
- sb.append(getResultMapName(table));
- sb.append("WithBLOBs"); //$NON-NLS-1$
-
- answer.addAttribute(new Attribute("id", sb.toString())); //$NON-NLS-1$
- answer.addAttribute(new Attribute("class", javaModelGenerator //$NON-NLS-1$
- .getRecordWithBLOBsType(table)
- .getFullyQualifiedName()));
-
- sb.setLength(0);
- sb.append(getSqlMapNamespace(table));
- sb.append('.');
- sb.append(getResultMapName(table));
- answer.addAttribute(new Attribute("extends", sb.toString())); //$NON-NLS-1$
-
- answer.addComment();
-
- Iterator iter = introspectedTable.getAllColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (!cd.isBLOBColumn()) {
- continue;
- }
-
- XmlElement resultElement = new XmlElement("result"); //$NON-NLS-1$
-
- resultElement.addAttribute(new Attribute(
- "column", cd.getRenamedColumnName())); //$NON-NLS-1$
- resultElement.addAttribute(new Attribute(
- "property", cd.getJavaProperty())); //$NON-NLS-1$
- resultElement.addAttribute(new Attribute(
- "jdbcType", cd.getResolvedJavaType().getJdbcTypeName())); //$NON-NLS-1$
-
- if (StringUtility.stringHasValue(cd.getTypeHandler())) {
- resultElement.addAttribute(new Attribute(
- "typeHandler", cd.getTypeHandler())); //$NON-NLS-1$
- }
-
- answer.addElement(resultElement);
- }
-
- return answer;
- }
-
- /**
- * This method should return an XmlElement which is the insert statement.
- *
- * @param introspectedTable
- * introspected table
- * @return the insert element
- */
- protected XmlElement getInsertElement(IntrospectedTable introspectedTable) {
-
- XmlElement answer = new XmlElement("insert"); //$NON-NLS-1$
-
- FullyQualifiedTable table = introspectedTable.getTable();
- answer.addAttribute(new Attribute("id", getInsertStatementId())); //$NON-NLS-1$
- if (AbatorRules
- .generateRecordWithBLOBsExtendingPrimaryKey(introspectedTable)
- || AbatorRules
- .generateRecordWithBLOBsExtendingBaseRecord(introspectedTable)) {
- answer.addAttribute(new Attribute(
- "parameterClass", javaModelGenerator //$NON-NLS-1$
- .getRecordWithBLOBsType(
- table)
- .getFullyQualifiedName()));
- } else if (AbatorRules
- .generateBaseRecordWithNoSuperclass(introspectedTable)
- || AbatorRules
- .generateBaseRecordExtendingPrimaryKey(introspectedTable)) {
- answer.addAttribute(new Attribute(
- "parameterClass", javaModelGenerator //$NON-NLS-1$
- .getRecordType(table)
- .getFullyQualifiedName()));
- } else {
- answer.addAttribute(new Attribute(
- "parameterClass", javaModelGenerator //$NON-NLS-1$
- .getPrimaryKeyType(table)
- .getFullyQualifiedName()));
- }
-
- answer.addComment();
-
- GeneratedKey gk = introspectedTable.getGeneratedKey();
-
- if (gk != null && !gk.isIdentity()) {
- ColumnDefinition cd = introspectedTable.getColumn(gk.getColumn());
- // if the column is null, then it's a configuration error. The
- // warning has already been reported
- if (cd != null) {
- // pre-generated key
- answer.addElement(getSelectKey(cd, gk));
- }
- }
-
- StringBuffer insertClause = new StringBuffer();
- StringBuffer valuesClause = new StringBuffer();
-
- insertClause.append("insert into "); //$NON-NLS-1$
- insertClause.append(table
- .getFullyQualifiedTableName());
- insertClause.append(" ("); //$NON-NLS-1$
-
- valuesClause.append("values ("); //$NON-NLS-1$
-
- ColumnDefinition identityColumn = null;
- boolean comma = false;
- Iterator iter = introspectedTable.getAllColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
-
- if (cd.isIdentity()) {
- identityColumn = cd;
- // cannot set values on identity fields
- continue;
- }
-
- if (comma) {
- insertClause.append(", "); //$NON-NLS-1$
- valuesClause.append(", "); //$NON-NLS-1$
- } else {
- comma = true; // turn on comma for next time
- }
-
- insertClause.append(cd.getColumnName());
- valuesClause.append(cd.getIbatisFormattedParameterClause());
- }
- insertClause.append(')');
- valuesClause.append(')');
-
- answer.addElement(new TextElement(insertClause.toString()));
- answer.addElement(new TextElement(valuesClause.toString()));
-
- if (gk != null && identityColumn != null) {
- answer.addElement(getSelectKey(identityColumn, gk));
- }
-
- return answer;
- }
-
- /**
- * This method should return an XmlElement for the update by primary
- * key statement that updates all fields in the table (including BLOB
- * fields).
- *
- * @param introspectedTable
- * introspected table
- * @return the update element
- */
- protected XmlElement getUpdateByPrimaryKeyWithBLOBs(IntrospectedTable introspectedTable) {
-
- XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
-
- FullyQualifiedTable table = introspectedTable.getTable();
- answer.addAttribute(new Attribute("id", getUpdateByPrimaryKeyWithBLOBsStatementId())); //$NON-NLS-1$
- answer.addAttribute(new Attribute("parameterClass", javaModelGenerator //$NON-NLS-1$
- .getRecordWithBLOBsType(table)
- .getFullyQualifiedName()));
-
- answer.addComment();
-
- StringBuffer sb = new StringBuffer();
-
- sb.append("update "); //$NON-NLS-1$
- sb.append(table.getFullyQualifiedTableName());
- answer.addElement(new TextElement(sb.toString()));
-
- // set up for first column
- sb.setLength(0);
- sb.append("set "); //$NON-NLS-1$
-
- Iterator iter = introspectedTable.getNonPrimaryKeyColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
-
- sb.append(cd.getColumnName());
- sb.append(" = "); //$NON-NLS-1$
- sb.append(cd.getIbatisFormattedParameterClause());
-
- 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;
- iter = introspectedTable.getPrimaryKeyColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
-
- sb.setLength(0);
- if (and) {
- sb.append(" and "); //$NON-NLS-1$
- } else {
- sb.append("where "); //$NON-NLS-1$
- and = true;
- }
-
- sb.append(cd.getColumnName());
- sb.append(" = #"); //$NON-NLS-1$
- sb.append(cd.getJavaProperty());
- sb.append('#');
- answer.addElement(new TextElement(sb.toString()));
- }
-
- return answer;
- }
-
- /**
- * This method should return an XmlElement for the update by primary
- * key statement that updates all fields in the table (excluding BLOB
- * fields).
- *
- * @param introspectedTable
- * introspected table
- * @return the update element
- */
- protected XmlElement getUpdateByPrimaryKey(IntrospectedTable introspectedTable) {
-
- XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
-
- FullyQualifiedTable table = introspectedTable.getTable();
- answer.addAttribute(new Attribute("id", getUpdateByPrimaryKeyStatementId())); //$NON-NLS-1$
- answer.addAttribute(new Attribute("parameterClass", javaModelGenerator //$NON-NLS-1$
- .getRecordType(table)
- .getFullyQualifiedName()));
-
- answer.addComment();
-
- StringBuffer sb = new StringBuffer();
- sb.append("update "); //$NON-NLS-1$
- sb.append(table.getFullyQualifiedTableName());
- answer.addElement(new TextElement(sb.toString()));
-
- // set up for first column
- sb.setLength(0);
- sb.append("set "); //$NON-NLS-1$
-
- Iterator iter = introspectedTable.getNonBLOBColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
-
- sb.append(cd.getColumnName());
- sb.append(" = "); //$NON-NLS-1$
- sb.append(cd.getIbatisFormattedParameterClause());
-
- 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;
- iter = introspectedTable.getPrimaryKeyColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
-
- sb.setLength(0);
- if (and) {
- sb.append(" and "); //$NON-NLS-1$
- } else {
- sb.append("where "); //$NON-NLS-1$
- and = true;
- }
-
- sb.append(cd.getColumnName());
- sb.append(" = "); //$NON-NLS-1$
- sb.append(cd.getIbatisFormattedParameterClause());
- answer.addElement(new TextElement(sb.toString()));
- }
-
- return answer;
- }
-
- /**
- * This method should return an XmlElement for the delete by primary
- * key statement.
- *
- * @param introspectedTable
- * introspected table
- * @return the delete element
- */
- protected XmlElement getDeleteByPrimaryKey(IntrospectedTable introspectedTable) {
- XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$
-
- FullyQualifiedTable table = introspectedTable.getTable();
- answer.addAttribute(new Attribute("id", getDeleteByPrimaryKeyStatementId())); //$NON-NLS-1$
- answer.addAttribute(new Attribute("parameterClass", javaModelGenerator //$NON-NLS-1$
- .getPrimaryKeyType(table)
- .getFullyQualifiedName()));
-
- answer.addComment();
-
- StringBuffer sb = new StringBuffer();
- sb.append("delete from "); //$NON-NLS-1$
- sb.append(table.getFullyQualifiedTableName());
- answer.addElement(new TextElement(sb.toString()));
-
- boolean and = false;
- Iterator iter = introspectedTable.getPrimaryKeyColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
-
- sb.setLength(0);
- if (and) {
- sb.append(" and "); //$NON-NLS-1$
- } else {
- sb.append("where "); //$NON-NLS-1$
- and = true;
- }
-
- sb.append(cd.getColumnName());
- sb.append(" = "); //$NON-NLS-1$
- sb.append(cd.getIbatisFormattedParameterClause());
- answer.addElement(new TextElement(sb.toString()));
- }
-
- return answer;
}
/**
@@ -658,7 +48,6 @@
* statement. This statement uses the "by example" SQL fragment
*
* @param introspectedTable
- * introspected table
* @return the delete element
*/
protected XmlElement getDeleteByExample(IntrospectedTable introspectedTable) {
@@ -690,309 +79,10 @@
}
/**
- * This method should return an XmlElement for the select by primary
- * key statement. The statement should include all fields in the table,
- * including BLOB fields.
- *
- * @param introspectedTable
- * introspected table
- * @return the select element
- */
- protected XmlElement getSelectByPrimaryKey(IntrospectedTable introspectedTable) {
-
- XmlElement answer = new XmlElement("select"); //$NON-NLS-1$
-
- FullyQualifiedTable table = introspectedTable.getTable();
- answer.addAttribute(new Attribute("id", getSelectByPrimaryKeyStatementId())); //$NON-NLS-1$
- if (AbatorRules.generateResultMapWithBLOBs(introspectedTable)) {
- answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
- getResultMapName(table) + "WithBLOBs")); //$NON-NLS-1$
- } else {
- answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
- getResultMapName(table)));
- }
- answer.addAttribute(new Attribute("parameterClass", javaModelGenerator //$NON-NLS-1$
- .getPrimaryKeyType(table)
- .getFullyQualifiedName()));
-
- answer.addComment();
-
- StringBuffer sb = new StringBuffer();
- sb.append("select "); //$NON-NLS-1$
-
- boolean comma = false;
- if (StringUtility.stringHasValue(introspectedTable.getSelectByPrimaryKeyQueryId())) {
- sb.append('\'');
- sb.append(introspectedTable.getSelectByPrimaryKeyQueryId());
- sb.append("' as QUERYID"); //$NON-NLS-1$
- comma = true;
- }
-
- Iterator iter = introspectedTable.getAllColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (comma) {
- sb.append(", "); //$NON-NLS-1$
- } else {
- comma = true;
- }
-
- sb.append(cd.getSelectListPhrase());
- }
-
- answer.addElement(new TextElement(sb.toString()));
-
- sb.setLength(0);
- sb.append("from "); //$NON-NLS-1$
- sb.append(table.getAliasedFullyQualifiedTableName());
- answer.addElement(new TextElement(sb.toString()));
-
- boolean and = false;
- iter = introspectedTable.getPrimaryKeyColumns();
- while (iter.hasNext()) {
- ColumnDefinition cd = (ColumnDefinition) iter.next();
-
- sb.setLength(0);
- if (and) {
- sb.append(" and "); //$NON-NLS-1$
- } else {
- sb.append("where "); //$NON-NLS-1$
- and = true;
- }
-
- sb.append(cd.getAliasedColumnName());
-
- sb.append(" = "); //$NON-NLS-1$
- sb.append(cd.getIbatisFormattedParameterClause());
- answer.addElement(new TextElement(sb.toString()));
- }
-
- return answer;
- }
-
- /**
- * This method should return an XmlElement for the select key
- * used to automatically generate keys.
- *
- * @param columnDefinition generated key column
- * @param generatedKey the generated key configuration element for this table
- * @return the selectKey element
- */
- protected XmlElement getSelectKey(ColumnDefinition columnDefinition, GeneratedKey generatedKey) {
- String identityColumnType = columnDefinition.getResolvedJavaType()
- .getFullyQualifiedJavaType().getFullyQualifiedName();
-
- XmlElement answer = new XmlElement("selectKey"); //$NON-NLS-1$
- answer.addAttribute(new Attribute("resultClass", identityColumnType)); //$NON-NLS-1$
- answer.addAttribute(new Attribute(
- "keyProperty", columnDefinition.getJavaProperty())); //$NON-NLS-1$
- answer.addElement(new TextElement(generatedKey.getSqlStatement()));
-
- return answer;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getSqlMapNamespace(org.apache.ibatis.abator.config.FullyQualifiedTable)
- */
- public String getSqlMapNamespace(FullyQualifiedTable table) {
- String key = "getSqlMapNamespace"; //$NON-NLS-1$
- String s;
-
- Map map = getTableStringMap(table);
- s = (String) map.get(key);
- if (s == null) {
- s = table.getFullyQualifiedTableNameWithUnderscores();
- map.put(key, s);
- }
-
- return s;
- }
-
- /**
- * Calculates the name of the result map. Typically this is the String
- * "abatorgenerated_XXXXResult" where XXXX is the name of the domain object
- * related to this table. The prefix "abatorgenerated_" is important because
- * it allows Abator to regenerate this element on subsequent runs.
- *
- * @param table
- * the current table
- * @return the name of the result map
- */
- protected String getResultMapName(FullyQualifiedTable table) {
- String key = "getResultMapName"; //$NON-NLS-1$
- String s;
-
- Map map = getTableStringMap(table);
- s = (String) map.get(key);
- if (s == null) {
- StringBuffer sb = new StringBuffer();
-
- sb.append("abatorgenerated_"); //$NON-NLS-1$
- sb.append(table.getDomainObjectName());
- sb.append("Result"); //$NON-NLS-1$
-
- s = sb.toString();
- map.put(key, s);
- }
-
- return s;
- }
-
- /**
- * Calculates a file name for the current table. Typically the name is
- * "XXXX_SqlMap.xml" where XXXX is the fully qualified table name (delimited
- * with underscores).
- *
- * @param table
- * the current table
- * @return tha name of the SqlMap file
- */
- protected String getSqlMapFileName(FullyQualifiedTable table) {
- String key = "getSqlMapFileName"; //$NON-NLS-1$
- String s;
-
- Map map = getTableStringMap(table);
- s = (String) map.get(key);
- if (s == null) {
- StringBuffer sb = new StringBuffer();
- sb.append(table.getFullyQualifiedTableNameWithUnderscores());
-
- sb.append("_SqlMap.xml"); //$NON-NLS-1$
-
- s = sb.toString();
- map.put(key, s);
- }
-
- return s;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getDeleteByPrimaryKeyStatementId()
- */
- public String getDeleteByPrimaryKeyStatementId() {
- return "abatorgenerated_deleteByPrimaryKey"; //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getDeleteByExampleStatementId()
- */
- public String getDeleteByExampleStatementId() {
- return "abatorgenerated_deleteByExample"; //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getInsertStatementId()
- */
- public String getInsertStatementId() {
- return "abatorgenerated_insert"; //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getSelectByPrimaryKeyStatementId()
- */
- public String getSelectByPrimaryKeyStatementId() {
- return "abatorgenerated_selectByPrimaryKey"; //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getSelectByExampleStatementId()
- */
- public String getSelectByExampleStatementId() {
- return "abatorgenerated_selectByExample"; //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getSelectByExampleWithBLOBsStatementId()
- */
- public String getSelectByExampleWithBLOBsStatementId() {
- return "abatorgenerated_selectByExampleWithBLOBs"; //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getUpdateByPrimaryKeyWithBLOBsStatementId()
- */
- public String getUpdateByPrimaryKeyWithBLOBsStatementId() {
- return "abatorgenerated_updateByPrimaryKeyWithBLOBs"; //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getUpdateByPrimaryKeyStatementId()
- */
- public String getUpdateByPrimaryKeyStatementId() {
- return "abatorgenerated_updateByPrimaryKey"; //$NON-NLS-1$
- }
-
- /**
- * Calculates the package for the current table.
- *
- * @param table
- * the current table
- * @return the package for the SqlMap for the current table
- */
- protected String getSqlMapPackage(FullyQualifiedTable table) {
- String key = "getSqlMapPackage"; //$NON-NLS-1$
- String s;
-
- Map map = getTableStringMap(table);
- s = (String) map.get(key);
- if (s == null) {
- if ("true".equals(properties.get("enableSubPackages"))) { //$NON-NLS-1$ //$NON-NLS-2$
- StringBuffer sb = new StringBuffer(targetPackage);
-
- if (StringUtility.stringHasValue(table.getCatalog())) {
- sb.append('.');
- sb.append(table.getCatalog().toLowerCase());
- }
-
- if (StringUtility.stringHasValue(table.getSchema())) {
- sb.append('.');
- sb.append(table.getSchema().toLowerCase());
- }
-
- s = sb.toString();
- } else {
- s = targetPackage;
- }
-
- map.put(key, s);
- }
-
- return s;
- }
-
- /**
- * Calculates the name of the example where clause element
- *
- * @return the name of the example where clause element
- */
- protected String getExampleWhereClauseId() {
- return "abatorgenerated_Example_Where_Clause"; //$NON-NLS-1$
- }
-
- /**
* This method should return an XmlElement for the example where clause
* SQL fragment (an sql fragment).
*
* @param introspectedTable
- * introspected table
* @return a well formatted String containing the SQL element
*/
protected XmlElement getByExampleWhereClauseFragment(IntrospectedTable introspectedTable) {
@@ -1006,15 +96,10 @@
XmlElement dynamicElement = new XmlElement("dynamic"); //$NON-NLS-1$
dynamicElement.addAttribute(new Attribute("prepend", "where")); //$NON-NLS-1$ //$NON-NLS-2$
- Iterator iter = introspectedTable.getAllColumns();
+ Iterator iter = introspectedTable.getNonBLOBColumns();
while (iter.hasNext()) {
ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (cd.isBLOBColumn()) {
- // don't generate select by example clauses for BLOBs
- continue;
- }
-
Iterator clauseIterator = ExampleClause.getAllExampleClauses();
while (clauseIterator.hasNext()) {
ExampleClause ec = (ExampleClause) clauseIterator.next();
@@ -1047,7 +132,6 @@
* statement that returns all fields in the table (except BLOB fields).
*
* @param introspectedTable
- * introspected table
* @return the select element
*/
protected XmlElement getSelectByExample(IntrospectedTable introspectedTable) {
@@ -1073,15 +157,10 @@
comma = true;
}
- Iterator iter = introspectedTable.getAllColumns();
+ Iterator iter = introspectedTable.getNonBLOBColumns();
while (iter.hasNext()) {
ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (cd.isBLOBColumn()) {
- // don't return BLOBs in select be examples
- continue;
- }
-
if (comma) {
sb.append(", "); //$NON-NLS-1$
} else {
@@ -1116,7 +195,6 @@
* statement that returns all fields in the table (including BLOB fields).
*
* @param introspectedTable
- * introspected table
* @return the select element
*/
protected XmlElement getSelectByExampleWithBLOBs(IntrospectedTable introspectedTable) {
@@ -1173,23 +251,5 @@
answer.addElement(isPropAvail);
return answer;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#setTargetProject(java.lang.String)
- */
- public void setTargetProject(String targetProject) {
- this.targetProject = targetProject;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#setWarnings(java.util.List)
- */
- public void setWarnings(List warnings) {
- this.warnings = warnings;
}
}
Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/sqlmap/SqlMapGeneratorIterateImpl.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/sqlmap/SqlMapGeneratorIterateImpl.java?rev=428963&r1=428962&r2=428963&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/sqlmap/SqlMapGeneratorIterateImpl.java (original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/sqlmap/SqlMapGeneratorIterateImpl.java Fri Aug 4 22:19:13 2006
@@ -35,7 +35,6 @@
import org.apache.ibatis.abator.api.dom.xml.XmlElement;
import org.apache.ibatis.abator.config.GeneratedKey;
import org.apache.ibatis.abator.internal.db.ColumnDefinition;
-import org.apache.ibatis.abator.internal.rules.AbatorRules;
import org.apache.ibatis.abator.internal.util.StringUtility;
import org.apache.ibatis.abator.internal.util.messages.Messages;
@@ -121,10 +120,8 @@
}
/*
- * (non-Javadoc)
- *
- * @see org.apache.ibatis.abator.api.SqlMapGenerator#getGeneratedXMLFiles(org.apache.ibatis.abator.internal.db.IntrospectedTable,
- * org.apache.ibatis.abator.api.ProgressCallback)
+ * (non-Javadoc)
+ * @see org.apache.ibatis.abator.api.SqlMapGenerator#getGeneratedXMLFiles(org.apache.ibatis.abator.api.IntrospectedTable, org.apache.ibatis.abator.api.ProgressCallback)
*/
public List getGeneratedXMLFiles(IntrospectedTable introspectedTable,
ProgressCallback callback) {
@@ -143,7 +140,6 @@
* Creates the default implementation of the Sql Map
*
* @param introspectedTable
- * the introspected table
* @return A GeneratedXMLFile for the current table
*/
protected GeneratedXmlFile getSqlMap(IntrospectedTable introspectedTable) {
@@ -164,7 +160,6 @@
* Creates the sqlMap element (the root element, and all child elements).
*
* @param introspectedTable
- * the introspected table
* @return the sqlMap element including all child elements
*/
protected XmlElement getSqlMapElement(IntrospectedTable introspectedTable) {
@@ -175,79 +170,78 @@
getSqlMapNamespace(table)));
XmlElement element;
- if (AbatorRules.generateResultMapWithoutBLOBs(introspectedTable)) {
+ if (introspectedTable.getRules().generateBaseResultMap()) {
element = getBaseResultMapElement(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateResultMapWithBLOBs(introspectedTable)) {
+ if (introspectedTable.getRules().generateResultMapWithBLOBs()) {
element = getResultMapWithBLOBsElement(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateSQLExampleWhereClause(introspectedTable)) {
+ if (introspectedTable.getRules().generateSQLExampleWhereClause()) {
element = getByExampleWhereClauseFragment(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateSelectByPrimaryKey(introspectedTable)) {
+ if (introspectedTable.getRules().generateSelectByPrimaryKey()) {
element = getSelectByPrimaryKey(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateSelectByExampleWithoutBLOBs(introspectedTable)) {
+ if (introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) {
element = getSelectByExample(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateSelectByExampleWithBLOBs(introspectedTable)) {
+ if (introspectedTable.getRules().generateSelectByExampleWithBLOBs()) {
element = getSelectByExampleWithBLOBs(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateDeleteByPrimaryKey(introspectedTable)) {
+ if (introspectedTable.getRules().generateDeleteByPrimaryKey()) {
element = getDeleteByPrimaryKey(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateDeleteByExample(introspectedTable)) {
+ if (introspectedTable.getRules().generateDeleteByExample()) {
element = getDeleteByExample(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateInsert(introspectedTable)) {
+ if (introspectedTable.getRules().generateInsert()) {
element = getInsertElement(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules.generateUpdateByPrimaryKeyWithBLOBs(introspectedTable)) {
+ if (introspectedTable.getRules().generateUpdateByPrimaryKeyWithBLOBs()) {
element = getUpdateByPrimaryKeyWithBLOBs(introspectedTable);
if (element != null) {
answer.addElement(element);
}
}
- if (AbatorRules
- .generateUpdateByPrimaryKeyWithoutBLOBs(introspectedTable)) {
- element = getUpdateByPrimaryKey(introspectedTable);
+ if (introspectedTable.getRules().generateUpdateByPrimaryKeyWithoutBLOBs()) {
+ element = getUpdateByPrimaryKeyWithoutBLOBs(introspectedTable);
if (element != null) {
answer.addElement(element);
}
@@ -261,34 +255,29 @@
* any BLOBs if they exist in the table).
*
* @param introspectedTable
- * the introspected table
* @return the resultMap element
*/
- protected XmlElement getBaseResultMapElement(
- IntrospectedTable introspectedTable) {
+ protected XmlElement getBaseResultMapElement(IntrospectedTable introspectedTable) {
XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$
FullyQualifiedTable table = introspectedTable.getTable();
answer.addAttribute(new Attribute("id", //$NON-NLS-1$
getResultMapName(table)));
- if (AbatorRules.generateBaseRecordWithNoSuperclass(introspectedTable)
- || AbatorRules
- .generateBaseRecordExtendingPrimaryKey(introspectedTable)) {
- answer.addAttribute(new Attribute("class", javaModelGenerator //$NON-NLS-1$
- .getRecordType(table).getFullyQualifiedName()));
+ FullyQualifiedJavaType returnType;
+ if (introspectedTable.getRules().generateBaseRecordClass()) {
+ returnType = javaModelGenerator.getBaseRecordType(table);
} else {
- answer.addAttribute(new Attribute("class", javaModelGenerator //$NON-NLS-1$
- .getPrimaryKeyType(table).getFullyQualifiedName()));
+ returnType = javaModelGenerator.getPrimaryKeyType(table);
}
+
+ answer.addAttribute(new Attribute("class", //$NON-NLS-1$
+ returnType.getFullyQualifiedName()));
answer.addComment();
- Iterator iter = introspectedTable.getAllColumns();
+ Iterator iter = introspectedTable.getNonBLOBColumns();
while (iter.hasNext()) {
ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (cd.isBLOBColumn()) {
- continue;
- }
XmlElement resultElement = new XmlElement("result"); //$NON-NLS-1$
@@ -316,11 +305,9 @@
* base result map.
*
* @param introspectedTable
- * the introspected table
* @return the resultMap element
*/
- protected XmlElement getResultMapWithBLOBsElement(
- IntrospectedTable introspectedTable) {
+ protected XmlElement getResultMapWithBLOBsElement(IntrospectedTable introspectedTable) {
XmlElement answer = new XmlElement("resultMap"); //$NON-NLS-1$
FullyQualifiedTable table = introspectedTable.getTable();
@@ -330,8 +317,18 @@
sb.append("WithBLOBs"); //$NON-NLS-1$
answer.addAttribute(new Attribute("id", sb.toString())); //$NON-NLS-1$
- answer.addAttribute(new Attribute("class", javaModelGenerator //$NON-NLS-1$
- .getRecordWithBLOBsType(table).getFullyQualifiedName()));
+
+ FullyQualifiedJavaType returnType;
+ if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
+ returnType = javaModelGenerator.getRecordWithBLOBsType(table);
+ } else {
+ // table has BLOBs, but no BLOB class - BLOB fields must be
+ // in the base class
+ returnType = javaModelGenerator.getBaseRecordType(table);
+ }
+
+ answer.addAttribute(new Attribute("class", //$NON-NLS-1$
+ returnType.getFullyQualifiedName()));
sb.setLength(0);
sb.append(getSqlMapNamespace(table));
@@ -341,12 +338,9 @@
answer.addComment();
- Iterator iter = introspectedTable.getAllColumns();
+ Iterator iter = introspectedTable.getBLOBColumns();
while (iter.hasNext()) {
ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (!cd.isBLOBColumn()) {
- continue;
- }
XmlElement resultElement = new XmlElement("result"); //$NON-NLS-1$
@@ -372,35 +366,20 @@
* This method should return an XmlElement which the insert statement.
*
* @param introspectedTable
- * the introspected table
* @return the insert element
*/
protected XmlElement getInsertElement(IntrospectedTable introspectedTable) {
-
+
XmlElement answer = new XmlElement("insert"); //$NON-NLS-1$
FullyQualifiedTable table = introspectedTable.getTable();
answer.addAttribute(new Attribute("id", getInsertStatementId())); //$NON-NLS-1$
- if (AbatorRules
- .generateRecordWithBLOBsExtendingPrimaryKey(introspectedTable)
- || AbatorRules
- .generateRecordWithBLOBsExtendingBaseRecord(introspectedTable)) {
- answer.addAttribute(new Attribute(
- "parameterClass", javaModelGenerator //$NON-NLS-1$
- .getRecordWithBLOBsType(table)
- .getFullyQualifiedName()));
- } else if (AbatorRules
- .generateBaseRecordWithNoSuperclass(introspectedTable)
- || AbatorRules
- .generateBaseRecordExtendingPrimaryKey(introspectedTable)) {
- answer.addAttribute(new Attribute(
- "parameterClass", javaModelGenerator //$NON-NLS-1$
- .getRecordType(table).getFullyQualifiedName()));
- } else {
- answer.addAttribute(new Attribute(
- "parameterClass", javaModelGenerator //$NON-NLS-1$
- .getPrimaryKeyType(table).getFullyQualifiedName()));
- }
+
+ FullyQualifiedJavaType parameterType =
+ introspectedTable.getRules().calculateAllFieldsClass(javaModelGenerator, table);
+
+ answer.addAttribute(new Attribute("parameterClass", //$NON-NLS-1$
+ parameterType.getFullyQualifiedName()));
answer.addComment();
@@ -465,19 +444,26 @@
* statement that updates all fields in the table (including BLOB fields).
*
* @param introspectedTable
- * the introspected table
* @return the update element
*/
- protected XmlElement getUpdateByPrimaryKeyWithBLOBs(
- IntrospectedTable introspectedTable) {
+ protected XmlElement getUpdateByPrimaryKeyWithBLOBs(IntrospectedTable introspectedTable) {
XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
FullyQualifiedTable table = introspectedTable.getTable();
answer.addAttribute(new Attribute(
"id", getUpdateByPrimaryKeyWithBLOBsStatementId())); //$NON-NLS-1$
- answer.addAttribute(new Attribute("parameterClass", javaModelGenerator //$NON-NLS-1$
- .getRecordWithBLOBsType(table).getFullyQualifiedName()));
+
+ FullyQualifiedJavaType parameterType;
+
+ if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
+ parameterType = javaModelGenerator.getRecordWithBLOBsType(table);
+ } else {
+ parameterType = javaModelGenerator.getBaseRecordType(table);
+ }
+
+ answer.addAttribute(new Attribute("parameterClass", //$NON-NLS-1$
+ parameterType.getFullyQualifiedName()));
answer.addComment();
@@ -540,19 +526,17 @@
* statement that updates all fields in the table (excluding BLOB fields).
*
* @param introspectedTable
- * the introspected table
* @return the update element
*/
- protected XmlElement getUpdateByPrimaryKey(
- IntrospectedTable introspectedTable) {
+ protected XmlElement getUpdateByPrimaryKeyWithoutBLOBs(IntrospectedTable introspectedTable) {
XmlElement answer = new XmlElement("update"); //$NON-NLS-1$
FullyQualifiedTable table = introspectedTable.getTable();
answer.addAttribute(new Attribute(
"id", getUpdateByPrimaryKeyStatementId())); //$NON-NLS-1$
- answer.addAttribute(new Attribute("parameterClass", javaModelGenerator //$NON-NLS-1$
- .getRecordType(table).getFullyQualifiedName()));
+ answer.addAttribute(new Attribute("parameterClass", //$NON-NLS-1$
+ javaModelGenerator.getBaseRecordType(table).getFullyQualifiedName()));
answer.addComment();
@@ -565,7 +549,7 @@
sb.setLength(0);
sb.append("set "); //$NON-NLS-1$
- Iterator iter = introspectedTable.getNonBLOBColumns();
+ Iterator iter = introspectedTable.getBaseColumns();
while (iter.hasNext()) {
ColumnDefinition cd = (ColumnDefinition) iter.next();
@@ -613,19 +597,23 @@
* statement.
*
* @param introspectedTable
- * the introspected table
* @return the delete element
*/
- protected XmlElement getDeleteByPrimaryKey(
- IntrospectedTable introspectedTable) {
+ protected XmlElement getDeleteByPrimaryKey(IntrospectedTable introspectedTable) {
XmlElement answer = new XmlElement("delete"); //$NON-NLS-1$
FullyQualifiedTable table = introspectedTable.getTable();
answer.addAttribute(new Attribute(
"id", getDeleteByPrimaryKeyStatementId())); //$NON-NLS-1$
- answer.addAttribute(new Attribute("parameterClass", javaModelGenerator //$NON-NLS-1$
- .getPrimaryKeyType(table).getFullyQualifiedName()));
+ FullyQualifiedJavaType parameterClass;
+ if (introspectedTable.getRules().generatePrimaryKeyClass()) {
+ parameterClass = javaModelGenerator.getPrimaryKeyType(table);
+ } else {
+ parameterClass = javaModelGenerator.getBaseRecordType(table);
+ }
+ answer.addAttribute(new Attribute("parameterClass", //$NON-NLS-1$
+ parameterClass.getFullyQualifiedName()));
answer.addComment();
@@ -661,7 +649,6 @@
* statement. This statement uses the "by example" SQL fragment
*
* @param introspectedTable
- * the introspected table
* @return the delete by example element
*/
protected XmlElement getDeleteByExample(IntrospectedTable introspectedTable) {
@@ -703,26 +690,34 @@
* including BLOB fields.
*
* @param introspectedTable
- * the introspected table
* @return the select by primary key element
*/
- protected XmlElement getSelectByPrimaryKey(
- IntrospectedTable introspectedTable) {
+ protected XmlElement getSelectByPrimaryKey(IntrospectedTable introspectedTable) {
XmlElement answer = new XmlElement("select"); //$NON-NLS-1$
FullyQualifiedTable table = introspectedTable.getTable();
answer.addAttribute(new Attribute(
"id", getSelectByPrimaryKeyStatementId())); //$NON-NLS-1$
- if (AbatorRules.generateResultMapWithBLOBs(introspectedTable)) {
+ if (introspectedTable.getRules().generateResultMapWithBLOBs()) {
answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
getResultMapName(table) + "WithBLOBs")); //$NON-NLS-1$
} else {
answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
getResultMapName(table)));
}
- answer.addAttribute(new Attribute("parameterClass", javaModelGenerator //$NON-NLS-1$
- .getPrimaryKeyType(table).getFullyQualifiedName()));
+
+ FullyQualifiedJavaType parameterType;
+ if (introspectedTable.getRules().generatePrimaryKeyClass()) {
+ parameterType = javaModelGenerator.getPrimaryKeyType(table);
+ } else {
+ // select by primary key, but no primary key class. Fields
+ // must be in the base record
+ parameterType = javaModelGenerator.getBaseRecordType(table);
+ }
+
+ answer.addAttribute(new Attribute("parameterClass", //$NON-NLS-1$
+ parameterType.getFullyQualifiedName()));
answer.addComment();
@@ -1002,8 +997,7 @@
* This method should return an XmlElement for the example where clause SQL
* fragment (an sql fragment).
*
- * @param introspectedTable the current table for which the where clause
- * should be generated
+ * @param introspectedTable
* @return the SQL element
*/
protected XmlElement getByExampleWhereClauseFragment(IntrospectedTable introspectedTable) {
@@ -1078,12 +1072,9 @@
// if any of the columns have a user defined type handler, then we need
// to add additional inner iterate elements that specify the type handler
- Iterator iter = introspectedTable.getAllColumns();
+ Iterator iter = introspectedTable.getNonBLOBColumns();
while (iter.hasNext()) {
ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (cd.isBLOBColumn()) {
- continue;
- }
if (StringUtility.stringHasValue(cd.getTypeHandler())) {
// name the property based on the column name, then
@@ -1204,7 +1195,6 @@
* returns all fields in the table (except BLOB fields).
*
* @param introspectedTable
- * the introspected table
* @return the select element
*/
protected XmlElement getSelectByExample(IntrospectedTable introspectedTable) {
@@ -1235,15 +1225,10 @@
comma = true;
}
- Iterator iter = introspectedTable.getAllColumns();
+ Iterator iter = introspectedTable.getNonBLOBColumns();
while (iter.hasNext()) {
ColumnDefinition cd = (ColumnDefinition) iter.next();
- if (cd.isBLOBColumn()) {
- // don't return BLOBs in select be examples
- continue;
- }
-
if (comma) {
sb.append(", "); //$NON-NLS-1$
} else {
@@ -1279,11 +1264,9 @@
* statement that returns all fields in the table (including BLOB fields).
*
* @param introspectedTable
- * the introspected table
* @return the select element
*/
- protected XmlElement getSelectByExampleWithBLOBs(
- IntrospectedTable introspectedTable) {
+ protected XmlElement getSelectByExampleWithBLOBs(IntrospectedTable introspectedTable) {
FullyQualifiedTable table = introspectedTable.getTable();
FullyQualifiedJavaType fqjt = javaModelGenerator.getExampleType(table);
Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/AggregatingIterator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/AggregatingIterator.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/AggregatingIterator.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/AggregatingIterator.java Fri Aug 4 22:19:13 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2006 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.abator.internal.util;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * This class implements an iterator that combines two or three other
+ * iterators together. This iterator does not support the remove function.
+ *
+ * @author Jeff Butler
+ *
+ */
+public class AggregatingIterator implements Iterator {
+ private Iterator iterator1;
+ private Iterator iterator2;
+ private Iterator iterator3;
+
+ /**
+ *
+ */
+ public AggregatingIterator(Iterator iterator1, Iterator iterator2, Iterator iterator3) {
+ super();
+
+ this.iterator1 = iterator1 == null ? new NullIterator() : iterator1;
+ this.iterator2 = iterator2 == null ? new NullIterator() : iterator2;
+ this.iterator3 = iterator3 == null ? new NullIterator() : iterator3;
+ }
+
+ public AggregatingIterator(Iterator iterator1, Iterator iterator2) {
+ this(iterator1, iterator2, null);
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return iterator1.hasNext()
+ || iterator2.hasNext()
+ || iterator3.hasNext();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ if (iterator1.hasNext()) {
+ return iterator1.next();
+ } else if (iterator2.hasNext()) {
+ return iterator2.next();
+ } else if (iterator3.hasNext()) {
+ return iterator3.next();
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public static class NullIterator implements Iterator {
+ public boolean hasNext() {
+ return false;
+ }
+
+ public Object next() {
+ throw new NoSuchElementException();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+}