Search in sources :

Example 11 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index in project jaxdb by jaxdb.

the class Generator method getType.

private Type getType(final Table table, final $Column column) throws GeneratorExecutionException {
    final String columnName = column.getName$().text();
    boolean isKeyForUpdate = false;
    // FIXME: Make efficient
    if (table.getJsqlKeyForUpdate() != null)
        for (final xLygluGCXAA.$Named col : table.getJsqlKeyForUpdate().getColumn()) if (isKeyForUpdate = columnName.equals(col.getName$().text()))
            break;
    final Class<?> cls = column.getClass().getSuperclass();
    GenerateOn<?> generateOnInsert = null;
    GenerateOn<?> generateOnUpdate = null;
    final boolean isPrimary = ddlx.isPrimary(table, column);
    final Object[] commonParams = { THIS, MUTABLE, "\"" + column.getName$().text() + "\"", ddlx.isUnique(table, column), isPrimary, isNull(column) };
    if (column instanceof $Char) {
        final $Char type = ($Char) column;
        if (type.getSqlxGenerateOnInsert$() != null) {
            if ($Char.GenerateOnInsert$.UUID.text().equals(type.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.UUID;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + type.getSqlxGenerateOnInsert$().text());
        }
        return new Type(table, column, isPrimary, data.CHAR.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getLength$() == null ? null : type.getLength$().text(), isVarying(type.getVarying$()));
    }
    if (column instanceof $Clob) {
        final $Clob type = ($Clob) column;
        return new Type(table, column, isPrimary, data.CLOB.class, commonParams, null, generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getLength$() == null ? null : type.getLength$().text());
    }
    if (column instanceof $Binary) {
        final $Binary type = ($Binary) column;
        return new Type(table, column, isPrimary, data.BINARY.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getLength$() == null ? null : type.getLength$().text(), isVarying(type.getVarying$()));
    }
    if (column instanceof $Blob) {
        final $Blob type = ($Blob) column;
        return new Type(table, column, isPrimary, data.BLOB.class, commonParams, null, generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getLength$() == null ? null : type.getLength$().text());
    }
    if (column instanceof $Integer) {
        final $Integer integerColumn = ($Integer) column;
        if (integerColumn.getGenerateOnInsert$() != null) {
            if ($Integer.GenerateOnInsert$.AUTO_5FINCREMENT.text().equals(integerColumn.getGenerateOnInsert$().text())) {
                generateOnInsert = GenerateOn.AUTO_GENERATED;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integerColumn.getGenerateOnInsert$().text());
            }
        }
        if (column instanceof $Tinyint) {
            final $Tinyint integer = ($Tinyint) column;
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if ($Tinyint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (isPrimary)
                        throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new Type(table, column, isPrimary, data.TINYINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Smallint) {
            final $Smallint integer = ($Smallint) column;
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if ($Smallint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (isPrimary)
                        throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new Type(table, column, isPrimary, data.SMALLINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Int) {
            final $Int integer = ($Int) column;
            if (integer.getSqlxGenerateOnInsert$() != null) {
                if (generateOnInsert != null)
                    throw new GeneratorExecutionException("ddlx:generateOnInsert and sqlx:generateOnInsert are mutually exclusive");
                if ($Int.GenerateOnInsert$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnInsert = GenerateOn.EPOCH_MINUTES;
                } else if ($Int.GenerateOnInsert$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnInsert = GenerateOn.EPOCH_SECONDS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integer.getSqlxGenerateOnInsert$().text());
                }
            }
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                if ($Int.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else if ($Int.GenerateOnUpdate$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnUpdate = GenerateOn.EPOCH_MINUTES;
                } else if ($Int.GenerateOnUpdate$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnUpdate = GenerateOn.EPOCH_SECONDS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new Type(table, column, isPrimary, data.INT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Bigint) {
            final $Bigint integer = ($Bigint) column;
            if (integer.getSqlxGenerateOnInsert$() != null) {
                if (generateOnInsert != null)
                    throw new GeneratorExecutionException("ddlx:generateOnInsert and sqlx:generateOnInsert are mutually exclusive");
                if ($Bigint.GenerateOnInsert$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnInsert = GenerateOn.EPOCH_MINUTES;
                } else if ($Bigint.GenerateOnInsert$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnInsert = GenerateOn.EPOCH_SECONDS;
                } else if ($Bigint.GenerateOnInsert$.EPOCH_5FMILLIS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 13)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 13 for EPOCH_MILLIS");
                    generateOnInsert = GenerateOn.EPOCH_MILLIS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integer.getSqlxGenerateOnInsert$().text());
                }
            }
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                if ($Bigint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnUpdate = GenerateOn.EPOCH_MINUTES;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnUpdate = GenerateOn.EPOCH_SECONDS;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FMILLIS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 13)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 13 for EPOCH_MILLIS");
                    generateOnUpdate = GenerateOn.EPOCH_MILLIS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new Type(table, column, isPrimary, data.BIGINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
    }
    if (column instanceof $Float) {
        final $Float type = ($Float) column;
        final Class<? extends data.Column<?>> col = data.FLOAT.class;
        final Number min = type.getMin$() != null ? type.getMin$().text() : null;
        final Number max = type.getMax$() != null ? type.getMax$().text() : null;
        return new Type(table, column, isPrimary, col, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, min, max);
    }
    if (column instanceof $Double) {
        final $Double type = ($Double) column;
        final Class<? extends data.Column<?>> col = data.DOUBLE.class;
        final Number min = type.getMin$() != null ? type.getMin$().text() : null;
        final Number max = type.getMax$() != null ? type.getMax$().text() : null;
        return new Type(table, column, isPrimary, col, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, min, max);
    }
    if (column instanceof $Decimal) {
        final $Decimal type = ($Decimal) column;
        return new Type(table, column, isPrimary, data.DECIMAL.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getPrecision$() == null ? null : type.getPrecision$().text().intValue(), type.getScale$() == null ? null : type.getScale$().text().intValue(), type.getMin$() == null ? null : type.getMin$().text(), type.getMax$() == null ? null : type.getMax$().text());
    }
    if (column instanceof $Date) {
        final $Date type = ($Date) column;
        if (type.getSqlxGenerateOnInsert$() != null) {
            if ($Date.GenerateOnInsert$.TIMESTAMP.text().equals(type.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + type.getSqlxGenerateOnInsert$().text());
        }
        if (type.getSqlxGenerateOnUpdate$() != null) {
            if ($Date.GenerateOnUpdate$.TIMESTAMP.text().equals(type.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + type.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new Type(table, column, isPrimary, data.DATE.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    if (column instanceof $Time) {
        final $Time type = ($Time) column;
        if (type.getSqlxGenerateOnInsert$() != null) {
            if ($Time.GenerateOnInsert$.TIMESTAMP.text().equals(type.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + type.getSqlxGenerateOnInsert$().text());
        }
        if (type.getSqlxGenerateOnUpdate$() != null) {
            if ($Time.GenerateOnUpdate$.TIMESTAMP.text().equals(type.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + type.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new Type(table, column, isPrimary, data.TIME.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getPrecision$() == null ? null : type.getPrecision$().text());
    }
    if (column instanceof $Datetime) {
        final $Datetime type = ($Datetime) column;
        if (type.getSqlxGenerateOnInsert$() != null) {
            if ($Datetime.GenerateOnInsert$.TIMESTAMP.text().equals(type.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + type.getSqlxGenerateOnInsert$().text());
        }
        if (type.getSqlxGenerateOnUpdate$() != null) {
            if ($Datetime.GenerateOnUpdate$.TIMESTAMP.text().equals(type.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + type.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new Type(table, column, isPrimary, data.DATETIME.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, type.getPrecision$() == null ? null : type.getPrecision$().text());
    }
    if (column instanceof $Boolean) {
        final $Boolean type = ($Boolean) column;
        return new Type(table, column, isPrimary, data.BOOLEAN.class, commonParams, type.getDefault$() == null ? null : type.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    if (column instanceof $Enum) {
        final $Enum type = ($Enum) column;
        return new Type(table, column, isPrimary, data.ENUM.class, commonParams, type.getDefault$() == null ? null : getClassNameOfEnum(table, type).append('.').append(enumStringToEnum(type.getDefault$().text())), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    throw new IllegalArgumentException("Unknown type: " + cls);
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal) org.jaxdb.jsql.data(org.jaxdb.jsql.data) GeneratorExecutionException(org.jaxdb.ddlx.GeneratorExecutionException) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)

Example 12 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index in project jaxdb by jaxdb.

the class Generator method makeTable.

private String makeTable(final Table table, final Map<String, Table> tableNameToTable) throws GeneratorExecutionException {
    final String tableName = table.getName$().text();
    final Info info = new Info();
    final Type[] types = getTypes(table, tableNameToTable, 0, info);
    final int noColumnsLocal = table.getColumn() == null ? 0 : table.getColumn().size();
    final int noColumnsTotal = types.length;
    final String classSimpleName = Identifiers.toClassCase(tableName);
    final String className = schemaClassName + "." + classSimpleName;
    final String instanceName = Identifiers.toInstanceCase(tableName);
    final StringBuilder out = new StringBuilder();
    if (!table.getAbstract$().text()) {
        out.append("\n  private static final ").append(className).append(" $").append(instanceName).append(" = new ").append(className).append("(false, false);\n\n");
        out.append("  public static ").append(className).append(' ').append(classSimpleName).append("() {\n");
        out.append("    return $").append(instanceName).append(";\n");
        out.append("  }\n");
    }
    final String ext = table.getExtends$() == null ? data.Table.class.getCanonicalName() + "<" + className + ">" : Identifiers.toClassCase(table.getExtends$().text());
    final String abs = table.getAbstract$().text() ? " abstract" : "";
    out.append(getDoc(table, 1, '\0', '\n'));
    out.append("\n  public").append(abs).append(" static class ").append(classSimpleName).append(" extends ").append(ext).append(" {\n");
    if (table.getExtends$() == null) {
        out.append("    private final ").append(Key.class.getName()).append('<').append(className).append("> _primaryKey$ = new ").append(Key.class.getName()).append("<>(this);\n\n");
        out.append("    @").append(Override.class.getName()).append('\n');
        out.append("    public final ").append(Key.class.getName()).append('<').append(className).append("> getKey() {\n");
        out.append("      return _primaryKey$;\n");
        out.append("    }\n\n");
    }
    if (!table.getAbstract$().text()) {
        out.append("    private static final ").append(String.class.getName()).append("[] _columnName$ = {");
        for (int i = 0; i < noColumnsTotal; ++i) // FIXME: Hacking this to record what is the index of each column
        types[i].column.text(String.valueOf(i));
        final List<$Column> sortedColumns = new ArrayList<>();
        for (final Type type : types) sortedColumns.add(type.column);
        sortedColumns.sort(namedComparator);
        for (final $Column column : sortedColumns) out.append("\"").append(column.getName$().text()).append("\", ");
        out.setCharAt(out.length() - 2, '}');
        out.setCharAt(out.length() - 1, ';');
        out.append("\n");
        out.append("    @").append(Override.class.getName()).append('\n');
        out.append("    ").append(String.class.getName()).append("[] _columnName$() {\n");
        out.append("      return _columnName$;\n");
        out.append("    }\n\n");
        out.append("    private static final byte[] _columnIndex$ = {");
        for (final $Column column : sortedColumns) out.append(column.text()).append(", ");
        out.setCharAt(out.length() - 2, '}');
        out.setCharAt(out.length() - 1, ';');
        out.append('\n');
        out.append("    @").append(Override.class.getName()).append('\n');
        out.append("    byte[] _columnIndex$() {\n");
        out.append("      return _columnIndex$;\n");
        out.append("    }\n\n");
        out.append("    @").append(Override.class.getName()).append('\n');
        out.append("    public ").append(String.class.getName()).append(" getName() {\n");
        out.append("      return \"").append(tableName).append("\";\n");
        out.append("    }\n\n");
        out.append("    @").append(Override.class.getName()).append('\n');
        out.append("    ").append(className).append(" newInstance() {\n");
        out.append("      return new ").append(className).append("(true, true);\n");
        out.append("    }\n\n");
        out.append("    @").append(Override.class.getName()).append('\n');
        out.append("    ").append(className).append(" immutable() {\n");
        out.append("      return $").append(instanceName).append(";\n");
        out.append("    }\n\n");
        final StringBuilder init = new StringBuilder();
        newColumnArray(init, noColumnsTotal).append(", ");
        newColumnArray(init, info.totalPrimaryCount.count).append(", ");
        newColumnArray(init, info.totalKeyForUpdateCount.count).append(", ");
        newColumnArray(init, info.totalAutoCount.count);
        out.append("    ").append(classSimpleName).append("(final boolean _mutable$, final boolean _wasSelected$) {\n");
        out.append("      this(_mutable$, _wasSelected$, ").append(init).append(", null, false);\n");
        out.append("    }\n\n");
        out.append("    /** Creates a new {@link ").append(className).append("}. */\n");
        out.append("    public ").append(classSimpleName).append("() {\n");
        out.append("      this(null, false);\n");
        out.append("    }\n\n");
        // Constructor with primary key columns
        if (info.totalPrimaryCount.count > 0) {
            final StringBuilder set = new StringBuilder();
            out.append("    /** Creates a new {@link ").append(className).append("} with the specified primary key. */\n");
            out.append("    public ").append(classSimpleName).append("(");
            final StringBuilder params = new StringBuilder();
            for (final Type type : types) {
                if (type.isPrimary) {
                    params.append(type.makeParam()).append(", ");
                    final String fieldName = Identifiers.toCamelCase(type.column.getName$().text());
                    set.append("      this.").append(fieldName).append(".set(").append(fieldName).append(");\n");
                }
            }
            params.setLength(params.length() - 2);
            out.append(params).append(") {\n");
            out.append("      this();\n");
            if (set.length() > 0) {
                set.setLength(set.length() - 1);
                out.append(set);
            }
            out.append("\n    }\n\n");
        }
        // Copy constructor
        out.append("    /** Creates a new {@link ").append(className).append("} as a copy of the specified {@link ").append(className).append("} instance. */\n");
        out.append("    public ").append(classSimpleName).append("(final ").append(className).append(" copy) {\n");
        out.append("      this(copy, true);\n");
        out.append("    }\n\n");
        out.append("    /** Creates a new {@link ").append(className).append("} as a copy of the specified {@link ").append(className).append("} instance. */\n");
        out.append("    ").append(classSimpleName).append("(final ").append(className).append(" copy, final boolean wasSet) {\n");
        out.append("      this(true, false, ").append(init).append(", copy, wasSet);\n");
        out.append("    }\n\n");
    }
    out.append("    ").append(classSimpleName).append("(final boolean _mutable$, final boolean _wasSelected$, final ").append(data.Column.class.getCanonicalName()).append("<?>[] _column$, final ").append(data.Column.class.getCanonicalName()).append("<?>[] _primary$, final ").append(data.Column.class.getCanonicalName()).append("<?>[] _keyForUpdate$, final ").append(data.Column.class.getCanonicalName()).append("<?>[] _auto$, final ").append(className).append(" copy, final boolean wasSet) {\n");
    out.append("      super(_mutable$, _wasSelected$, _column$, _primary$, _keyForUpdate$, _auto$");
    if (table.getExtends$() != null)
        out.append(", copy, wasSet");
    out.append(");\n");
    int primaryIndex = info.totalPrimaryCount.offset;
    int keyForUpdateIndex = info.totalKeyForUpdateCount.offset;
    int autoIndex = info.totalAutoCount.offset;
    for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
        if (i > s)
            out.append('\n');
        final Type type = types[i];
        out.append("      _column$[").append(i).append("] = ");
        if (type.isPrimary)
            out.append("_primary$[").append(primaryIndex++).append("] = ");
        if (type.keyForUpdate)
            out.append("_keyForUpdate$[").append(keyForUpdateIndex++).append("] = ");
        if (org.jaxdb.ddlx.Generator.isAuto(type.column))
            out.append("_auto$[").append(autoIndex++).append("] = ");
        type.assignColumn(out);
    }
    out.append('\n');
    out.append("      if (copy != null) {\n");
    for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
        if (i > s)
            out.append('\n');
        final Type type = types[i];
        final String fieldName = Identifiers.toCamelCase(type.column.getName$().text());
        out.append("        this.").append(fieldName).append(".copy(copy.").append(fieldName).append(", wasSet);");
    }
    out.append("\n      }\n");
    out.append("    }\n\n");
    out.append("    @").append(Override.class.getName()).append('\n');
    out.append("    void _merge$(final ").append(info.rootClassName).append(" table, final ").append(data.class.getName()).append(".Merge merge) {\n");
    if (table.getExtends$() != null) {
        out.append("      super._merge$(table, merge);\n");
        out.append("      final ").append(className).append(" t = (").append(className).append(")table;\n");
    } else {
        out.append("      final ").append(className).append(" t = table;\n");
    }
    boolean hasColumnsToMerge = false;
    for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
        final Type type = types[i];
        if (!type.isPrimary) {
            if (hasColumnsToMerge)
                out.append('\n');
            hasColumnsToMerge = true;
            final String fieldName = Identifiers.toCamelCase(type.column.getName$().text());
            out.append("      if (t.").append(fieldName).append(".wasSet() || merge != null && ").append(fieldName).append(".generateOnUpdate != null)\n");
            out.append("        ").append(fieldName).append(".copy(t.").append(fieldName).append(", true);\n");
        }
    }
    out.append("    }\n");
    for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) out.append(types[i].declareColumn());
    out.append("\n\n");
    if (table.getAbstract$().text()) {
        out.append("    @").append(Override.class.getName()).append('\n');
        out.append("    public abstract ").append(className).append(" clone();\n\n");
    } else {
        out.append("    @").append(Override.class.getName()).append('\n');
        out.append("    public ").append(className).append(" clone() {\n");
        out.append("      return new ").append(className).append("(this, false);\n");
        out.append("    }\n\n");
    }
    out.append("    @").append(Override.class.getName()).append('\n');
    out.append("    public boolean equals(final ").append(Object.class.getName()).append(" obj) {\n");
    out.append("      if (obj == this)\n");
    out.append("        return true;\n\n");
    out.append("      if (!(obj instanceof ").append(className).append("))\n");
    out.append("        return false;\n\n");
    if (table.getExtends$() != null) {
        out.append("      if (!super.equals(obj))\n");
        out.append("        return false;\n\n");
    }
    out.append("      final ").append(className).append(" that = (").append(className).append(")obj;");
    for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
        final Type type = types[i];
        out.append("\n      if (this.").append(type.getInstanceName()).append(".isNull() ? !that.").append(type.getInstanceName()).append(".isNull() : !this.").append(type.getInstanceName()).append(".get().equals(that.").append(type.getInstanceName()).append(".get()))");
        out.append("\n        return false;\n");
    }
    out.append("\n      return true;");
    out.append("\n    }\n\n");
    out.append("    @").append(Override.class.getName()).append('\n');
    out.append("    public int hashCode() {\n");
    if (table.getExtends$() != null)
        out.append("      int hashCode = super.hashCode();");
    else
        out.append("      int hashCode = ").append(tableName.hashCode()).append(";");
    for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
        final Type type = types[i];
        out.append("\n      if (!this.").append(type.getInstanceName()).append(".isNull())");
        out.append("\n        hashCode = 31 * hashCode + this.").append(type.getInstanceName()).append(".get().hashCode();\n");
    }
    out.append("\n      return hashCode;");
    out.append("\n    }\n\n");
    out.append("    @").append(Override.class.getName()).append('\n');
    out.append("    protected void toString(final boolean wasSetOnly, final ").append(StringBuilder.class.getName()).append(" s) {\n");
    if (table.getExtends$() != null)
        out.append("      super.toString(wasSetOnly, s);");
    for (int s = types.length - noColumnsLocal, i = s; i < types.length; ++i) {
        final Type type = types[i];
        final boolean ifClause = !type.isPrimary && !type.keyForUpdate;
        if (ifClause)
            out.append("      if (!wasSetOnly || this.").append(type.getInstanceName()).append(".wasSet)\n  ");
        out.append("      s.append(\",\\\"").append(type.column.getName$().text()).append("\\\":\").append(this.").append(type.getInstanceName()).append(".toJson());\n");
        if (ifClause)
            out.append('\n');
    }
    out.append("      if (s.length() > 0)\n");
    out.append("        s.setCharAt(0, '{');\n");
    out.append("      else\n");
    out.append("        s.append('{');\n\n");
    out.append("      s.append('}');");
    out.append("\n    }");
    out.append("\n  }");
    return out.toString();
}
Also used : org.jaxdb.jsql.data(org.jaxdb.jsql.data) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 13 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index in project mzmine2 by mzmine.

the class NetCDFReadTask method readNextScan.

/**
 * Reads one scan from the file. Requires that general information has already been read.
 */
private Scan readNextScan() throws IOException {
    // Get scan starting position and length
    int[] scanStartPosition = new int[1];
    int[] scanLength = new int[1];
    Integer[] startAndLength = scansIndex.get(scanNum);
    // End of file
    if (startAndLength == null) {
        return null;
    }
    scanStartPosition[0] = startAndLength[0];
    scanLength[0] = startAndLength[1];
    // Get retention time of the scan
    Double retentionTime = scansRetentionTimes.get(scanNum);
    if (retentionTime == null) {
        logger.severe("Could not find retention time for scan " + scanNum);
        throw (new IOException("Could not find retention time for scan " + scanNum));
    }
    // An empty scan needs special attention..
    if (scanLength[0] == 0) {
        scanNum++;
        return new SimpleScan(null, scanNum, 1, retentionTime.doubleValue(), 0, 0, null, new DataPoint[0], MassSpectrumType.CENTROIDED, PolarityType.UNKNOWN, "", null);
    }
    // Is there any way how to extract polarity from netcdf?
    PolarityType polarity = PolarityType.UNKNOWN;
    // Is there any way how to extract scan definition from netcdf?
    String scanDefinition = "";
    // Read mass and intensity values
    Array massValueArray;
    Array intensityValueArray;
    try {
        massValueArray = massValueVariable.read(scanStartPosition, scanLength);
        intensityValueArray = intensityValueVariable.read(scanStartPosition, scanLength);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Could not read from variables mass_values and/or intensity_values.", e);
        throw (new IOException("Could not read from variables mass_values and/or intensity_values."));
    }
    Index massValuesIndex = massValueArray.getIndex();
    Index intensityValuesIndex = intensityValueArray.getIndex();
    int arrayLength = massValueArray.getShape()[0];
    DataPoint[] dataPoints = new DataPoint[arrayLength];
    for (int j = 0; j < arrayLength; j++) {
        Index massIndex0 = massValuesIndex.set0(j);
        Index intensityIndex0 = intensityValuesIndex.set0(j);
        double mz = massValueArray.getDouble(massIndex0) * massValueScaleFactor;
        double intensity = intensityValueArray.getDouble(intensityIndex0) * intensityValueScaleFactor;
        dataPoints[j] = new SimpleDataPoint(mz, intensity);
    }
    scanNum++;
    // Auto-detect whether this scan is centroided
    MassSpectrumType spectrumType = ScanUtils.detectSpectrumType(dataPoints);
    SimpleScan buildingScan = new SimpleScan(null, scanNum, 1, retentionTime.doubleValue(), 0, 0, null, dataPoints, spectrumType, polarity, scanDefinition, null);
    return buildingScan;
}
Also used : PolarityType(net.sf.mzmine.datamodel.PolarityType) Index(ucar.ma2.Index) MassSpectrumType(net.sf.mzmine.datamodel.MassSpectrumType) IOException(java.io.IOException) IOException(java.io.IOException) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Array(ucar.ma2.Array) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 14 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index in project imageio-ext by geosolutions-it.

the class HOPSConverter method setTimeVariableAttributes.

// ////////////////////////////////////////////////////////////////////////
// 
// HELPERS !!!
// 
// ////////////////////////////////////////////////////////////////////////
private float setTimeVariableAttributes(Variable time_0, NetcdfFileWriteable ncFileOut) throws IOException {
    Array time_0_Data = time_0.read();
    Index time_0_Index = time_0_Data.getIndex();
    final String name = time_0.getName();
    final float referenceTime = time_0_Data.getFloat(time_0_Index.set(0));
    float fTime = referenceTime;
    Attribute offset = time_0.findAttribute("add_offset");
    if (offset != null)
        fTime += offset.getNumericValue().floatValue();
    GregorianCalendar calendar = null;
    if (time_0.getDescription().toLowerCase().contains("modified julian")) {
        calendar = NetCDFConverterUtilities.fromModifiedJulian(fTime, time_0.getDescription(), time_0.getUnitsString());
    } else {
        calendar = NetCDFConverterUtilities.fromJulian(fTime);
    }
    final String year = Integer.toString(calendar.get(Calendar.YEAR));
    final String month = Integer.toString((calendar.get(Calendar.MONTH) + 1));
    final String day = Integer.toString(calendar.get(Calendar.DAY_OF_MONTH));
    String hour = Integer.toString(calendar.get(Calendar.HOUR));
    if (hour.equalsIgnoreCase("0"))
        hour += "0";
    String minute = Integer.toString(calendar.get(Calendar.MINUTE));
    if (minute.equalsIgnoreCase("0"))
        minute += "0";
    String second = Integer.toString(calendar.get(Calendar.SECOND));
    if (second.equalsIgnoreCase("0"))
        second += "0";
    final String millisecond = Integer.toString(calendar.get(Calendar.MILLISECOND));
    final StringBuffer sbTime = new StringBuffer(year).append("-").append(month).append("-").append(day).append(" ").append(hour).append(":").append(minute).append(":").append(second).append(".").append(millisecond);
    ncFileOut.addVariableAttribute(name, "units", "days since " + sbTime.toString());
    ncFileOut.addVariableAttribute(name, "long_name", "time");
    return referenceTime;
}
Also used : Array(ucar.ma2.Array) Attribute(ucar.nc2.Attribute) GregorianCalendar(java.util.GregorianCalendar) Index(ucar.ma2.Index)

Example 15 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Index in project imageio-ext by geosolutions-it.

the class HOPSConverter method runTest.

public void runTest() throws IOException {
    try {
        final NetcdfFile ncFileIn = NetcdfFile.open(inputFile.getAbsolutePath());
        final File outDir = /*createTodayDirectory(this.outDir)*/
        new File("C:/work/data/testWritten/");
        // keep original name
        final File outputFile = File.createTempFile(inputFile.getName(), ".tmp");
        final NetcdfFileWriteable ncFileOut = NetcdfFileWriteable.createNew(outputFile.getAbsolutePath());
        // input dimensions
        Dimension timeDim0 = ncFileIn.findDimension("time");
        Dimension latDim0 = ncFileIn.findDimension("lat");
        Dimension lonDim0 = ncFileIn.findDimension("lon");
        // input variables
        Variable time_0 = ncFileIn.findVariable("time");
        Array time_0_Data = time_0.read();
        Index time_0_Index = time_0_Data.getIndex();
        Variable lon_0 = ncFileIn.findVariable("lon");
        final int nLon = lon_0.getDimension(0).getLength();
        Variable lat_0 = ncFileIn.findVariable("lat");
        final int nLat = lat_0.getDimension(0).getLength();
        Array lat_0_Data = lat_0.read();
        Index lat_0_Index = lat_0_Data.getIndex();
        Array lon_0_Data = lon_0.read();
        Index lon_0_Index = lon_0_Data.getIndex();
        // Depth
        Variable z_0 = ncFileIn.findVariable("z");
        final int nLevels = z_0.getDimension(0).getLength();
        Array z_0_Data = z_0.read();
        Index z_0_Index = z_0_Data.getIndex();
        Dimension timeDim = ncFileOut.addDimension("time", timeDim0.getLength());
        Dimension latDim = ncFileOut.addDimension(NetCDFUtilities.LAT, latDim0.getLength());
        Dimension lonDim = ncFileOut.addDimension(NetCDFUtilities.LON, lonDim0.getLength());
        Dimension depthDim = ncFileOut.addDimension(NetCDFUtilities.DEPTH, nLevels);
        // writing file
        computeMatrixExtremes(lat_0_Data, lon_0_Data, lonDim0.getLength(), latDim0.getLength(), lat_0_Index, lon_0_Index);
        NetCDFConverterUtilities.copyGlobalAttributes(ncFileOut, ncFileIn.getGlobalAttributes());
        // //
        // 
        // Time requires a special Management
        // 
        // //
        // time Variable
        ncFileOut.addVariable("time", DataType.FLOAT, new Dimension[] { timeDim });
        // ncFileOut.addVariableAttribute("Time", "long_name", "Time");
        final float referenceTime = setTimeVariableAttributes(time_0, ncFileOut);
        // lat Variable
        ArrayFloat lat_1_Data = new ArrayFloat(new int[] { latDim0.getLength() });
        Index lat_1_Index = lat_1_Data.getIndex();
        ncFileOut.addVariable(NetCDFUtilities.LAT, DataType.FLOAT, new Dimension[] { latDim });
        ncFileOut.addVariableAttribute(NetCDFUtilities.LAT, "long_name", NetCDFUtilities.LATITUDE);
        ncFileOut.addVariableAttribute(NetCDFUtilities.LAT, UNITS, lat_0.getUnitsString());
        for (int yPos = 0; yPos < latDim0.getLength(); yPos++) {
            lat_1_Data.setFloat(lat_1_Index.set(yPos), new Float(this.ymax - (new Float(yPos).floatValue() * this.periodY)).floatValue());
        // new Float(
        // this.ymin
        // + (new Float(yPos)
        // .floatValue() * this.periodY))
        // .floatValue());
        }
        // lon Variable
        ArrayFloat lon_1_Data = new ArrayFloat(new int[] { lonDim0.getLength() });
        Index lon_1_Index = lon_1_Data.getIndex();
        ncFileOut.addVariable(NetCDFUtilities.LON, DataType.FLOAT, new Dimension[] { lonDim });
        ncFileOut.addVariableAttribute(NetCDFUtilities.LON, "long_name", NetCDFUtilities.LONGITUDE);
        ncFileOut.addVariableAttribute(NetCDFUtilities.LON, UNITS, lon_0.getUnitsString());
        for (int xPos = 0; xPos < lonDim0.getLength(); xPos++) {
            lon_1_Data.setFloat(lon_1_Index.set(xPos), new Float(this.xmin + (new Float(xPos).floatValue() * this.periodX)).floatValue());
        }
        // depth level Variable
        ArrayFloat depthlevelDim_1_Data = new ArrayFloat(new int[] { depthDim.getLength() });
        Index depthlevelDim_1_Index = depthlevelDim_1_Data.getIndex();
        ncFileOut.addVariable(NetCDFUtilities.DEPTH, DataType.FLOAT, new Dimension[] { depthDim });
        ncFileOut.addVariableAttribute(NetCDFUtilities.DEPTH, "long_name", NetCDFUtilities.DEPTH);
        ncFileOut.addVariableAttribute(NetCDFUtilities.DEPTH, UNITS, z_0.getUnitsString());
        ncFileOut.addVariableAttribute(NetCDFUtilities.DEPTH, "positive", "up");
        for (int wPos = 0; wPos < depthDim.getLength(); wPos++) {
            depthlevelDim_1_Data.setFloat(depthlevelDim_1_Index.set(wPos), z_0_Data.getFloat(depthlevelDim_1_Index));
        }
        // {} Variables
        for (int i = 0; i < NUMVARS; i++) {
            String varName = (String) variables.get(i);
            Variable var = ncFileIn.findVariable(varName);
            ncFileOut.addVariable(varName, var.getDataType(), new Dimension[] { timeDim, depthDim, latDim, lonDim });
            NetCDFConverterUtilities.setVariableAttributes(var, ncFileOut, new String[] { "positions" });
        }
        // writing bin data ...
        ncFileOut.create();
        ArrayFloat timeData = new ArrayFloat(new int[] { timeDim.getLength() });
        Index timeIndex = timeData.getIndex();
        for (int t = 0; t < timeDim.getLength(); t++) {
            float julianTime = time_0_Data.getFloat(time_0_Index.set(t)) - referenceTime;
            timeData.setFloat(timeIndex.set(t), julianTime);
        }
        ncFileOut.write("time", timeData);
        Variable timeVar = ncFileOut.findVariable("time");
        timeDim.addCoordinateVariable(timeVar);
        ncFileOut.write(NetCDFUtilities.LAT, lat_1_Data);
        ncFileOut.write(NetCDFUtilities.LON, lon_1_Data);
        Variable depthVar = ncFileOut.findVariable("depth");
        depthDim.addCoordinateVariable(depthVar);
        ncFileOut.write(NetCDFUtilities.DEPTH, depthlevelDim_1_Data);
        // TODO: AutoApply MASK?
        ArrayFloat maskMatrix = new ArrayFloat.D2(latDim.getLength(), lonDim.getLength());
        Index maskIma = maskMatrix.getIndex();
        if (APPLY_MASK) {
            Variable mask = ncFileIn.findVariable("mask");
            Array maskData = mask.read();
            Index maskIndex = maskData.getIndex();
            ArrayFloat tempData = new ArrayFloat(new int[] { latDim0.getLength(), lonDim0.getLength() });
            Index tempIndex = tempData.getIndex();
            for (int yPos = 0; yPos < latDim0.getLength(); yPos++) {
                for (int xPos = 0; xPos < lonDim0.getLength(); xPos++) {
                    tempData.setFloat(tempIndex.set(yPos, xPos), maskData.getFloat(maskIndex.set(yPos, xPos)));
                }
            }
            WritableRaster outData = Resampler(lat_0_Data, lon_0_Data, lonDim0.getLength(), latDim0.getLength(), 2, tempData, -1);
            for (int j = 0; j < latDim0.getLength(); j++) {
                for (int k = 0; k < lonDim0.getLength(); k++) {
                    float sample = outData.getSampleFloat(k, j, 0);
                    maskMatrix.setFloat(maskIma.set(j, k), sample);
                }
            }
        }
        for (int i = 0; i < NUMVARS; i++) {
            String varName = (String) variables.get(i);
            Variable var = ncFileIn.findVariable(varName);
            Array originalVarData = var.read();
            Index varIndex = originalVarData.getIndex();
            Attribute fv = var.findAttribute("_FillValue");
            float fillValue = Float.NaN;
            if (fv != null) {
                fillValue = (fv.getNumericValue()).floatValue();
            }
            ArrayFloat T_tmp_Data = new ArrayFloat(new int[] { latDim0.getLength(), lonDim0.getLength() });
            Index T_tmp_Index = T_tmp_Data.getIndex();
            ArrayFloat Tmatrix = new ArrayFloat.D4(timeDim.getLength(), depthDim.getLength(), latDim.getLength(), lonDim.getLength());
            Index Tima = Tmatrix.getIndex();
            for (int tPos = 0; tPos < timeDim0.getLength(); tPos++) {
                for (int levelPos = 0; levelPos < depthDim.getLength(); levelPos++) {
                    for (int yPos = 0; yPos < latDim0.getLength(); yPos++) {
                        for (int xPos = 0; xPos < lonDim0.getLength(); xPos++) {
                            T_tmp_Data.setFloat(T_tmp_Index.set(yPos, xPos), originalVarData.getFloat(varIndex.set(tPos, yPos, xPos, levelPos)));
                        }
                    }
                    WritableRaster outData = Resampler(lat_0_Data, lon_0_Data, lonDim0.getLength(), latDim0.getLength(), 2, T_tmp_Data, fillValue);
                    for (int j = 0; j < latDim0.getLength(); j++) {
                        for (int k = 0; k < lonDim0.getLength(); k++) {
                            float sample = outData.getSampleFloat(k, j, 0);
                            if (APPLY_MASK) {
                                float maskValue = maskMatrix.getFloat(maskIma.set(j, k));
                                if (maskValue == 0)
                                    sample = fillValue;
                            }
                            Tmatrix.setFloat(Tima.set(tPos, levelPos, j, k), sample);
                        }
                    }
                }
            }
            ncFileOut.write(varName, Tmatrix);
        }
        ncFileOut.close();
        outputFile.renameTo(new File(outDir + File.separator + inputFile.getName()));
    } catch (Exception e) {
        // something bad happened
        if (LOGGER.isLoggable(Level.INFO))
            LOGGER.log(Level.INFO, e.getLocalizedMessage(), e);
        JAI.getDefaultInstance().getTileCache().flush();
    }
}
Also used : NetcdfFileWriteable(ucar.nc2.NetcdfFileWriteable) Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute) Index(ucar.ma2.Index) ArrayFloat(ucar.ma2.ArrayFloat) Dimension(ucar.nc2.Dimension) IOException(java.io.IOException) NetcdfFile(ucar.nc2.NetcdfFile) Array(ucar.ma2.Array) ArrayFloat(ucar.ma2.ArrayFloat) WritableRaster(java.awt.image.WritableRaster) File(java.io.File) NetcdfFile(ucar.nc2.NetcdfFile)

Aggregations

Index (ucar.ma2.Index)30 ArrayList (java.util.ArrayList)21 Array (ucar.ma2.Array)20 Test (org.junit.Test)12 IOException (java.io.IOException)11 Attribute (ucar.nc2.Attribute)11 AbstractMessage (com.google.protobuf.AbstractMessage)10 WritableRaster (java.awt.image.WritableRaster)10 ArrayFloat (ucar.ma2.ArrayFloat)10 Index (com.google.firestore.admin.v1.Index)9 Dimension (ucar.nc2.Dimension)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)8 NetcdfFileWriteable (ucar.nc2.NetcdfFileWriteable)8 Variable (ucar.nc2.Variable)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)7 File (java.io.File)5 List (java.util.List)5 ArrayDouble (ucar.ma2.ArrayDouble)5