Search in sources :

Example 36 with OType

use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.

the class OCSVExtractor method fetchNext.

private OExtractedItem fetchNext(CSVRecord csvRecord) {
    ODocument doc = new ODocument();
    final Map<String, String> recordAsMap = csvRecord.toMap();
    if (columnTypes.isEmpty()) {
        for (Map.Entry<String, String> en : recordAsMap.entrySet()) {
            final String value = en.getValue();
            if (!csvFormat.getAllowMissingColumnNames() || !en.getKey().isEmpty()) {
                if (value == null || nullValue.equals(value) || value.isEmpty())
                    doc.field(en.getKey(), null, OType.ANY);
                else
                    doc.field(en.getKey(), determineTheType(value));
            }
        }
    } else {
        for (Map.Entry<String, OType> typeEntry : columnTypes.entrySet()) {
            final String fieldName = typeEntry.getKey();
            final OType fieldType = typeEntry.getValue();
            String fieldValueAsString = recordAsMap.get(fieldName);
            try {
                if (fieldType.getDefaultJavaType().equals(Date.class)) {
                    if (fieldType.equals(OType.DATE))
                        doc.field(fieldName, transformToDate(fieldValueAsString));
                    else
                        doc.field(fieldName, transformToDateTime(fieldValueAsString));
                } else {
                    Object fieldValue = OType.convert(fieldValueAsString, fieldType.getDefaultJavaType());
                    doc.field(fieldName, fieldValue);
                }
            } catch (Exception e) {
                processor.getStats().incrementErrors();
                log(OETLProcessor.LOG_LEVELS.ERROR, "Error on converting row %d field '%s' , value '%s' (class:%s) to type: %s", csvRecord.getRecordNumber(), fieldName, fieldValueAsString, fieldValueAsString.getClass().getName(), fieldType);
            }
        }
    }
    log(DEBUG, "document=%s", doc);
    current++;
    return new OExtractedItem(current, doc);
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OExtractedItem(com.orientechnologies.orient.etl.OExtractedItem) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) ParseException(java.text.ParseException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 37 with OType

use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.

the class OFetchHelper method processRecord.

private static void processRecord(final ODocument record, final Object iUserObject, final OFetchPlan iFetchPlan, final int iCurrentLevel, final int iLevelFromRoot, final int iFieldDepthLevel, final Map<ORID, Integer> parsedRecords, final String iFieldPathFromRoot, final OFetchListener iListener, final OFetchContext iContext, final String iFormat) throws IOException {
    if (record == null)
        return;
    if (!iListener.requireFieldProcessing() && iFetchPlan == OFetchHelper.DEFAULT_FETCHPLAN)
        return;
    Object fieldValue;
    iContext.onBeforeFetch(record);
    Set<String> toRemove = new HashSet<String>();
    for (String fieldName : record.fieldNames()) {
        String fieldPath = !iFieldPathFromRoot.isEmpty() ? iFieldPathFromRoot + "." + fieldName : fieldName;
        int depthLevel;
        depthLevel = getDepthLevel(iFetchPlan, fieldPath, iCurrentLevel);
        if (depthLevel == -2) {
            toRemove.add(fieldName);
            continue;
        }
        if (iFieldDepthLevel > -1)
            depthLevel = iFieldDepthLevel;
        fieldValue = record.rawField(fieldName);
        OType fieldType = record.fieldType(fieldName);
        boolean fetch = !iFormat.contains("shallow") && (!(fieldValue instanceof OIdentifiable) || depthLevel == -1 || iCurrentLevel <= depthLevel || (iFetchPlan != null && iFetchPlan.has(fieldPath, iCurrentLevel)));
        final boolean isEmbedded = isEmbedded(fieldValue);
        if (!fetch && isEmbedded && iContext.fetchEmbeddedDocuments())
            // EMBEDDED, GO DEEPER
            fetch = true;
        if (iFormat.contains("shallow") || fieldValue == null || (!fetch && fieldValue instanceof OIdentifiable) || !(fieldValue instanceof OIdentifiable) && (!(fieldValue instanceof ORecordLazyMultiValue) || !((ORecordLazyMultiValue) fieldValue).rawIterator().hasNext() || !(((ORecordLazyMultiValue) fieldValue).rawIterator().next() instanceof OIdentifiable)) && (!(fieldValue.getClass().isArray()) || Array.getLength(fieldValue) == 0 || !(Array.get(fieldValue, 0) instanceof OIdentifiable)) && !containsIdentifiers(fieldValue)) {
            iContext.onBeforeStandardField(fieldValue, fieldName, iUserObject, fieldType);
            iListener.processStandardField(record, fieldValue, fieldName, iContext, iUserObject, iFormat, fieldType);
            iContext.onAfterStandardField(fieldValue, fieldName, iUserObject, fieldType);
        } else {
            try {
                if (fetch) {
                    final int nextLevel = isEmbedded ? iLevelFromRoot : iLevelFromRoot + 1;
                    fetch(record, iUserObject, iFetchPlan, fieldValue, fieldName, iCurrentLevel, nextLevel, iFieldDepthLevel, parsedRecords, depthLevel, fieldPath, iListener, iContext);
                }
            } catch (Exception e) {
                OLogManager.instance().error(null, "Fetching error on record %s", e, record.getIdentity());
            }
        }
    }
    for (String fieldName : toRemove) {
        iListener.skipStandardField(record, fieldName, iContext, iUserObject, iFormat);
    }
    iContext.onAfterFetch(record);
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) IOException(java.io.IOException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)

Example 38 with OType

use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.

the class OIndexAbstractDelegate method checkForKeyType.

protected void checkForKeyType(final Object iKey) {
    if (delegate.getDefinition() == null) {
        // RECOGNIZE THE KEY TYPE AT RUN-TIME
        final OType type = OType.getTypeByClass(iKey.getClass());
        if (type == null)
            return;
        OIndexManagerProxy indexManager = ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata().getIndexManager();
        getInternal().setType(type);
        indexManager.save();
    }
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType)

Example 39 with OType

use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.

the class OIndexDefinitionFactory method createSingleFieldIndexDefinition.

private static OIndexDefinition createSingleFieldIndexDefinition(OClass oClass, final String field, final OType type, OCollate collate, String indexKind, String algorithm) {
    final String fieldName = OClassImpl.decodeClassName(adjustFieldName(oClass, extractFieldName(field)));
    final OIndexDefinition indexDefinition;
    final OProperty propertyToIndex = oClass.getProperty(fieldName);
    final OType indexType;
    if (type == OType.EMBEDDEDMAP || type == OType.LINKMAP) {
        final OPropertyMapIndexDefinition.INDEX_BY indexBy = extractMapIndexSpecifier(field);
        if (indexBy.equals(OPropertyMapIndexDefinition.INDEX_BY.KEY))
            indexType = OType.STRING;
        else {
            if (type == OType.LINKMAP)
                indexType = OType.LINK;
            else {
                indexType = propertyToIndex.getLinkedType();
                if (indexType == null)
                    throw new OIndexException("Linked type was not provided." + " You should provide linked type for embedded collections that are going to be indexed.");
            }
        }
        indexDefinition = new OPropertyMapIndexDefinition(oClass.getName(), fieldName, indexType, indexBy);
    } else if (type.equals(OType.EMBEDDEDLIST) || type.equals(OType.EMBEDDEDSET) || type.equals(OType.LINKLIST) || type.equals(OType.LINKSET)) {
        if (type.equals(OType.LINKSET))
            indexType = OType.LINK;
        else if (type.equals(OType.LINKLIST)) {
            indexType = OType.LINK;
        } else {
            indexType = propertyToIndex.getLinkedType();
            if (indexType == null)
                throw new OIndexException("Linked type was not provided." + " You should provide linked type for embedded collections that are going to be indexed.");
        }
        indexDefinition = new OPropertyListIndexDefinition(oClass.getName(), fieldName, indexType);
    } else if (type.equals(OType.LINKBAG)) {
        indexDefinition = new OPropertyRidBagIndexDefinition(oClass.getName(), fieldName);
    } else
        indexDefinition = new OPropertyIndexDefinition(oClass.getName(), fieldName, type);
    if (collate == null && propertyToIndex != null)
        collate = propertyToIndex.getCollate();
    if (collate != null)
        indexDefinition.setCollate(collate);
    return indexDefinition;
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OType(com.orientechnologies.orient.core.metadata.schema.OType)

Example 40 with OType

use of com.orientechnologies.orient.core.metadata.schema.OType in project orientdb by orientechnologies.

the class OIndexDefinitionFactory method checkTypes.

private static void checkTypes(OClass oClass, List<String> fieldNames, List<OType> types) {
    if (fieldNames.size() != types.size())
        throw new IllegalArgumentException("Count of field names doesn't match count of field types. It was " + fieldNames.size() + " fields, but " + types.size() + " types.");
    for (int i = 0, fieldNamesSize = fieldNames.size(); i < fieldNamesSize; i++) {
        String fieldName = fieldNames.get(i);
        OType type = types.get(i);
        final OProperty property = oClass.getProperty(fieldName);
        if (property != null && !type.equals(property.getType())) {
            throw new IllegalArgumentException("Property type list not match with real property types");
        }
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OType(com.orientechnologies.orient.core.metadata.schema.OType)

Aggregations

OType (com.orientechnologies.orient.core.metadata.schema.OType)65 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)21 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)15 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)14 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)12 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)11 Map (java.util.Map)10 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ORecordLazyList (com.orientechnologies.orient.core.db.record.ORecordLazyList)5 ORecordLazyMultiValue (com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)5 OTrackedMap (com.orientechnologies.orient.core.db.record.OTrackedMap)5 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)5 OBinarySerializerFactory (com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)5 Collection (java.util.Collection)5 ORecordLazyMap (com.orientechnologies.orient.core.db.record.ORecordLazyMap)4 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)4 OTrackedList (com.orientechnologies.orient.core.db.record.OTrackedList)4 ORID (com.orientechnologies.orient.core.id.ORID)4