2014-02-12 02:37:31 +00:00
|
|
|
package org.servalproject.test;
|
|
|
|
|
2014-02-23 23:27:51 +00:00
|
|
|
import org.servalproject.servaldna.IJniResults;
|
2014-02-12 02:37:31 +00:00
|
|
|
import org.servalproject.servaldna.ServalDCommand;
|
2014-02-23 23:27:51 +00:00
|
|
|
import org.servalproject.servaldna.ServalDFailureException;
|
2014-02-12 02:37:31 +00:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
class ServalDTests
|
|
|
|
{
|
2014-02-23 23:27:51 +00:00
|
|
|
public static int printCommand(final String fieldDelim, final String rowDelim, String... args) throws ServalDFailureException {
|
|
|
|
return ServalDCommand.command(new IJniResults() {
|
|
|
|
int columns = -1;
|
|
|
|
int column = -1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startResultSet(int columns) {
|
|
|
|
this.columns = columns;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setColumnName(int column, String name) {
|
|
|
|
System.out.print(name + fieldDelim);
|
|
|
|
if (column >= 0 && column + 1 == columns)
|
|
|
|
System.out.println();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void eol() {
|
|
|
|
if (columns == -1 || ++column == columns) {
|
|
|
|
System.out.print(rowDelim);
|
|
|
|
column = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void putString(String value) {
|
|
|
|
System.out.print(value);
|
|
|
|
eol();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void putBlob(byte[] value) {
|
|
|
|
System.out.print(new String(value));
|
|
|
|
eol();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void putLong(long value) {
|
|
|
|
System.out.print(value);
|
|
|
|
eol();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void putDouble(double value) {
|
|
|
|
System.out.print(value);
|
|
|
|
eol();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void totalRowCount(int rows) {
|
|
|
|
}
|
|
|
|
}, args);
|
|
|
|
}
|
|
|
|
|
2014-02-19 05:05:08 +00:00
|
|
|
public static void main(String... args)
|
2014-02-12 02:37:31 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
for (int i = 0; i != args.length; ++i)
|
|
|
|
if ("(null)".equals(args[i]))
|
|
|
|
args[i] = null;
|
|
|
|
|
|
|
|
int repeatCount=1;
|
|
|
|
|
|
|
|
if (args[0].equals("repeat")){
|
|
|
|
repeatCount = Integer.decode(args[1]);
|
|
|
|
args = Arrays.copyOfRange(args, 2, args.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(repeatCount>0){
|
2014-02-23 23:27:51 +00:00
|
|
|
printCommand("", " ", args);
|
2014-02-19 05:05:08 +00:00
|
|
|
System.out.println();
|
2014-02-12 02:37:31 +00:00
|
|
|
repeatCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
}
|