Search in sources :

Example 86 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class JdbcUtils method appendOrderByFields.

public static StringBuilder appendOrderByFields(final StringBuilder sql, final Map<? extends CharSequence, Boolean> orderBy) {
    boolean first = true;
    for (final Entry<? extends CharSequence, Boolean> entry : orderBy.entrySet()) {
        if (first) {
            first = false;
        } else {
            sql.append(", ");
        }
        final CharSequence fieldName = entry.getKey();
        if (fieldName instanceof FieldDefinition) {
            final FieldDefinition fieldDefinition = (FieldDefinition) fieldName;
            fieldDefinition.appendColumnName(sql);
        } else {
            sql.append(fieldName);
        }
        final Boolean ascending = entry.getValue();
        if (!ascending) {
            sql.append(" DESC");
        }
    }
    return sql;
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition)

Example 87 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class JdbcUtils method addColumnNames.

public static void addColumnNames(final StringBuilder sql, final RecordDefinition recordDefinition, final String tablePrefix) {
    for (int i = 0; i < recordDefinition.getFieldCount(); i++) {
        if (i > 0) {
            sql.append(", ");
        }
        final FieldDefinition fieldDefinition = recordDefinition.getField(i);
        addSelectColumnName(sql, tablePrefix, fieldDefinition);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition)

Example 88 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class JdbcQueryIterator method getNextRecord.

public static Record getNextRecord(final JdbcRecordStore recordStore, final RecordDefinition recordDefinition, final List<FieldDefinition> fields, final RecordFactory<Record> recordFactory, final ResultSet resultSet, final boolean internStrings) {
    final Record record = recordFactory.newRecord(recordDefinition);
    if (record != null) {
        record.setState(RecordState.INITIALIZING);
        int columnIndex = 1;
        for (final FieldDefinition field : fields) {
            final JdbcFieldDefinition jdbcField = (JdbcFieldDefinition) field;
            try {
                columnIndex = jdbcField.setFieldValueFromResultSet(resultSet, columnIndex, record, internStrings);
            } catch (final SQLException e) {
                throw new RuntimeException("Unable to get value " + (columnIndex + 1) + " from result set", e);
            }
        }
        record.setState(RecordState.PERSISTED);
        recordStore.addStatistic("query", record);
    }
    return record;
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) SQLException(java.sql.SQLException) FieldDefinition(com.revolsys.record.schema.FieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) Record(com.revolsys.record.Record)

Example 89 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class AbstractJdbcRecordStore method getField.

public JdbcFieldDefinition getField(final String schemaName, final String tableName, final String columnName) {
    final String typePath = PathUtil.toPath(schemaName, tableName);
    final RecordDefinition recordDefinition = getRecordDefinition(typePath);
    if (recordDefinition == null) {
        return null;
    } else {
        final FieldDefinition attribute = recordDefinition.getField(columnName);
        return (JdbcFieldDefinition) attribute;
    }
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) FieldDefinition(com.revolsys.record.schema.FieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 90 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class XlsxRecordWriter method addHeaderRow.

private void addHeaderRow(final Worksheet worksheet, final RecordDefinition recordDefinition) {
    final List<Cols> columnGroups = worksheet.getCols();
    final Cols columns = smlObjectFactory.createCols();
    columnGroups.add(columns);
    final Row headerRow = smlObjectFactory.createRow();
    this.sheetRows.add(headerRow);
    final List<Cell> cells = headerRow.getC();
    for (final FieldDefinition field : recordDefinition.getFields()) {
        final String fieldName = field.getName();
        final Col column = smlObjectFactory.createCol();
        columns.getCol().add(column);
        column.setMin(field.getIndex() + 1);
        column.setMax(field.getIndex() + 1);
        column.setBestFit(true);
        final int textLength = Math.min(40, Math.max(fieldName.length() + 2, field.getMaxStringLength()));
        column.setWidth(textLength * 1.25);
        addCellInlineString(cells, fieldName);
    }
}
Also used : Col(org.xlsx4j.sml.Col) Cols(org.xlsx4j.sml.Cols) FieldDefinition(com.revolsys.record.schema.FieldDefinition) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell)

Aggregations

FieldDefinition (com.revolsys.record.schema.FieldDefinition)133 RecordDefinition (com.revolsys.record.schema.RecordDefinition)38 DataType (com.revolsys.datatype.DataType)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)19 PathName (com.revolsys.io.PathName)15 Record (com.revolsys.record.Record)15 ArrayList (java.util.ArrayList)15 Geometry (com.revolsys.geometry.model.Geometry)13 CodeTable (com.revolsys.record.code.CodeTable)9 Query (com.revolsys.record.query.Query)8 LineString (com.revolsys.geometry.model.LineString)7 ArrayRecord (com.revolsys.record.ArrayRecord)7 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)7 SQLException (java.sql.SQLException)7 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 BadLocationException (javax.swing.text.BadLocationException)4