com.github.gkutiel.store.Temp Maven / Gradle / Ivy
package com.github.gkutiel.store;
import java.lang.reflect.Field;
import java.util.List;
public class Temp {
public static String insert(final boolean hasKey, final String tableName, final int valueCounts) {
final StringBuilder insert = new StringBuilder();
insert.append(hasKey ? "MERGE" : "INSERT");
insert.append(" INTO ");
insert.append(tableName);
insert.append(" VALUES(?");
for (int i = 0; i < valueCounts; i++)
insert.append(",?");
insert.append(")");
return insert.toString();
}
public static String table(final String tableName, final List fs, final String[] primaryKey) {
final StringBuilder table = new StringBuilder();
table.append("CREATE TABLE IF NOT EXISTS ");
table.append(tableName);
table.append(" (_obj VARCHAR(8192)");
for (final Field f : fs) {
table.append(",");
table.append(f.getName());
table.append(" ");
table.append(Java2Sql.toSql(f.getType()));
}
if (primaryKey != null && primaryKey.length > 0) {
table.append(",PRIMARY KEY (");
table.append(primaryKey[0]);
for (int i = 1; i < primaryKey.length; i++) {
table.append(",");
table.append(primaryKey[i]);
}
table.append(")");
}
table.append(")");
return table.toString();
}
}