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,22 +50,22 @@ import org.apache.openjpa.util.MultiLoaderClassResolver;
* <li><code>schemaFile</code></li>
* <li><code>sqlFile</code></li>
* <li><code>sqlEncode</code></li>
* <li><code>sqlTerminator</code></li>
* <li><code>tmpClassLoader</code></li>
* </ul> Of these arguments, only <code>action</code> is required.
*/
public class MappingToolTask
extends AbstractTask {
private static final Localizer _loc = Localizer.forPackage
(MappingToolTask.class);
private static final Localizer _loc = Localizer.forPackage(MappingToolTask.class);
protected MappingTool.Flags flags = new MappingTool.Flags();
protected String file = null;
protected String schemaFile = null;
protected String sqlFile = null;
protected String sqlEncode = null;
protected String file;
protected String schemaFile;
protected String sqlFile;
protected String sqlEncode;
protected boolean tmpClassLoader = true;
/**
* Set the enumerated MappingTool action type.
*/
@ -170,6 +170,14 @@ public class MappingToolTask
public void setSQLEncode(String 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.

View File

@ -100,8 +100,7 @@ public class MappingTool
ACTION_IMPORT,
};
private static final Localizer _loc =
Localizer.forPackage(MappingTool.class);
private static final Localizer _loc = Localizer.forPackage(MappingTool.class);
private final JDBCConfiguration _conf;
private final Log _log;
@ -499,6 +498,7 @@ public class MappingTool
tool.setDropSequences(flags.dropSequences);
tool.setWriter(flags.sqlWriter);
tool.setOpenJPATables(flags.openjpaTables);
tool.setSQLTerminator(flags.sqlTerminator);
}
tool.setSchemaGroup(getSchemaGroup());
@ -980,6 +980,7 @@ public class MappingTool
String schemaFileName = opts.removeProperty("schemaFile", "sf", null);
String sqlFileName = opts.removeProperty("sqlFile", "sql", null);
String sqlEncoding = opts.removeProperty("sqlEncode", "se", null);
String sqlTerminator = opts.removeProperty("sqlTerminator", "st", ";");
String schemas = opts.removeProperty("s");
if (schemas != null)
opts.setProperty("schemas", schemas);
@ -996,7 +997,7 @@ public class MappingTool
flags.sqlWriter = Files.getWriter(sqlFileName, loader, sqlEncoding);
else
flags.sqlWriter = Files.getWriter(sqlFileName, loader);
flags.sqlTerminator = sqlTerminator;
return run(conf, args, flags, loader);
}
@ -1133,6 +1134,7 @@ public class MappingTool
public boolean primaryKeys = false;
public boolean foreignKeys = 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_IMPORT = "import";
public static final String ACTION_EXPORT = "export";
public static final String ACTION_DELETE_TABLE_CONTENTS =
"deleteTableContents";
public static final String ACTION_DELETE_TABLE_CONTENTS = "deleteTableContents";
public static final String[] ACTIONS = new String[]{
ACTION_ADD,
@ -91,8 +90,7 @@ public class SchemaTool {
ACTION_DELETE_TABLE_CONTENTS,
};
private static final Localizer _loc = Localizer.forPackage
(SchemaTool.class);
private static final Localizer _loc = Localizer.forPackage(SchemaTool.class);
private final JDBCConfiguration _conf;
private final DataSource _ds;
@ -111,7 +109,8 @@ public class SchemaTool {
private SchemaGroup _group = null;
private SchemaGroup _db = null;
private boolean _fullDB = false;
private String _sqlTerminator = ";";
/**
* Default constructor. Tools constructed this way will not have an
* action, so the {@link #run()} method will be a no-op.
@ -309,6 +308,10 @@ public class SchemaTool {
else
_writer = new PrintWriter(writer);
}
public void setSQLTerminator(String t) {
_sqlTerminator = t;
}
/**
* Return the schema group the tool will act on.
@ -1251,7 +1254,7 @@ public class SchemaTool {
}
} else {
for (int i = 0; i < sql.length; i++)
_writer.println(sql[i] + ";");
_writer.println(sql[i] + _sqlTerminator);
_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
with <literal>-sqlFile</literal> to write the SQL script in a different
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>
</listitem>
<listitem>