in core/src/main/java/site/ycsb/CommandLine.java [61:158]
public static void main(String[] args) {
Properties props = new Properties();
Properties fileprops = new Properties();
parseArguments(args, props, fileprops);
for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
String prop = (String) e.nextElement();
fileprops.setProperty(prop, props.getProperty(prop));
}
props = fileprops;
System.out.println("YCSB Command Line client");
System.out.println("Type \"help\" for command line help");
System.out.println("Start with \"-help\" for usage info");
String table = props.getProperty(CoreWorkload.TABLENAME_PROPERTY, CoreWorkload.TABLENAME_PROPERTY_DEFAULT);
//create a DB
String dbname = props.getProperty(Client.DB_PROPERTY, DEFAULT_DB);
ClassLoader classLoader = CommandLine.class.getClassLoader();
DB db = null;
try {
Class dbclass = classLoader.loadClass(dbname);
db = (DB) dbclass.newInstance();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
db.setProperties(props);
try {
db.init();
} catch (DBException e) {
e.printStackTrace();
System.exit(0);
}
System.out.println("Connected.");
//main loop
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (;;) {
//get user input
System.out.print("> ");
String input = null;
try {
input = br.readLine();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
if (input.compareTo("") == 0) {
continue;
}
if (input.compareTo("help") == 0) {
help();
continue;
}
if (input.compareTo("quit") == 0) {
break;
}
String[] tokens = input.split(" ");
long st = System.currentTimeMillis();
//handle commands
if (tokens[0].compareTo("table") == 0) {
handleTable(tokens, table);
} else if (tokens[0].compareTo("read") == 0) {
handleRead(tokens, table, db);
} else if (tokens[0].compareTo("scan") == 0) {
handleScan(tokens, table, db);
} else if (tokens[0].compareTo("update") == 0) {
handleUpdate(tokens, table, db);
} else if (tokens[0].compareTo("insert") == 0) {
handleInsert(tokens, table, db);
} else if (tokens[0].compareTo("delete") == 0) {
handleDelete(tokens, table, db);
} else {
System.out.println("Error: unknown command \"" + tokens[0] + "\"");
}
System.out.println((System.currentTimeMillis() - st) + " ms");
}
}