Author: jgbutler Date: Sat Dec 6 20:56:51 2008 New Revision: 724075 URL: http://svn.apache.org/viewvc?rev=724075&view=rev Log: [ibator] improvements to progress reporting
Modified: ibatis/trunk/java/tools/ibator/core/build/build.xml ibatis/trunk/java/tools/ibator/core/build/version.properties ibatis/trunk/java/tools/ibator/core/htmldoc/migratingFromAbator.html ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/ant/AntProgressCallback.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/JavaTypeResolver.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/IntrospectedTableIbatis2Java2Impl.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/DAOGenerator.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/AbstractDAOTemplate.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/RecordWithBLOBsGenerator.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/SqlMapGenerator.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/NullProgressCallback.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties Modified: ibatis/trunk/java/tools/ibator/core/build/build.xml URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/build.xml?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/build/build.xml (original) +++ ibatis/trunk/java/tools/ibator/core/build/build.xml Sat Dec 6 20:56:51 2008 @@ -232,7 +232,7 @@ classname="org.apache.ibatis.ibator.ant.IbatorAntTask" classpathref="emma.runtime.path"/> - <ibator configfile="${basedir}/../testJava2/ibatortest/java2/ibatorConfig.xml" > + <ibator configfile="${basedir}/../testJava2/ibatortest/java2/ibatorConfig.xml" verbose="true"> <propertyset> <propertyref name="generated.source.dir.java2"/> </propertyset> @@ -261,7 +261,7 @@ <echo message="Expect three warnings from ibator (BLOBSONLY, NonExistantTable, FRED)" /> - <ibator configfile="${basedir}/../testJava5/ibatortest/ibatorConfig.xml" > + <ibator configfile="${basedir}/../testJava5/ibatortest/ibatorConfig.xml" verbose="true"> <propertyset> <propertyref name="generated.source.dir.java5"/> <propertyref name="generated.bin.dir.java5"/> Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/build/version.properties (original) +++ ibatis/trunk/java/tools/ibator/core/build/version.properties Sat Dec 6 20:56:51 2008 @@ -1,4 +1,4 @@ #ibator build version info -#Thu Nov 27 07:43:20 CST 2008 +#Sat Dec 06 16:47:44 CST 2008 version=1.2.0 -buildNum=642 +buildNum=647 Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/migratingFromAbator.html URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/migratingFromAbator.html?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/htmldoc/migratingFromAbator.html (original) +++ ibatis/trunk/java/tools/ibator/core/htmldoc/migratingFromAbator.html Sat Dec 6 20:56:51 2008 @@ -63,7 +63,7 @@ page for full details.</li> <li>The <code>JavaTypeResolver</code> interface has changed and is simplified. If you specified a custom implementation on the - <javaTypeResolver> element, you must rework your implementation + <code><javaTypeResolver></code> element, you must rework your implementation class.</li> <li>The ibator classloading strategy has changed substantially, and we now recommend that you manage the runtime classpath external to ibator. If you manage the classpath with @@ -79,6 +79,8 @@ element.</li> </ul> </li> + <li>The <cde>ProgressCallback</code> interface has changed significantly. If you implemented + this interface for some other execution environment, you will need to rework your implementation.</li> </ul> </body> </html> \ No newline at end of file Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html (original) +++ ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html Sat Dec 6 20:56:51 2008 @@ -70,7 +70,7 @@ to determine many of the rules for code generation.</p> <p>Ibator supplies two implementations of introspected table. The implementation is chosen bases on the value of the <code>targetRuntime</code> attribute of the -<code><ibatorContext></code> element. In many cases it will be fer simpler +<code><ibatorContext></code> element. In many cases it will be far simpler to extend one of the built in implementations, rather than creating an implementation from scratch. The following table shows the built in implementations:</p> <table cellspacing="0" cellpadding="5" border="1"> Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/ant/AntProgressCallback.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/ant/AntProgressCallback.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/ant/AntProgressCallback.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/ant/AntProgressCallback.java Sat Dec 6 20:56:51 2008 @@ -16,7 +16,7 @@ package org.apache.ibatis.ibator.ant; -import org.apache.ibatis.ibator.api.ProgressCallback; +import org.apache.ibatis.ibator.internal.NullProgressCallback; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -26,7 +26,7 @@ * @author Jeff Butler * */ -public class AntProgressCallback implements ProgressCallback { +public class AntProgressCallback extends NullProgressCallback { private Task task; private boolean verbose; @@ -40,30 +40,10 @@ this.verbose = verbose; } - /* (non-Javadoc) - * @see org.apache.ibatis.ibator.api.ProgressCallback#setNumberOfSubTasks(int) - */ - public void setNumberOfSubTasks(int totalSubTasks) { - } - - /* (non-Javadoc) - * @see org.apache.ibatis.ibator.api.ProgressCallback#startSubTask(java.lang.String) - */ - public void startSubTask(String subTaskName) { + @Override + public void startTask(String subTaskName) { if (verbose) { task.log(subTaskName, Project.MSG_VERBOSE); } } - - /* (non-Javadoc) - * @see org.apache.ibatis.ibator.api.ProgressCallback#finished() - */ - public void finished() { - } - - /* (non-Javadoc) - * @see org.apache.ibatis.ibator.api.ProgressCallback#checkCancel() - */ - public void checkCancel() throws InterruptedException { - } } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java Sat Dec 6 20:56:51 2008 @@ -112,14 +112,14 @@ /** * This is the main method for generating code. This method is long running, but - * progress can be provided and the method can be cancelled through the ProgressCallback + * progress can be provided and the method can be canceled through the ProgressCallback * interface. This version of the method runs all configured contexts. * * @param callback an instance of the ProgressCallback interface, or <code>null</code> * if you do not require progress information * @throws SQLException * @throws IOException - * @throws InterruptedException if the method is cancelled through the ProgressCallback + * @throws InterruptedException if the method is canceled through the ProgressCallback */ public void generate(ProgressCallback callback) throws SQLException, IOException, InterruptedException { @@ -128,7 +128,7 @@ /** * This is the main method for generating code. This method is long running, but - * progress can be provided and the method can be cancelled through the ProgressCallback + * progress can be provided and the method can be canceled through the ProgressCallback * interface. * * @param callback an instance of the ProgressCallback interface, or <code>null</code> @@ -139,7 +139,7 @@ * @throws InvalidConfigurationException * @throws SQLException * @throws IOException - * @throws InterruptedException if the method is cancelled through the ProgressCallback + * @throws InterruptedException if the method is canceled through the ProgressCallback */ public void generate(ProgressCallback callback, Set<String> contextIds) throws SQLException, IOException, InterruptedException { @@ -165,7 +165,7 @@ * @throws InvalidConfigurationException * @throws SQLException * @throws IOException - * @throws InterruptedException if the method is cancelled through the ProgressCallback + * @throws InterruptedException if the method is canceled through the ProgressCallback */ public void generate(ProgressCallback callback, Set<String> contextIds, Set<String> fullyQualifiedTableNames) throws SQLException, IOException, InterruptedException { @@ -190,15 +190,6 @@ } } - int totalSteps = 0; - - // TODO... -// for (IbatorContext ibatorContext : contextsToRun) { -// totalSteps += ibatorContext.getTotalSteps(); -// } - - callback.setNumberOfSubTasks(totalSteps); - // setup custom classloader if required if (ibatorConfiguration.getClassPathEntries().size() > 0) { ClassLoader classLoader = @@ -206,12 +197,31 @@ IbatorObjectFactory.setExternalClassLoader(classLoader); } - // now run the generates... + // now run the introspections... + int totalSteps = 0; for (IbatorContext ibatorContext : contextsToRun) { - ibatorContext.generateFiles(callback, generatedJavaFiles, - generatedXmlFiles, warnings, fullyQualifiedTableNames); + totalSteps += ibatorContext.getIntrospectionSteps(); } - + callback.introspectionStarted(totalSteps); + + for (IbatorContext ibatorContext : contextsToRun) { + ibatorContext.introspectTables(callback, warnings, fullyQualifiedTableNames); + } + + // now run the generates + totalSteps = 0; + for (IbatorContext ibatorContext : contextsToRun) { + totalSteps += ibatorContext.getGenerationSteps(); + } + callback.generationStarted(totalSteps); + + for (IbatorContext ibatorContext : contextsToRun) { + ibatorContext.generateFiles(callback, generatedJavaFiles, generatedXmlFiles, warnings); + } + + // now save the files + callback.saveStarted(generatedXmlFiles.size() + generatedJavaFiles.size()); + for (GeneratedXmlFile gxf : generatedXmlFiles) { projects.add(gxf.getTargetProject()); @@ -237,6 +247,8 @@ continue; } + callback.checkCancel(); + callback.startTask(Messages.getString("Progress.15", targetFile.getName())); //$NON-NLS-1$ writeFile(targetFile, source); } @@ -266,16 +278,20 @@ } else { source = gjf.getFormattedContent(); } - + + callback.checkCancel(); + callback.startTask(Messages.getString("Progress.15", targetFile.getName())); //$NON-NLS-1$ writeFile(targetFile, source); } catch (ShellException e) { warnings.add(e.getMessage()); } } - + for (String project : projects) { shellCallback.refreshProject(project); } + + callback.done(); } /** Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java Sat Dec 6 20:56:51 2008 @@ -483,4 +483,12 @@ * @return true if the generated code makes use of Java5 features */ public abstract boolean isJava5Targeted(); + + /** + * This method should return the number of progress messages that + * will be send during the generation phase. + * + * @return the number of progress messages + */ + public abstract int getGenerationSteps(); } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/JavaTypeResolver.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/JavaTypeResolver.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/JavaTypeResolver.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/JavaTypeResolver.java Sat Dec 6 20:56:51 2008 @@ -68,8 +68,9 @@ * * @param introspectedColumn the column whose Java type needs to be * calculated - * @return true the calculated type, or null if an unsupported data type. If null, - * the column should be set to Object type and a warning will be issued. + * @return true the calculated type, or null if an unsupported data type. If null + * is returned, ibator will set the type to Object and issue a warning + * unless the column is ignored or otherwise overridden */ FullyQualifiedJavaType calculateJavaType(IntrospectedColumn introspectedColumn); } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java Sat Dec 6 20:56:51 2008 @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation + * Copyright 2008 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. @@ -17,47 +17,80 @@ /** * This interface can be implemented to return progress information from the file generation - * process. This interface is loosely based on the standard Eclipse IProgressMonitor interface, - * but does not implement all its methods. + * process. * - * During the execution of a long running method, ibator will call the - * <code>setNumberOfSubTasks</code> method first, and then repeatedly call <code>startSubTask</code. - * When the long running method is complete, ibator will call <code>finished</code>. - * Periodically, ibator will call <code>checkCancel</code> to see if the method should + * During the execution of code generation, there are three main operations: + * database introspection, code generation based on the results of + * introspection, and then merging/saving generated files. + * Ibator will call methods in this interface accordingly and in this order: + * <ol> + * <li>introspectionStarted(int)</li> + * <li>(Repeatedly) startTask(String)</li> + * <li>generationStarted(int)</li> + * <li>(Repeatedly) startTask(String)</li> + * <li>saveStarted(int)</li> + * <li>(Repeatedly) startTask(String)</li> + * <li>done()</li> + * </ol> + * <p> + * Periodically, ibator will call <code>checkCancel()</code> to see if the method should * be canceled. + * <p> + * For planning purposes, the most common use case will have a ratio + * of 20% instrospection tasks, 40% generation tasks, and 40% save tasks. * * @author Jeff Butler */ public interface ProgressCallback { /** - * Called to designate the maximum number of startSubTask messages that will be sent. - * It is not guaranteed that this number startSubTask messages will be sent. The - * actual number of messages depends on the objects generated from each table. + * Called to note the start of the introspection phase, and to note the + * maximum number of startTask messages that will be sent for the introspection + * phase. * - * @param totalSubTasks + * @param totalTasks the maximum number of times startTask will be called for + * the introspection phase. */ + void introspectionStarted(int totalTasks); - void setNumberOfSubTasks(int totalSubTasks); + /** + * Called to note the start of the generation phase, and to note the + * maximum number of startTask messages that will be sent for the generation + * phase. + * + * @param totalTasks the maximum number of times startTask will be called for + * the generation phase. + */ + void generationStarted(int totalTasks); /** - * Called to denote the beginning of another task + * Called to note the start of the file saving phase, and to note the + * maximum number of startTask messages that will be sent for the + * file saving phase phase. * - * @param subTaskName a descriptive name of the current work step + * @param totalTasks the maximum number of times startTask will be called for + * the file saving phase. */ - void startSubTask(String subTaskName); + void saveStarted(int totalTasks); /** - * ibator calls this method when all subtasks are finished + * Called to denote the beginning of a save task + * + * @param taskName a descriptive name of the current work step */ - void finished(); - + void startTask(String taskName); + + /** + * ibator calls this method when all generated files have been saved + */ + void done(); + /** * ibator will call this method periodically during a long running method. - * If the the implementation throws InterruptedException, then the method + * If the the implementation throws <code>InterruptedException</code> then the method * will be canceled. Any files that have already been saved will remain on * the file system. * - * @throws InterruptedException if the main task should finish + * @throws InterruptedException if the operation should be halted */ void checkCancel() throws InterruptedException; } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java Sat Dec 6 20:56:51 2008 @@ -18,7 +18,6 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Set; @@ -33,7 +32,6 @@ import org.apache.ibatis.ibator.api.dom.xml.XmlElement; import org.apache.ibatis.ibator.internal.IbatorObjectFactory; import org.apache.ibatis.ibator.internal.IbatorPluginAggregator; -import org.apache.ibatis.ibator.internal.NullProgressCallback; import org.apache.ibatis.ibator.internal.db.ConnectionFactory; import org.apache.ibatis.ibator.internal.db.DatabaseIntrospector; import org.apache.ibatis.ibator.internal.util.StringUtility; @@ -335,19 +333,59 @@ return pluginAggregator; } + public String getTargetRuntime() { + return targetRuntime; + } + + public void setTargetRuntime(String targetRuntime) { + this.targetRuntime = targetRuntime; + } + + public String getIntrospectedColumnImpl() { + return introspectedColumnImpl; + } + + public void setIntrospectedColumnImpl(String introspectedColumnImpl) { + this.introspectedColumnImpl = introspectedColumnImpl; + } + + public boolean getSuppressTypeWarnings(IntrospectedTable introspectedTable) { + return suppressTypeWarnings && !introspectedTable.isJava5Targeted(); + } + + // methods related to code generation. + // + // Methods should be called in this order: + // + // 1. getIntrospectionSteps() + // 2. introspectTables() + // 3. getGenerationSteps() + // 4. generateFiles() + // + + private List<IntrospectedTable> introspectedTables; + + public int getIntrospectionSteps() { + int steps = 0; + + steps++; // connect to database + + // for each table: + // + // 1. Create introspected table implementation + + steps += tableConfigurations.size() * 1; + + return steps; + } + /** - * Generate iBATIS artifacts based on the configuration specified in the + * Introspect tables based on the configuration specified in the * constructor. This method is long running. * * @param callback * a progress callback if progress information is desired, or * <code>null</code> - * @param generatedJavaFiles - * any Java file generated from this method will be added to - * the List The objects will be of type GeneratedJavaFile. - * @param generatedXmlFiles - * any XML file generated from this method will be added to - * the List. The objects will be of type GeneratedXMLFile. * @param warnings * any warning generated from this method will be added to * the List. Warnings are always Strings. @@ -362,166 +400,133 @@ * @throws SQLException * if some error arises while introspecting the specified * database tables. - * * @throws InterruptedException * if the progress callback reports a cancel */ - public void generateFiles(ProgressCallback callback, - List<GeneratedJavaFile> generatedJavaFiles, - List<GeneratedXmlFile> generatedXmlFiles, + public void introspectTables(ProgressCallback callback, List<String> warnings, Set<String> fullyQualifiedTableNames) - throws SQLException, InterruptedException { - IbatorEngine ibatorEngine = new IbatorEngine(); - ibatorEngine.generateFiles(callback, generatedJavaFiles, generatedXmlFiles, warnings, fullyQualifiedTableNames); - } - - private class IbatorEngine { - public void generateFiles(ProgressCallback callback, - List<GeneratedJavaFile> generatedJavaFiles, - List<GeneratedXmlFile> generatedXmlFiles, - List<String> warnings, Set<String> fullyQualifiedTableNames) - throws SQLException, InterruptedException { - - if (callback == null) { - callback = new NullProgressCallback(); - } - - JavaTypeResolver javaTypeResolver = IbatorObjectFactory - .createJavaTypeResolver(IbatorContext.this, warnings); - pluginAggregator = new IbatorPluginAggregator(); - for (IbatorPluginConfiguration ibatorPluginConfiguration : pluginConfigurations) { - IbatorPlugin plugin = IbatorObjectFactory.createIbatorPlugin( - IbatorContext.this, ibatorPluginConfiguration); - if (plugin.validate(warnings)) { - pluginAggregator.addPlugin(plugin); - } else { - warnings.add(Messages.getString( - "Warning.24", //$NON-NLS-1$ - ibatorPluginConfiguration.getConfigurationType(), - id)); - } - } - - Connection connection = null; + throws SQLException, InterruptedException { - try { - callback.startSubTask(Messages.getString("Progress.0")); //$NON-NLS-1$ - connection = getConnection(); - - DatabaseIntrospector databaseIntrospector = new DatabaseIntrospector( - IbatorContext.this, connection.getMetaData(), javaTypeResolver, - warnings); - - for (TableConfiguration tc : tableConfigurations) { - String tableName = StringUtility - .composeFullyQualifiedTableName(tc.getCatalog(), tc - .getSchema(), tc.getTableName(), '.'); - - if (fullyQualifiedTableNames != null - && fullyQualifiedTableNames.size() > 0) { - if (!fullyQualifiedTableNames.contains(tableName)) { - continue; - } - } - - if (!tc.areAnyStatementsEnabled()) { - warnings - .add(Messages.getString("Warning.0", tableName)); //$NON-NLS-1$ + introspectedTables = new ArrayList<IntrospectedTable>(); + JavaTypeResolver javaTypeResolver = IbatorObjectFactory + .createJavaTypeResolver(IbatorContext.this, warnings); + + Connection connection = null; + + try { + callback.startTask(Messages.getString("Progress.0")); //$NON-NLS-1$ + connection = getConnection(); + + DatabaseIntrospector databaseIntrospector = new DatabaseIntrospector( + IbatorContext.this, connection.getMetaData(), javaTypeResolver, + warnings); + + for (TableConfiguration tc : tableConfigurations) { + String tableName = StringUtility + .composeFullyQualifiedTableName(tc.getCatalog(), tc + .getSchema(), tc.getTableName(), '.'); + + if (fullyQualifiedTableNames != null + && fullyQualifiedTableNames.size() > 0) { + if (!fullyQualifiedTableNames.contains(tableName)) { continue; } + } - Collection<? extends IntrospectedTable> introspectedTables; - callback.startSubTask(Messages.getString( - "Progress.1", tableName)); //$NON-NLS-1$ - introspectedTables = databaseIntrospector - .introspectTables(tc); - callback.checkCancel(); - - if (introspectedTables != null) { - for (IntrospectedTable introspectedTable : introspectedTables) { - callback.checkCancel(); - - introspectedTable.calculateGenerators(warnings, callback); - generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles()); - generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles()); - - generatedJavaFiles - .addAll(pluginAggregator - .contextGenerateAdditionalJavaFiles(introspectedTable)); - generatedXmlFiles - .addAll(pluginAggregator - .contextGenerateAdditionalXmlFiles(introspectedTable)); - } - } + if (!tc.areAnyStatementsEnabled()) { + warnings + .add(Messages.getString("Warning.0", tableName)); //$NON-NLS-1$ + continue; } - generatedJavaFiles.addAll(pluginAggregator - .contextGenerateAdditionalJavaFiles()); - generatedXmlFiles.addAll(pluginAggregator - .contextGenerateAdditionalXmlFiles()); - } finally { - closeConnection(connection); - callback.finished(); + callback.startTask(Messages.getString( + "Progress.1", tableName)); //$NON-NLS-1$ + List<IntrospectedTable> tables = databaseIntrospector.introspectTables(tc); + + if (tables != null) { + introspectedTables.addAll(tables); + } + + callback.checkCancel(); } + } finally { + closeConnection(connection); } + + for (IntrospectedTable introspectedTable : introspectedTables) { + introspectedTable.calculateGenerators(warnings, callback); + } + } - public int getTotalSteps() { - int steps = 0; - - steps++; // connect to database - - // for each table: - // - // 1. Introspect - // 2. Generate Example - // 3. Generate Primary Key - // 4. Generate Record - // 5. Generate Record with BLOBs - // 6. Generate SQL Map - // 7. Generate DAO Interface - // 8. Generate DAO Implementation + public int getGenerationSteps() { + int steps = 0; - steps += tableConfigurations.size() * 8; + if (introspectedTables != null) { + for (IntrospectedTable introspectedTable : introspectedTables) { + steps += introspectedTable.getGenerationSteps(); + } + } + + return steps; + } + + public void generateFiles(ProgressCallback callback, + List<GeneratedJavaFile> generatedJavaFiles, + List<GeneratedXmlFile> generatedXmlFiles, + List<String> warnings) + throws InterruptedException { - return steps; + pluginAggregator = new IbatorPluginAggregator(); + for (IbatorPluginConfiguration ibatorPluginConfiguration : pluginConfigurations) { + IbatorPlugin plugin = IbatorObjectFactory.createIbatorPlugin( + IbatorContext.this, ibatorPluginConfiguration); + if (plugin.validate(warnings)) { + pluginAggregator.addPlugin(plugin); + } else { + warnings.add(Messages.getString( + "Warning.24", //$NON-NLS-1$ + ibatorPluginConfiguration.getConfigurationType(), + id)); + } } - private Connection getConnection() throws SQLException { - Connection connection = ConnectionFactory.getInstance() - .getConnection(jdbcConnectionConfiguration); + if (introspectedTables != null) { + for (IntrospectedTable introspectedTable : introspectedTables) { + callback.checkCancel(); - return connection; - } + generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles()); + generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles()); - private void closeConnection(Connection connection) { - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - // ignore - ; - } + generatedJavaFiles + .addAll(pluginAggregator + .contextGenerateAdditionalJavaFiles(introspectedTable)); + generatedXmlFiles + .addAll(pluginAggregator + .contextGenerateAdditionalXmlFiles(introspectedTable)); } } - } - public String getTargetRuntime() { - return targetRuntime; + generatedJavaFiles.addAll(pluginAggregator + .contextGenerateAdditionalJavaFiles()); + generatedXmlFiles.addAll(pluginAggregator + .contextGenerateAdditionalXmlFiles()); } - public void setTargetRuntime(String targetRuntime) { - this.targetRuntime = targetRuntime; - } + private Connection getConnection() throws SQLException { + Connection connection = ConnectionFactory.getInstance() + .getConnection(jdbcConnectionConfiguration); - public String getIntrospectedColumnImpl() { - return introspectedColumnImpl; + return connection; } - public void setIntrospectedColumnImpl(String introspectedColumnImpl) { - this.introspectedColumnImpl = introspectedColumnImpl; - } - - public boolean getSuppressTypeWarnings(IntrospectedTable introspectedTable) { - return suppressTypeWarnings && !introspectedTable.isJava5Targeted(); + private void closeConnection(Connection connection) { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + // ignore + ; + } + } } } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/IntrospectedTableIbatis2Java2Impl.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/IntrospectedTableIbatis2Java2Impl.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/IntrospectedTableIbatis2Java2Impl.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/IntrospectedTableIbatis2Java2Impl.java Sat Dec 6 20:56:51 2008 @@ -170,4 +170,11 @@ public boolean isJava5Targeted() { return false; } + + @Override + public int getGenerationSteps() { + return javaModelGenerators.size() + + daoGenerators.size() + + 1; // 1 for the sqlMapGenerator + } } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/DAOGenerator.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/DAOGenerator.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/DAOGenerator.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/DAOGenerator.java Sat Dec 6 20:56:51 2008 @@ -69,7 +69,7 @@ public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); - progressCallback.startSubTask(Messages.getString("Progress.14", table.toString())); + progressCallback.startGenerationTask(Messages.getString("Progress.14", table.toString())); TopLevelClass topLevelClass = getTopLevelClassShell(); Interface interfaze = getInterfaceShell(); Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/AbstractDAOTemplate.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/AbstractDAOTemplate.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/AbstractDAOTemplate.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/AbstractDAOTemplate.java Sat Dec 6 20:56:51 2008 @@ -27,6 +27,10 @@ import org.apache.ibatis.ibator.api.dom.java.Parameter; /** + * Base class for DAO templates. Subclasses should override + * any of the configureXXX methods to specify the unique properties + * of the desired DAO objects. + * * @author Jeff Butler */ public abstract class AbstractDAOTemplate { @@ -281,24 +285,180 @@ } } - // TODO - fully document each of these methods - protected void configureCheckedExceptions() { - } - protected void configureFields() { - } - protected void configureImplementationImports() { - } - protected void configureInterfaceImports() { - } - protected void configureMethods() { - } - protected void configureSuperClass() { - } + /** + * Override this method to add checked exceptions to the + * throws clause of any generated DAO method. When overriding + * this method, call <code>addCheckedException(FullyQualifiedJavaType)</code> + * one or more times to add checked exception(s) to all generated + * DAO methods. + */ + protected void configureCheckedExceptions() { } + + /** + * Override this method to add fields to any + * generated DAO implementation class. When overriding + * this method, call <code>addField(Field)</code> one + * or more times to add field(s) to the generated + * DAO implementation class. + */ + protected void configureFields() {} + + /** + * Override this method to add imports to + * generated DAO implementation classes. When overriding + * this method, call + * <code>addImplementationImport(FullyQualifiedJavaType)</code> one + * or more times to add import(s) to generated + * DAO implementation classes. + */ + protected void configureImplementationImports() {} + + /** + * Override this method to add imports to + * generated DAO interface classes. When overriding + * this method, call + * <code>addInterfaceImport(FullyQualifiedJavaType)</code> one + * or more times to add import(s) to generated + * DAO interface classes. + */ + protected void configureInterfaceImports() {} + /** + * Override this method to add methods to + * generated DAO implementation classes. When overriding + * this method, call + * <code>addMethod(Method)</code> one + * or more times to add method(s) to generated + * DAO implementation classes. + */ + protected void configureMethods() {} + + /** + * Override this method to set the superclass for any + * generated DAO implementation class. When overriding this + * method call <code>setSuperClass(FullyQualifiedJavaType)</code> + * to set the superclass for generated DAO implementation classes. + */ + protected void configureSuperClass() {} + + /** + * Override this method to configure a constructor for generated + * DAO implementation classes. During code generation, ibator will + * build a new constructor using the visibility, parameters, body lines, + * and exceptions set on the constructor template. When overriding this + * method, call <code>setConstructorTemplate(Method)</code> to + * set the constructor template. + */ + protected abstract void configureConstructorTemplate(); + + /** + * Override this method to configure an insert method template. + * A method template is a string with three substitution + * markers that ibator will fill in when generating code. The + * substitution markers will be: + * <ul> + * <li>{0} - The SqlMap namespace</li> + * <li>{1} - The SqlMap statement id</li> + * <li>{2} - The parameter object</li> + * </ul> + * + * For example, when calling methods in the SqlMapClient interface, + * the template would be: + * + * sqlMapClient.insert(\"{0}.{1}\", {2}); + * + * Overriding methods should call the + * <code>setInsertMethodTemplate(String)</code method to set the + * template. + * + */ protected abstract void configureInsertMethodTemplate(); + + /** + * Override this method to configure a queryForList method template. + * A method template is a string with three substitution + * markers that ibator will fill in when generating code. The + * substitution markers will be: + * <ul> + * <li>{0} - The SqlMap namespace</li> + * <li>{1} - The SqlMap statement id</li> + * <li>{2} - The parameter object</li> + * </ul> + * + * For example, when calling methods in the SqlMapClient interface, + * the template would be: + * + * sqlMapClient.queryForList(\"{0}.{1}\", {2}); + * + * Overriding methods should call the + * <code>setQueryForListMethodTemplate(String)</code method to set the + * template. + */ protected abstract void configureQueryForListMethodTemplate(); + + /** + * Override this method to configure a queryForObject method template. + * A method template is a string with three substitution + * markers that ibator will fill in when generating code. The + * substitution markers will be: + * <ul> + * <li>{0} - The SqlMap namespace</li> + * <li>{1} - The SqlMap statement id</li> + * <li>{2} - The parameter object</li> + * </ul> + * + * For example, when calling methods in the SqlMapClient interface, + * the template would be: + * + * sqlMapClient.queryForObject(\"{0}.{1}\", {2}); + * + * Overriding methods should call the + * <code>setQueryForObjectMethodTemplate(String)</code method to set the + * template. + */ protected abstract void configureQueryForObjectMethodTemplate(); + + /** + * Override this method to configure an update method template. + * A method template is a string with three substitution + * markers that ibator will fill in when generating code. The + * substitution markers will be: + * <ul> + * <li>{0} - The SqlMap namespace</li> + * <li>{1} - The SqlMap statement id</li> + * <li>{2} - The parameter object</li> + * </ul> + * + * For example, when calling methods in the SqlMapClient interface, + * the template would be: + * + * sqlMapClient.update(\"{0}.{1}\", {2}); + * + * Overriding methods should call the + * <code>setUpdateMethodTemplate(String)</code method to set the + * template. + */ protected abstract void configureUpdateMethodTemplate(); - protected abstract void configureConstructorTemplate(); + + /** + * Override this method to configure a delete method template. + * A method template is a string with three substitution + * markers that ibator will fill in when generating code. The + * substitution markers will be: + * <ul> + * <li>{0} - The SqlMap namespace</li> + * <li>{1} - The SqlMap statement id</li> + * <li>{2} - The parameter object</li> + * </ul> + * + * For example, when calling methods in the SqlMapClient interface, + * the template would be: + * + * sqlMapClient.delete(\"{0}.{1}\", {2}); + * + * Overriding methods should call the + * <code>setDeleteMethodTemplate(String)</code method to set the + * template. + */ protected abstract void configureDeleteMethodTemplate(); } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java Sat Dec 6 20:56:51 2008 @@ -44,7 +44,7 @@ public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); - progressCallback.startSubTask(Messages.getString("Progress.8", table.toString())); + progressCallback.startGenerationTask(Messages.getString("Progress.8", table.toString())); IbatorPlugin plugins = ibatorContext.getPlugins(); CommentGenerator commentGenerator = ibatorContext.getCommentGenerator(); Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java Sat Dec 6 20:56:51 2008 @@ -55,7 +55,7 @@ public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); - progressCallback.startSubTask(Messages.getString("Progress.6", table.toString())); + progressCallback.startGenerationTask(Messages.getString("Progress.6", table.toString())); CommentGenerator commentGenerator = ibatorContext.getCommentGenerator(); FullyQualifiedJavaType type = introspectedTable.getExampleType(); Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java Sat Dec 6 20:56:51 2008 @@ -47,7 +47,7 @@ */ public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); - progressCallback.startSubTask(Messages.getString("Progress.7", table.toString())); + progressCallback.startGenerationTask(Messages.getString("Progress.7", table.toString())); IbatorPlugin plugins = ibatorContext.getPlugins(); CommentGenerator commentGenerator = ibatorContext.getCommentGenerator(); Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/RecordWithBLOBsGenerator.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/RecordWithBLOBsGenerator.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/RecordWithBLOBsGenerator.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/RecordWithBLOBsGenerator.java Sat Dec 6 20:56:51 2008 @@ -47,7 +47,7 @@ */ public List<CompilationUnit> getCompilationUnits() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); - progressCallback.startSubTask(Messages.getString("Progress.9", table.toString())); + progressCallback.startGenerationTask(Messages.getString("Progress.9", table.toString())); IbatorPlugin plugins = ibatorContext.getPlugins(); CommentGenerator commentGenerator = ibatorContext.getCommentGenerator(); Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/SqlMapGenerator.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/SqlMapGenerator.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/SqlMapGenerator.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/SqlMapGenerator.java Sat Dec 6 20:56:51 2008 @@ -55,7 +55,7 @@ protected XmlElement getSqlMapElement() { FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable(); - progressCallback.startSubTask(Messages.getString("Progress.12", table.toString())); + progressCallback.startGenerationTask(Messages.getString("Progress.12", table.toString())); XmlElement answer = new XmlElement("sqlMap"); //$NON-NLS-1$ answer.addAttribute(new Attribute("namespace", //$NON-NLS-1$ table.getSqlMapNamespace())); Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/NullProgressCallback.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/NullProgressCallback.java?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/NullProgressCallback.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/NullProgressCallback.java Sat Dec 6 20:56:51 2008 @@ -32,29 +32,15 @@ super(); } - /* - * (non-Javadoc) - * @see org.apache.ibatis.ibator.api.ProgressCallback#finished() - */ - public void finished() { - } + public void generationStarted(int totalTasks) { } - /* - * (non-Javadoc) - * @see org.apache.ibatis.ibator.api.ProgressCallback#checkCancel() - */ - public void checkCancel() throws InterruptedException { - } - - /* (non-Javadoc) - * @see org.apache.ibatis.ibator.api.ProgressCallback#setNumberOfSubTasks(int) - */ - public void setNumberOfSubTasks(int totalSubTasks) { - } + public void introspectionStarted(int totalTasks) { } + + public void saveStarted(int totalTasks) { } + + public void startTask(String taskName) { } - /* (non-Javadoc) - * @see org.apache.ibatis.ibator.api.ProgressCallback#startSubTask(java.lang.String) - */ - public void startSubTask(String subTaskName) { - } + public void checkCancel() throws InterruptedException { } + + public void done() { } } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties?rev=724075&r1=724074&r2=724075&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/util/messages/messages.properties Sat Dec 6 20:56:51 2008 @@ -81,6 +81,7 @@ Progress.12=Generating SQL Map for table {0} Progress.13=Found SQL Statement: {0} Progress.14=Generating DAO Interface and Implementation for table {0} +Progress.15=Saving file {0} Usage.Lines=19 Usage.0=Apache iBATIS ibator - a code generator for iBATIS. Usage: