Search in sources :

Example 21 with Column

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;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 22 with Column

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;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 23 with Column

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());
}
Also used : Table(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Schema.Table) org.jaxdb.jsql.data(org.jaxdb.jsql.data) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum) IOException(java.io.IOException) File(java.io.File) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 24 with Column

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;
    }
}
Also used : Builder(com.google.bigtable.v2.RowFilter.Chain.Builder) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) ByteString(com.google.protobuf.ByteString) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) RowFilter(com.google.bigtable.v2.RowFilter) Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family) Row(com.google.bigtable.v2.Row) DeleteFromRow(com.google.bigtable.v2.Mutation.DeleteFromRow) ExecutionException(java.util.concurrent.ExecutionException)

Example 25 with Column

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)));
}
Also used : Column(com.google.bigtable.v2.Column) Cell(com.google.bigtable.v2.Cell) Test(org.junit.Test)

Aggregations

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)21 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)11 Column (org.molgenis.emx2.Column)11 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)10 Column (com.google.bigtable.v2.Column)9 List (java.util.List)9 Family (com.google.bigtable.v2.Family)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)8 Test (org.junit.Test)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)7 MolgenisException (org.molgenis.emx2.MolgenisException)6 Map (java.util.Map)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)4 SqlColumnExecutor.validateColumn (org.molgenis.emx2.sql.SqlColumnExecutor.validateColumn)4 Cell (com.google.bigtable.v2.Cell)3 ResultSet (java.sql.ResultSet)3 ExecutionException (java.util.concurrent.ExecutionException)3