Search in sources :

Example 6 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class Domain method getIdentifier.

@Override
public Identifier getIdentifier(final List<Object> values, final boolean loadMissing) {
    if (values.size() == 1) {
        final Object value = values.get(0);
        if (value == null) {
            return null;
        } else if (this.idValueMap.containsKey(value)) {
            return Identifier.newIdentifier(value);
        } else if (this.stringIdMap.containsKey(value.toString())) {
            return this.stringIdMap.get(value.toString());
        } else {
            final String lowerValue = ((String) value).toLowerCase();
            final Identifier id = this.valueIdMap.get(lowerValue);
            return id;
        }
    } else {
        throw new IllegalArgumentException("Expecting only a single value " + values);
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier)

Example 7 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class Domain method addCodedValue.

public synchronized Domain addCodedValue(final Object code, final String name) {
    final Identifier identifier = Identifier.newIdentifier(code);
    final CodedValue value = new CodedValue(code, name);
    this.codedValues.add(value);
    final List<Object> values = Collections.<Object>singletonList(name);
    this.idValueMap.put(identifier, values);
    this.stringIdMap.put(code.toString(), identifier);
    this.valueIdMap.put(name.toLowerCase(), identifier);
    if (code instanceof Number) {
        final int id = ((Number) code).intValue();
        if (this.maxId < id) {
            this.maxId = id;
        }
    }
    return this;
}
Also used : Identifier(com.revolsys.identifier.Identifier)

Example 8 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class RecordStore method newRecord.

default Record newRecord(RecordDefinition recordDefinition, final Map<String, ? extends Object> values) {
    final PathName typePath = recordDefinition.getPathName();
    recordDefinition = getRecordDefinition(recordDefinition);
    if (recordDefinition == null) {
        throw new IllegalArgumentException("Cannot find table " + typePath + " for " + this);
    } else {
        final Record record = newRecord(recordDefinition);
        if (record != null) {
            record.setValues(values);
            final String idFieldName = recordDefinition.getIdFieldName();
            if (Property.hasValue(idFieldName)) {
                if (values.get(idFieldName) == null) {
                    final Identifier id = newPrimaryIdentifier(typePath);
                    record.setIdentifier(id);
                }
            }
        }
        return record;
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) PathName(com.revolsys.io.PathName)

Example 9 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class RecordStore method newRecordWithIdentifier.

default Record newRecordWithIdentifier(final RecordDefinition recordDefinition) {
    final Record record = newRecord(recordDefinition);
    if (record != null) {
        final String idFieldName = recordDefinition.getIdFieldName();
        if (Property.hasValue(idFieldName)) {
            final PathName typePath = recordDefinition.getPathName();
            final Identifier id = newPrimaryIdentifier(typePath);
            record.setIdentifier(id);
        }
    }
    return record;
}
Also used : Identifier(com.revolsys.identifier.Identifier) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) PathName(com.revolsys.io.PathName)

Example 10 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class Value method setFieldDefinition.

@Override
public void setFieldDefinition(final FieldDefinition field) {
    if (field != null) {
        this.fieldDefinition = field;
        if (field instanceof JdbcFieldDefinition) {
            this.jdbcField = (JdbcFieldDefinition) field;
        } else {
            this.jdbcField = JdbcFieldDefinition.newFieldDefinition(this.queryValue);
        }
        CodeTable codeTable = null;
        if (field != null) {
            final RecordDefinition recordDefinition = field.getRecordDefinition();
            if (recordDefinition != null) {
                final String fieldName = field.getName();
                codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
                if (codeTable instanceof CodeTableProperty) {
                    final CodeTableProperty codeTableProperty = (CodeTableProperty) codeTable;
                    if (codeTableProperty.getRecordDefinition() == recordDefinition) {
                        codeTable = null;
                    }
                }
                if (codeTable != null) {
                    final Identifier id = codeTable.getIdentifier(this.queryValue);
                    if (id == null) {
                        this.displayValue = this.queryValue;
                    } else {
                        setQueryValue(id);
                        final List<Object> values = codeTable.getValues(id);
                        if (values.size() == 1) {
                            this.displayValue = values.get(0);
                        } else {
                            this.displayValue = Strings.toString(":", values);
                        }
                    }
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) TypedIdentifier(com.revolsys.identifier.TypedIdentifier) Identifier(com.revolsys.identifier.Identifier) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) CodeTableProperty(com.revolsys.record.code.CodeTableProperty) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

Identifier (com.revolsys.identifier.Identifier)56 Record (com.revolsys.record.Record)17 ArrayList (java.util.ArrayList)12 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 SingleIdentifier (com.revolsys.identifier.SingleIdentifier)8 ListIdentifier (com.revolsys.identifier.ListIdentifier)7 TypedIdentifier (com.revolsys.identifier.TypedIdentifier)6 CodeTable (com.revolsys.record.code.CodeTable)6 RecordReader (com.revolsys.record.io.RecordReader)5 RecordStore (com.revolsys.record.schema.RecordStore)5 Transaction (com.revolsys.transaction.Transaction)5 List (java.util.List)5 Geometry (com.revolsys.geometry.model.Geometry)4 BaseCloseable (com.revolsys.io.BaseCloseable)4 PathName (com.revolsys.io.PathName)4 ArrayRecord (com.revolsys.record.ArrayRecord)4 Query (com.revolsys.record.query.Query)4 OsmElement (com.revolsys.record.io.format.openstreetmap.model.OsmElement)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)2