| Method from org.apache.openjpa.jdbc.kernel.ValueTableJDBCSeq Detail: |
protected Column addPrimaryKeyColumn(Table table) {
DBDictionary dict = getConfiguration().getDBDictionaryInstance();
Column pkColumn = table.addColumn(dict.getValidColumnName
(getPrimaryKeyColumn(), table));
pkColumn.setType(dict.getPreferredType(Types.VARCHAR));
pkColumn.setJavaType(JavaTypes.STRING);
pkColumn.setSize(dict.characterColumnSize);
return pkColumn;
}
|
protected Object getPrimaryKey(ClassMapping mapping) {
return _value;
}
|
public String getPrimaryKeyValue() {
return _value;
}
The primary key value for this row. Defaults to DEFAULT. |
public static void main(String[] args) throws Exception {
Options opts = new Options();
final String[] arguments = opts.setFromCmdLine(args);
boolean ret = Configurations.runAgainstAllAnchors(opts,
new Configurations.Runnable() {
public boolean run(Options opts) throws Exception {
JDBCConfiguration conf = new JDBCConfigurationImpl();
try {
return ValueTableJDBCSeq.run(conf, arguments, opts);
} finally {
conf.close();
}
}
});
if (!ret)
System.out.println(_loc.get("clstable-seq-usage"));
}
Usage: java org.apache.openjpa.jdbc.kernel.ValueTableJDBCSeq [option]*
-action/-a <add | drop | get | set> [primary key value] [value]
Where the following options are recognized.
- -properties/-p <properties file or resource>: The
path or resource name of a OpenJPA properties file containing
information such as the license key and connection data as
outlined in JDBCConfiguration . Optional.
- -<property name> <property value>: All bean
properties of the OpenJPA JDBCConfiguration can be set by
using their names and supplying a value. For example:
-licenseKey adslfja83r3lkadf
The various actions are as follows.
- add: Create the sequence table.
- drop: Drop the sequence table.
- get: Print the current sequence value for the given
primary key value.
- set: Set the sequence value for the given primary key
value.
|
public static boolean run(JDBCConfiguration conf,
String[] args,
Options opts) throws Exception {
String action = opts.removeProperty("action", "a", null);
Configurations.populateConfiguration(conf, opts);
return run(conf, args, action, null, null);
}
Run the tool. Returns false if invalid options were given. |
public static boolean run(JDBCConfiguration conf,
String[] args,
String action,
MappingRepository repos,
ClassLoader loader) throws Exception {
ValueTableJDBCSeq seq = new ValueTableJDBCSeq();
String props = Configurations.getProperties(conf.getSequence());
Configurations.configureInstance(seq, conf, props);
if (ACTION_DROP.equals(action)) {
if (args.length != 0)
return false;
seq.dropTable();
} else if (ACTION_ADD.equals(action)) {
if (args.length != 0)
return false;
seq.refreshTable();
} else if (ACTION_GET.equals(action) || ACTION_SET.equals(action)) {
if (args.length > 0)
seq.setPrimaryKeyValue(args[0]);
Connection conn = conf.getDataSource2(null).getConnection();
try {
long cur = seq.getSequence(null, conn);
if (ACTION_GET.equals(action))
System.out.println(seq.getPrimaryKeyValue() + ": " + cur);
else {
long set;
if (args.length > 1)
set = Long.parseLong(args[1]);
else
set = cur + seq.getAllocate();
if (set < cur)
set = cur;
else {
Status stat = seq.getStatus(null);
seq.setSequence(null, stat, (int) (set - cur), true,
conn);
set = stat.seq;
}
System.err.println(seq.getPrimaryKeyValue() + ": " + set);
}
}
catch (NumberFormatException nfe) {
return false;
} finally {
try {
conn.close();
} catch (SQLException se) {
}
}
} else
return false;
return true;
}
Run the tool. Return false if an invalid option was given. |
public void setPrimaryKeyValue(String value) {
_value = value;
}
The primary key value for this row. Defaults to DEFAULT. |