use of com.helger.genericode.v10.Column in project jaxdb by jaxdb.
the class OracleCompiler method types.
@Override
List<CreateStatement> types(final $Table table, final Map<String, Map<String, String>> tableNameToEnumToOwner) {
final List<CreateStatement> statements = new ArrayList<>();
if (table.getColumn() != null) {
for (final $Column column : table.getColumn()) {
if (column instanceof $Integer) {
final $Integer integer = ($Integer) column;
if (Generator.isAuto(integer)) {
final StringBuilder builder = new StringBuilder();
builder.append("CREATE SEQUENCE ").append(q(getSequenceName(table, integer)));
builder.append(" INCREMENT BY 1");
final String startWith = getAttr("default", integer);
if (startWith != null)
builder.append(" START WITH ").append(startWith);
final String max = getAttr("max", integer);
final Byte precision;
builder.append(" MAXVALUE ");
builder.append(max != null ? max : (precision = getPrecision(integer)) != null ? FastMath.longE10[precision] : Long.MAX_VALUE);
String min = getAttr("min", integer);
if (min == null)
min = startWith;
if (min != null)
builder.append(" MINVALUE ").append(min);
else
builder.append(" NOMINVALUE ");
builder.append(" CYCLE NOCACHE");
statements.add(0, new CreateStatement(builder.toString()));
}
}
}
}
statements.addAll(super.types(table, tableNameToEnumToOwner));
return statements;
}
use of com.helger.genericode.v10.Column in project jaxdb by jaxdb.
the class PostgreSQLCompiler method types.
@Override
List<CreateStatement> types(final $Table table, final Map<String, Map<String, String>> tableNameToEnumToOwner) {
final List<CreateStatement> statements = new ArrayList<>();
if (table.getColumn() != null) {
StringBuilder sql = null;
for (final $Column column : table.getColumn()) {
if (column instanceof $Enum) {
final $Enum type = ($Enum) column;
if (sql == null)
sql = new StringBuilder();
else
sql.setLength(0);
sql.append("CREATE TYPE ").append(q(Dialect.getTypeName(type, tableNameToEnumToOwner))).append(" AS ENUM (");
if (type.getValues$() != null) {
final List<String> enums = Dialect.parseEnum(type.getValues$().text());
final Iterator<String> iterator = enums.iterator();
for (int i = 0; iterator.hasNext(); ++i) {
if (i > 0)
sql.append(", ");
sql.append('\'').append(iterator.next()).append('\'');
}
}
statements.add(0, new CreateStatement(sql.append(')').toString()));
} else if (column instanceof $Integer) {
final $Integer integer = ($Integer) column;
if (Generator.isAuto(integer)) {
final StringBuilder builder = new StringBuilder("CREATE SEQUENCE " + q(getSequenceName(table, integer)));
final String min = getAttr("min", integer);
if (min != null)
builder.append(" MINVALUE ").append(min);
final String max = getAttr("max", integer);
if (max != null)
builder.append(" MAXVALUE ").append(max);
final String _default = getAttr("default", integer);
if (_default != null)
builder.append(" START ").append(_default);
builder.append(" CYCLE");
statements.add(0, new CreateStatement(builder.toString()));
}
}
}
}
statements.addAll(super.types(table, tableNameToEnumToOwner));
return statements;
}
use of com.helger.genericode.v10.Column in project jaxdb by jaxdb.
the class Generator method generate.
private void generate() throws GeneratorExecutionException, IOException {
if (logger.isInfoEnabled())
logger.info("Generating jSQL: " + name);
final File dir = new File(destDir, packageName.replace('.', '/'));
if (!dir.exists() && !dir.mkdirs())
throw new IOException("Unable to create output dir: " + dir.getAbsolutePath());
final StringBuilder out = new StringBuilder(HEADER_COMMENT);
out.append("package ").append(packageName).append(";\n\n");
out.append(getDoc(ddlx.getNormalizedSchema(), 0, '\0', '\n'));
out.append('@').append(SuppressWarnings.class.getName()).append("(\"all\")\n");
out.append('@').append(Generated.class.getName()).append("(value=\"").append(GENERATED_VALUE).append("\", date=\"").append(GENERATED_DATE).append("\")\n");
out.append("public final class ").append(schemaClassSimpleName).append(" extends ").append(Schema.class.getCanonicalName()).append(" {");
final List<Table> tables = ddlx.getNormalizedSchema().getTable();
final SchemaManifest schemaManifest = new SchemaManifest(tables);
final StringBuilder cachedTables = new StringBuilder();
for (final TableMeta tableMeta : schemaManifest.tableNameToTableMeta.values()) {
tableMeta.init(schemaManifest);
if (!tableMeta.isAbstract)
cachedTables.append(tableMeta.classCase).append("(), ");
}
if (cachedTables.length() > 0)
cachedTables.setLength(cachedTables.length() - 2);
final List<$Column> templates = ddlx.getNormalizedSchema().getTemplate();
if (templates != null)
for (final $Column template : templates) if (template instanceof $Enum)
out.append(declareEnumClass(schemaClassName, ($Enum) template, 2)).append('\n');
// First create the abstract entities
for (final TableMeta tableMeta : schemaManifest.tableNameToTableMeta.values()) if (tableMeta.table.getAbstract$().text())
out.append(makeTable(tableMeta)).append('\n');
// Then, in proper inheritance order, the real entities
final List<Table> sortedTables = new ArrayList<>();
for (final TableMeta tableMeta : schemaManifest.tableNameToTableMeta.values()) {
if (!tableMeta.table.getAbstract$().text()) {
sortedTables.add(tableMeta.table);
out.append(makeTable(tableMeta)).append('\n');
}
}
sortedTables.sort(namedComparator);
out.append("\n private static final ").append(String.class.getName()).append("[] names = {");
for (final Table table : sortedTables) out.append('"').append(table.getName$().text()).append("\", ");
out.setCharAt(out.length() - 2, '}');
out.setCharAt(out.length() - 1, ';');
out.append("\n private static final ").append(data.Table.class.getCanonicalName()).append("<?>[] tables = {");
for (final Table table : sortedTables) getClassNameOfTable(out, table).append("(), ");
out.setCharAt(out.length() - 2, '}');
out.setCharAt(out.length() - 1, ';');
out.append('\n');
out.append("\n public static ").append(data.Table.class.getCanonicalName()).append("<?>[] getTables() {");
out.append("\n return tables;");
out.append("\n }\n");
out.append("\n public static ").append(data.Table.class.getCanonicalName()).append("<?> getTable(final ").append(String.class.getName()).append(" name) {");
out.append("\n final int index = ").append(Arrays.class.getName()).append(".binarySearch(names, name);");
out.append("\n return index < 0 ? null : tables[index];");
out.append("\n }\n");
out.append("\n private static final ").append(schemaClassSimpleName).append(" _schema$ = new ").append(schemaClassSimpleName).append("();\n");
out.append("\n static ").append(schemaClassSimpleName).append(" getSchema() {");
out.append("\n return _schema$;");
out.append("\n }\n");
// out.append("\n private static ").append(TableCache.class.getName()).append(" cache;\n");
// out.append("\n public static ").append(TableCache.class.getName()).append(" getRowCache() {");
// out.append("\n return cache;");
// out.append("\n }\n");
// out.append("\n public static void setRowCache(").append(TableCache.class.getName()).append(" cache) {");
// out.append("\n ").append(schemaClassSimpleName).append(".cache = cache;");
// out.append("\n }\n");
out.append("\n private ").append(schemaClassSimpleName).append("() {");
out.append("\n }");
out.append("\n}");
final File javaFile = new File(dir, schemaClassSimpleName + ".java");
Files.write(javaFile.toPath(), out.toString().getBytes());
}
use of com.helger.genericode.v10.Column in project YCSB by brianfrankcooper.
the class GoogleBigtableClient method read.
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
if (debug) {
System.out.println("Doing read from Bigtable columnfamily " + new String(columnFamilyBytes));
System.out.println("Doing read for key: " + key);
}
setTable(table);
RowFilter filter = RowFilter.newBuilder().setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)).build();
if (fields != null && fields.size() > 0) {
Builder filterChain = RowFilter.Chain.newBuilder();
filterChain.addFilters(filter);
filterChain.addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1).build());
int count = 0;
// usually "field#" so pre-alloc
final StringBuilder regex = new StringBuilder(fields.size() * 6);
for (final String field : fields) {
if (count++ > 0) {
regex.append("|");
}
regex.append(field);
}
filterChain.addFilters(RowFilter.newBuilder().setColumnQualifierRegexFilter(ByteStringer.wrap(regex.toString().getBytes()))).build();
filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
}
final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRows(RowSet.newBuilder().addRowKeys(ByteStringer.wrap(key.getBytes())));
List<Row> rows;
try {
rows = client.readRowsAsync(rrr.build()).get();
if (rows == null || rows.isEmpty()) {
return Status.NOT_FOUND;
}
for (final Row row : rows) {
for (final Family family : row.getFamiliesList()) {
if (Arrays.equals(family.getNameBytes().toByteArray(), columnFamilyBytes)) {
for (final Column column : family.getColumnsList()) {
// we should only have a single cell per column
result.put(column.getQualifier().toString(UTF8_CHARSET), new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
if (debug) {
System.out.println("Result for field: " + column.getQualifier().toString(UTF8_CHARSET) + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));
}
}
}
}
}
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Interrupted during get: " + e);
Thread.currentThread().interrupt();
return Status.ERROR;
} catch (ExecutionException e) {
System.err.println("Exception during get: " + e);
return Status.ERROR;
}
}
use of com.helger.genericode.v10.Column in project simple-bigtable by spotify.
the class CellsReadImplTest method testParentDataTypeToDataType.
@Test
public void testParentDataTypeToDataType() throws Exception {
assertEquals(Lists.newArrayList(), cellsRead.parentTypeToCurrentType().apply(Optional.empty()));
assertEquals(Lists.newArrayList(), cellsRead.parentTypeToCurrentType().apply(Optional.of(Column.getDefaultInstance())));
final Cell cell = Cell.getDefaultInstance();
final Column column = Column.newBuilder().addCells(cell).build();
assertEquals(ImmutableList.of(cell), cellsRead.parentTypeToCurrentType().apply(Optional.of(column)));
}
Aggregations