OPENJPA-2108: Allow configuration for SQL termination character in Mapping Tool

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1232449 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2012-01-17 15:52:17 +00:00
parent 1a50b5fe76
commit 3c1a262106
4 changed files with 32 additions and 17 deletions

View File

@ -50,20 +50,20 @@ import org.apache.openjpa.util.MultiLoaderClassResolver;
* <li><code>schemaFile</code></li> * <li><code>schemaFile</code></li>
* <li><code>sqlFile</code></li> * <li><code>sqlFile</code></li>
* <li><code>sqlEncode</code></li> * <li><code>sqlEncode</code></li>
* <li><code>sqlTerminator</code></li>
* <li><code>tmpClassLoader</code></li> * <li><code>tmpClassLoader</code></li>
* </ul> Of these arguments, only <code>action</code> is required. * </ul> Of these arguments, only <code>action</code> is required.
*/ */
public class MappingToolTask public class MappingToolTask
extends AbstractTask { extends AbstractTask {
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer.forPackage(MappingToolTask.class);
(MappingToolTask.class);
protected MappingTool.Flags flags = new MappingTool.Flags(); protected MappingTool.Flags flags = new MappingTool.Flags();
protected String file = null; protected String file;
protected String schemaFile = null; protected String schemaFile;
protected String sqlFile = null; protected String sqlFile;
protected String sqlEncode = null; protected String sqlEncode;
protected boolean tmpClassLoader = true; protected boolean tmpClassLoader = true;
/** /**
@ -171,6 +171,14 @@ public class MappingToolTask
this.sqlEncode = sqlEncode; this.sqlEncode = sqlEncode;
} }
/**
* Sets the characters used to terminate a generated SQL.
* By default, a semicolon.
*/
public void setSQLTerminator(String t) {
flags.sqlTerminator = t;
}
/** /**
* Set whether this action applies to metadata as well as mappings. * Set whether this action applies to metadata as well as mappings.
*/ */

View File

@ -100,8 +100,7 @@ public class MappingTool
ACTION_IMPORT, ACTION_IMPORT,
}; };
private static final Localizer _loc = private static final Localizer _loc = Localizer.forPackage(MappingTool.class);
Localizer.forPackage(MappingTool.class);
private final JDBCConfiguration _conf; private final JDBCConfiguration _conf;
private final Log _log; private final Log _log;
@ -499,6 +498,7 @@ public class MappingTool
tool.setDropSequences(flags.dropSequences); tool.setDropSequences(flags.dropSequences);
tool.setWriter(flags.sqlWriter); tool.setWriter(flags.sqlWriter);
tool.setOpenJPATables(flags.openjpaTables); tool.setOpenJPATables(flags.openjpaTables);
tool.setSQLTerminator(flags.sqlTerminator);
} }
tool.setSchemaGroup(getSchemaGroup()); tool.setSchemaGroup(getSchemaGroup());
@ -980,6 +980,7 @@ public class MappingTool
String schemaFileName = opts.removeProperty("schemaFile", "sf", null); String schemaFileName = opts.removeProperty("schemaFile", "sf", null);
String sqlFileName = opts.removeProperty("sqlFile", "sql", null); String sqlFileName = opts.removeProperty("sqlFile", "sql", null);
String sqlEncoding = opts.removeProperty("sqlEncode", "se", null); String sqlEncoding = opts.removeProperty("sqlEncode", "se", null);
String sqlTerminator = opts.removeProperty("sqlTerminator", "st", ";");
String schemas = opts.removeProperty("s"); String schemas = opts.removeProperty("s");
if (schemas != null) if (schemas != null)
opts.setProperty("schemas", schemas); opts.setProperty("schemas", schemas);
@ -996,7 +997,7 @@ public class MappingTool
flags.sqlWriter = Files.getWriter(sqlFileName, loader, sqlEncoding); flags.sqlWriter = Files.getWriter(sqlFileName, loader, sqlEncoding);
else else
flags.sqlWriter = Files.getWriter(sqlFileName, loader); flags.sqlWriter = Files.getWriter(sqlFileName, loader);
flags.sqlTerminator = sqlTerminator;
return run(conf, args, flags, loader); return run(conf, args, flags, loader);
} }
@ -1133,6 +1134,7 @@ public class MappingTool
public boolean primaryKeys = false; public boolean primaryKeys = false;
public boolean foreignKeys = false; public boolean foreignKeys = false;
public boolean indexes = false; public boolean indexes = false;
public String sqlTerminator = ";";
} }
/** /**

View File

@ -74,8 +74,7 @@ public class SchemaTool {
public static final String ACTION_DROPDB = "dropDB"; public static final String ACTION_DROPDB = "dropDB";
public static final String ACTION_IMPORT = "import"; public static final String ACTION_IMPORT = "import";
public static final String ACTION_EXPORT = "export"; public static final String ACTION_EXPORT = "export";
public static final String ACTION_DELETE_TABLE_CONTENTS = public static final String ACTION_DELETE_TABLE_CONTENTS = "deleteTableContents";
"deleteTableContents";
public static final String[] ACTIONS = new String[]{ public static final String[] ACTIONS = new String[]{
ACTION_ADD, ACTION_ADD,
@ -91,8 +90,7 @@ public class SchemaTool {
ACTION_DELETE_TABLE_CONTENTS, ACTION_DELETE_TABLE_CONTENTS,
}; };
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer.forPackage(SchemaTool.class);
(SchemaTool.class);
private final JDBCConfiguration _conf; private final JDBCConfiguration _conf;
private final DataSource _ds; private final DataSource _ds;
@ -111,6 +109,7 @@ public class SchemaTool {
private SchemaGroup _group = null; private SchemaGroup _group = null;
private SchemaGroup _db = null; private SchemaGroup _db = null;
private boolean _fullDB = false; private boolean _fullDB = false;
private String _sqlTerminator = ";";
/** /**
* Default constructor. Tools constructed this way will not have an * Default constructor. Tools constructed this way will not have an
@ -310,6 +309,10 @@ public class SchemaTool {
_writer = new PrintWriter(writer); _writer = new PrintWriter(writer);
} }
public void setSQLTerminator(String t) {
_sqlTerminator = t;
}
/** /**
* Return the schema group the tool will act on. * Return the schema group the tool will act on.
*/ */
@ -1251,7 +1254,7 @@ public class SchemaTool {
} }
} else { } else {
for (int i = 0; i < sql.length; i++) for (int i = 0; i < sql.length; i++)
_writer.println(sql[i] + ";"); _writer.println(sql[i] + _sqlTerminator);
_writer.flush(); _writer.flush();
} }

View File

@ -125,7 +125,9 @@ mappings, even if the schema already exists.
<literal>-sqlEncode/-se &lt;encoding&gt;</literal>: Use this option <literal>-sqlEncode/-se &lt;encoding&gt;</literal>: Use this option
with <literal>-sqlFile</literal> to write the SQL script in a different with <literal>-sqlFile</literal> to write the SQL script in a different
Java character set encoding than the default JVM locale, such as Java character set encoding than the default JVM locale, such as
<literal>UTF-8</literal>. <literal>-sqlTerminator/-st &lt;terminal&gt;</literal>: Use this option
with <literal>-sqlFile</literal> to write the SQL terminating with a
different character instead of a semicolon.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>