Search in sources :

Example 6 with OType

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

the class ORecordSerializerNetworkV0 method writeLinkMap.

private int writeLinkMap(final BytesContainer bytes, final Map<Object, OIdentifiable> map) {
    final boolean disabledAutoConversion = map instanceof ORecordLazyMultiValue && ((ORecordLazyMultiValue) map).isAutoConvertToRecord();
    if (disabledAutoConversion)
        // AVOID TO FETCH RECORD
        ((ORecordLazyMultiValue) map).setAutoConvertToRecord(false);
    try {
        final int fullPos = OVarIntSerializer.write(bytes, map.size());
        for (Entry<Object, OIdentifiable> entry : map.entrySet()) {
            // TODO:check skip of complex types
            // FIXME: changed to support only string key on map
            final OType type = OType.STRING;
            writeOType(bytes, bytes.alloc(1), type);
            writeString(bytes, entry.getKey().toString());
            if (entry.getValue() == null)
                writeNullLink(bytes);
            else
                writeOptimizedLink(bytes, entry.getValue());
        }
        return fullPos;
    } finally {
        if (disabledAutoConversion)
            ((ORecordLazyMultiValue) map).setAutoConvertToRecord(true);
    }
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)

Example 7 with OType

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

the class ORecordSerializerNetworkV0 method writeEmbeddedMap.

@SuppressWarnings("unchecked")
private int writeEmbeddedMap(BytesContainer bytes, Map<Object, Object> map) {
    final int[] pos = new int[map.size()];
    int i = 0;
    Entry<Object, Object>[] values = new Entry[map.size()];
    final int fullPos = OVarIntSerializer.write(bytes, map.size());
    for (Entry<Object, Object> entry : map.entrySet()) {
        // TODO:check skip of complex types
        // FIXME: changed to support only string key on map
        OType type = OType.STRING;
        writeOType(bytes, bytes.alloc(1), type);
        writeString(bytes, entry.getKey().toString());
        pos[i] = bytes.alloc(OIntegerSerializer.INT_SIZE + 1);
        values[i] = entry;
        i++;
    }
    for (i = 0; i < values.length; i++) {
        int pointer = 0;
        final Object value = values[i].getValue();
        if (value != null) {
            final OType type = getTypeFromValueEmbedded(value);
            if (type == null) {
                throw new OSerializationException("Impossible serialize value of type " + value.getClass() + " with the ODocument binary serializer");
            }
            pointer = serializeValue(bytes, value, type, null);
            OIntegerSerializer.INSTANCE.serializeLiteral(pointer, bytes.bytes, pos[i]);
            writeOType(bytes, (pos[i] + OIntegerSerializer.INT_SIZE), type);
        }
    }
    return fullPos;
}
Also used : ODocumentEntry(com.orientechnologies.orient.core.record.impl.ODocumentEntry) Entry(java.util.Map.Entry) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) OType(com.orientechnologies.orient.core.metadata.schema.OType)

Example 8 with OType

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

the class OSecurityShared method createOrUpdateORoleClass.

private OClass createOrUpdateORoleClass(final ODatabaseDocument database, OClass identityClass) {
    OClass roleClass = database.getMetadata().getSchema().getClass("ORole");
    boolean unsafe = false;
    if (roleClass == null) {
        roleClass = database.getMetadata().getSchema().createClass("ORole", identityClass);
        unsafe = true;
    } else if (!roleClass.getSuperClasses().contains(identityClass))
        // MIGRATE AUTOMATICALLY TO 1.2.0
        roleClass.setSuperClasses(Arrays.asList(identityClass));
    if (!roleClass.existsProperty("name")) {
        roleClass.createProperty("name", OType.STRING, (OType) null, unsafe).setMandatory(true).setNotNull(true).setCollate("ci");
        roleClass.createIndex("ORole.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
    } else {
        final OProperty name = roleClass.getProperty("name");
        if (name.getAllIndexes().isEmpty())
            roleClass.createIndex("ORole.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
    }
    if (!roleClass.existsProperty("mode"))
        roleClass.createProperty("mode", OType.BYTE, (OType) null, unsafe);
    if (!roleClass.existsProperty("rules"))
        roleClass.createProperty("rules", OType.EMBEDDEDMAP, OType.BYTE, unsafe);
    if (!roleClass.existsProperty("inheritedRole"))
        roleClass.createProperty("inheritedRole", OType.LINK, roleClass, unsafe);
    return roleClass;
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OType(com.orientechnologies.orient.core.metadata.schema.OType)

Example 9 with OType

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

the class OCompositeKeySerializer method preprocess.

@Override
public OCompositeKey preprocess(OCompositeKey value, Object... hints) {
    if (value == null)
        return null;
    final OType[] types = getKeyTypes(hints);
    final List<Object> keys = value.getKeys();
    final OCompositeKey compositeKey = new OCompositeKey();
    final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance();
    for (int i = 0; i < keys.size(); i++) {
        final Object key = keys.get(i);
        final OType type;
        if (types.length > i)
            type = types[i];
        else
            type = OType.getTypeByClass(key.getClass());
        OBinarySerializer<Object> keySerializer = ((OBinarySerializer<Object>) factory.getObjectSerializer(type));
        compositeKey.addKey(keySerializer.preprocess(key));
    }
    return compositeKey;
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Example 10 with OType

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

the class OCSVTransformer method executeTransform.

@Override
public Object executeTransform(final Object input) {
    if (skipTransform())
        return null;
    log(OETLProcessor.LOG_LEVELS.DEBUG, "parsing=%s", input);
    final List<String> fields = OStringSerializerHelper.smartSplit(input.toString(), new char[] { separator }, 0, -1, false, false, false, false, unicode);
    if (!isColumnNamesCorrect(fields))
        return null;
    final ODocument doc = new ODocument();
    for (int i = 0; i < columnNames.size() && i < fields.size(); ++i) {
        final String fieldName = columnNames.get(i);
        Object fieldValue = null;
        try {
            final String fieldStringValue = getCellContent(fields.get(i));
            final OType fieldType = columnTypes != null ? columnTypes.get(i) : null;
            if (fieldType != null && fieldType != OType.ANY) {
                // DEFINED TYPE
                fieldValue = processKnownType(doc, i, fieldName, fieldStringValue, fieldType);
            } else {
                // DETERMINE THE TYPE
                if (fieldStringValue != null)
                    fieldValue = determineTheType(fieldStringValue);
            }
            doc.field(fieldName, fieldValue);
        } catch (Exception e) {
            processor.getStats().incrementErrors();
            log(OETLProcessor.LOG_LEVELS.ERROR, "Error on setting document field %s=%s (cause=%s)", fieldName, fieldValue, e.toString());
        }
    }
    log(OETLProcessor.LOG_LEVELS.DEBUG, "document=%s", doc);
    return doc;
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) ParseException(java.text.ParseException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

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