Search in sources :

Example 31 with OType

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

the class OSimpleKeyIndexDefinition method serializeToStream.

@Override
protected void serializeToStream() {
    super.serializeToStream();
    final List<String> keyTypeNames = new ArrayList<String>(keyTypes.length);
    for (final OType keyType : keyTypes) keyTypeNames.add(keyType.toString());
    document.field("keyTypes", keyTypeNames, OType.EMBEDDEDLIST);
    if (collate instanceof OCompositeCollate) {
        List<String> collatesNames = new ArrayList<String>();
        for (OCollate curCollate : ((OCompositeCollate) this.collate).getCollates()) collatesNames.add(curCollate.getName());
        document.field("collates", collatesNames, OType.EMBEDDEDLIST);
    } else
        document.field("collate", collate.getName());
    document.field("nullValuesIgnored", isNullValuesIgnored());
}
Also used : ArrayList(java.util.ArrayList) OType(com.orientechnologies.orient.core.metadata.schema.OType) OCollate(com.orientechnologies.orient.core.collate.OCollate)

Example 32 with OType

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

the class OStorageConfiguration method fromStream.

public void fromStream(final byte[] stream, int offset, int length) {
    clear();
    final String[] values = new String(stream, offset, length).split("\\|");
    int index = 0;
    version = Integer.parseInt(read(values[index++]));
    name = read(values[index++]);
    schemaRecordId = read(values[index++]);
    dictionaryRecordId = read(values[index++]);
    if (version > 0)
        indexMgrRecordId = read(values[index++]);
    else
        // @COMPATIBILITY
        indexMgrRecordId = null;
    localeLanguage = read(values[index++]);
    localeCountry = read(values[index++]);
    dateFormat = read(values[index++]);
    dateTimeFormat = read(values[index++]);
    // @COMPATIBILITY 1.2.0
    if (version >= 4) {
        timeZone = TimeZone.getTimeZone(read(values[index++]));
        charset = read(values[index++]);
    }
    final ORecordConflictStrategyFactory conflictStrategyFactory = Orient.instance().getRecordConflictStrategy();
    if (version >= 12)
        conflictStrategy = conflictStrategyFactory.getStrategy(read(values[index++])).getName();
    else
        conflictStrategy = conflictStrategyFactory.getDefaultStrategy();
    // @COMPATIBILITY
    if (version > 1)
        index = phySegmentFromStream(values, index, fileTemplate);
    int size = Integer.parseInt(read(values[index++]));
    // PREPARE THE LIST OF CLUSTERS
    clusters.clear();
    String determineStorageCompression = null;
    for (int i = 0; i < size; ++i) {
        final int clusterId = Integer.parseInt(read(values[index++]));
        if (clusterId == -1)
            continue;
        final String clusterName = read(values[index++]);
        final int targetDataSegmentId = version >= 3 ? Integer.parseInt(read(values[index++])) : 0;
        final String clusterType = read(values[index++]);
        final OStorageClusterConfiguration currentCluster;
        if (clusterType.equals("d")) {
            final boolean cc = Boolean.valueOf(read(values[index++]));
            final float bb = Float.valueOf(read(values[index++]));
            final float aa = Float.valueOf(read(values[index++]));
            final String clusterCompression = read(values[index++]);
            if (determineStorageCompression == null)
                // TRY TO DETERMINE THE STORAGE COMPRESSION. BEFORE VERSION 11 IT WASN'T STORED IN STORAGE CFG, SO GET FROM THE FIRST
                // CLUSTER
                determineStorageCompression = clusterCompression;
            String clusterEncryption = null;
            if (version >= 15)
                clusterEncryption = read(values[index++]);
            final String clusterConflictStrategy;
            if (version >= 12)
                clusterConflictStrategy = read(values[index++]);
            else
                // INHERIT THE STRATEGY IN STORAGE
                clusterConflictStrategy = null;
            OStorageClusterConfiguration.STATUS status = OStorageClusterConfiguration.STATUS.ONLINE;
            if (version >= 13)
                status = OStorageClusterConfiguration.STATUS.valueOf(read(values[index++]));
            currentCluster = new OStoragePaginatedClusterConfiguration(this, clusterId, clusterName, null, cc, bb, aa, clusterCompression, clusterEncryption, configuration.getValueAsString(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY), clusterConflictStrategy, status);
        } else if (clusterType.equals("p"))
            // PHYSICAL CLUSTER
            throw new IllegalArgumentException("Cluster of storage 'local' are not supported since 2.0");
        else
            throw new IllegalArgumentException("Unsupported cluster type: " + clusterType);
        // MAKE ROOMS, EVENTUALLY FILLING EMPTIES ENTRIES
        for (int c = clusters.size(); c <= clusterId; ++c) clusters.add(null);
        clusters.set(clusterId, currentCluster);
    }
    if (version < 13) {
        // OLD: READ DATA-SEGMENTS
        size = Integer.parseInt(read(values[index++]));
        for (int i = 0; i < size; ++i) {
            int dataId = Integer.parseInt(read(values[index++]));
            if (dataId == -1)
                continue;
            read(values[index++]);
            read(values[index++]);
            read(values[index++]);
            read(values[index++]);
        }
        // READ TX_SEGMENT STUFF
        read(values[index++]);
        read(values[index++]);
        read(values[index++]);
        read(values[index++]);
        read(values[index++]);
    }
    size = Integer.parseInt(read(values[index++]));
    clearProperties();
    for (int i = 0; i < size; ++i) setProperty(read(values[index++]), read(values[index++]));
    if (version >= 7)
        binaryFormatVersion = Integer.parseInt(read(values[index++]));
    else if (version == 6)
        binaryFormatVersion = 9;
    else
        binaryFormatVersion = 8;
    if (version >= 8)
        clusterSelection = read(values[index++]);
    else
        // DEFAULT = ROUND-ROBIN
        clusterSelection = ORoundRobinClusterSelectionStrategy.NAME;
    if (version >= 9)
        setMinimumClusters(Integer.parseInt(read(values[index++])));
    else
        // DEFAULT = 1
        setMinimumClusters(1);
    autoInitClusters();
    if (version >= 10) {
        recordSerializer = read(values[index++]);
        recordSerializerVersion = Integer.parseInt(read(values[index++]));
    }
    if (version >= 11) {
        // READ THE CONFIGURATION
        final int cfgSize = Integer.parseInt(read(values[index++]));
        for (int i = 0; i < cfgSize; ++i) {
            final String key = read(values[index++]);
            final Object value = read(values[index++]);
            final OGlobalConfiguration cfg = OGlobalConfiguration.findByKey(key);
            if (cfg != null) {
                if (value != null)
                    configuration.setValue(key, OType.convert(value, cfg.getType()));
            } else
                OLogManager.instance().warn(this, "Ignored storage configuration because not supported: %s=%s", key, value);
        }
    } else
        // SAVE STORAGE COMPRESSION METHOD AS PROPERTY
        configuration.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, determineStorageCompression);
    if (version > 15) {
        final int enginesSize = Integer.parseInt(read(values[index++]));
        for (int i = 0; i < enginesSize; i++) {
            final String name = read(values[index++]);
            final String algorithm = read(values[index++]);
            final String indexType;
            if (version > 16)
                indexType = read(values[index++]);
            else
                indexType = "";
            final byte valueSerializerId = Byte.parseByte(read(values[index++]));
            final byte keySerializerId = Byte.parseByte(read(values[index++]));
            final boolean isAutomatic = Boolean.parseBoolean(read((values[index++])));
            final Boolean durableInNonTxMode;
            if (read(values[index]) == null) {
                durableInNonTxMode = null;
                index++;
            } else
                durableInNonTxMode = Boolean.parseBoolean(read(values[index++]));
            final int version = Integer.parseInt(read(values[index++]));
            final boolean nullValuesSupport = Boolean.parseBoolean(read((values[index++])));
            final int keySize = Integer.parseInt(read(values[index++]));
            final int typesLength = Integer.parseInt(read(values[index++]));
            final OType[] types = new OType[typesLength];
            for (int n = 0; n < types.length; n++) {
                final OType type = OType.valueOf(read(values[index++]));
                types[n] = type;
            }
            final int propertiesSize = Integer.parseInt(read(values[index++]));
            final Map<String, String> engineProperties;
            if (propertiesSize == 0)
                engineProperties = null;
            else {
                engineProperties = new HashMap<String, String>(propertiesSize);
                for (int n = 0; n < propertiesSize; n++) {
                    final String key = read(values[index++]);
                    final String value = read(values[index++]);
                    engineProperties.put(key, value);
                }
            }
            final IndexEngineData indexEngineData = new IndexEngineData(name, algorithm, indexType, durableInNonTxMode, version, valueSerializerId, keySerializerId, isAutomatic, types, nullValuesSupport, keySize, engineProperties);
            indexEngines.put(name.toLowerCase(getLocaleInstance()), indexEngineData);
        }
    }
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) ORecordConflictStrategyFactory(com.orientechnologies.orient.core.conflict.ORecordConflictStrategyFactory)

Example 33 with OType

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

the class OStorageConfiguration method toStream.

/**
   * Added version used for managed Network Versioning.
   *
   * @param iNetworkVersion
   * @return
   * @throws OSerializationException
   */
public byte[] toStream(final int iNetworkVersion) throws OSerializationException {
    final StringBuilder buffer = new StringBuilder(8192);
    write(buffer, CURRENT_VERSION);
    write(buffer, name);
    write(buffer, schemaRecordId);
    write(buffer, dictionaryRecordId);
    write(buffer, indexMgrRecordId);
    write(buffer, localeLanguage);
    write(buffer, localeCountry);
    write(buffer, dateFormat);
    write(buffer, dateTimeFormat);
    write(buffer, timeZone.getID());
    write(buffer, charset);
    if (iNetworkVersion > 24)
        write(buffer, conflictStrategy);
    phySegmentToStream(buffer, fileTemplate);
    write(buffer, clusters.size());
    for (OStorageClusterConfiguration c : clusters) {
        if (c == null) {
            write(buffer, -1);
            continue;
        }
        write(buffer, c.getId());
        write(buffer, c.getName());
        write(buffer, c.getDataSegmentId());
        if (c instanceof OStoragePaginatedClusterConfiguration) {
            write(buffer, "d");
            final OStoragePaginatedClusterConfiguration paginatedClusterConfiguration = (OStoragePaginatedClusterConfiguration) c;
            write(buffer, paginatedClusterConfiguration.useWal);
            write(buffer, paginatedClusterConfiguration.recordOverflowGrowFactor);
            write(buffer, paginatedClusterConfiguration.recordGrowFactor);
            write(buffer, paginatedClusterConfiguration.compression);
            if (iNetworkVersion >= 31)
                write(buffer, paginatedClusterConfiguration.encryption);
            if (iNetworkVersion > 24)
                write(buffer, paginatedClusterConfiguration.conflictStrategy);
            if (iNetworkVersion > 25)
                write(buffer, paginatedClusterConfiguration.getStatus().name().toString());
        }
    }
    if (iNetworkVersion <= 25) {
        // dataSegment array
        write(buffer, 0);
        // tx Segment File
        write(buffer, "");
        write(buffer, "");
        write(buffer, 0);
        // tx segment flags
        write(buffer, false);
        write(buffer, false);
    }
    synchronized (properties) {
        write(buffer, properties.size());
        for (OStorageEntryConfiguration e : properties) entryToStream(buffer, e);
    }
    write(buffer, binaryFormatVersion);
    write(buffer, clusterSelection);
    write(buffer, getMinimumClusters());
    if (iNetworkVersion > 24) {
        write(buffer, recordSerializer);
        write(buffer, recordSerializerVersion);
        // WRITE CONFIGURATION
        write(buffer, configuration.getContextSize());
        for (String k : configuration.getContextKeys()) {
            final OGlobalConfiguration cfg = OGlobalConfiguration.findByKey(k);
            write(buffer, k);
            write(buffer, cfg.isHidden() ? null : configuration.getValueAsString(cfg));
        }
    }
    write(buffer, indexEngines.size());
    for (IndexEngineData engineData : indexEngines.values()) {
        write(buffer, engineData.name);
        write(buffer, engineData.algorithm);
        write(buffer, engineData.indexType == null ? "" : engineData.indexType);
        write(buffer, engineData.valueSerializerId);
        write(buffer, engineData.keySerializedId);
        write(buffer, engineData.isAutomatic);
        write(buffer, engineData.durableInNonTxMode);
        write(buffer, engineData.version);
        write(buffer, engineData.nullValuesSupport);
        write(buffer, engineData.keySize);
        if (engineData.keyTypes != null) {
            write(buffer, engineData.keyTypes.length);
            for (OType type : engineData.keyTypes) {
                write(buffer, type.name());
            }
        } else {
            write(buffer, 0);
        }
        if (engineData.engineProperties == null) {
            write(buffer, 0);
        } else {
            write(buffer, engineData.engineProperties.size());
            for (Map.Entry<String, String> property : engineData.engineProperties.entrySet()) {
                write(buffer, property.getKey());
                write(buffer, property.getValue());
            }
        }
    }
    // PLAIN: ALLOCATE ENOUGH SPACE TO REUSE IT EVERY TIME
    buffer.append("|");
    return buffer.toString().getBytes();
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 34 with OType

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

the class ODocumentFieldWalker method walkDocument.

private void walkDocument(ODocument document, ODocumentFieldVisitor fieldWalker, Set<ODocument> walked) {
    if (walked.contains(document))
        return;
    walked.add(document);
    boolean oldLazyLoad = document.isLazyLoad();
    document.setLazyLoad(false);
    final boolean updateMode = fieldWalker.updateMode();
    final OClass clazz = ODocumentInternal.getImmutableSchemaClass(document);
    for (String fieldName : document.fieldNames()) {
        final OType concreteType = document.fieldType(fieldName);
        OType fieldType = concreteType;
        OType linkedType = null;
        if (fieldType == null && clazz != null) {
            OProperty property = clazz.getProperty(fieldName);
            if (property != null) {
                fieldType = property.getType();
                linkedType = property.getLinkedType();
            }
        }
        Object fieldValue = document.field(fieldName, fieldType);
        Object newValue = fieldWalker.visitField(fieldType, linkedType, fieldValue);
        boolean updated;
        if (updateMode)
            updated = updateFieldValueIfChanged(document, fieldName, fieldValue, newValue, concreteType);
        else
            updated = false;
        // 3. document is not not embedded.
        if (!updated && fieldValue != null && !(OType.LINK.equals(fieldType) || OType.LINKBAG.equals(fieldType) || OType.LINKLIST.equals(fieldType) || OType.LINKSET.equals(fieldType) || (fieldValue instanceof ORecordLazyMultiValue))) {
            if (fieldWalker.goDeeper(fieldType, linkedType, fieldValue)) {
                if (fieldValue instanceof Map)
                    walkMap((Map) fieldValue, fieldType, fieldWalker, walked);
                else if (fieldValue instanceof ODocument) {
                    final ODocument doc = (ODocument) fieldValue;
                    if (OType.EMBEDDED.equals(fieldType) || doc.isEmbedded())
                        walkDocument((ODocument) fieldValue, fieldWalker);
                } else if (OMultiValue.isIterable(fieldValue))
                    walkIterable(OMultiValue.getMultiValueIterable(fieldValue), fieldType, fieldWalker, walked);
            }
        }
        if (!fieldWalker.goFurther(fieldType, linkedType, fieldValue, newValue)) {
            document.setLazyLoad(oldLazyLoad);
            return;
        }
    }
    document.setLazyLoad(oldLazyLoad);
}
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) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 35 with OType

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

the class OAbstractLookupTransformer method lookup.

protected Object lookup(Object joinValue, final boolean iReturnRIDS) {
    Object result = null;
    if (joinValue != null) {
        if (sqlQuery == null && index == null) {
            // ONLY THE FIRST TIME
            if (lookup.toUpperCase().startsWith("SELECT"))
                sqlQuery = new OSQLSynchQuery<ODocument>(lookup);
            else {
                index = pipeline.getDocumentDatabase().getMetadata().getIndexManager().getIndex(lookup);
                if (index == null) {
                    log(OETLProcessor.LOG_LEVELS.DEBUG, "WARNING: index %s not found. Lookups could be really slow", lookup);
                    final String[] parts = lookup.split("\\.");
                    sqlQuery = new OSQLSynchQuery<ODocument>("SELECT FROM " + parts[0] + " WHERE " + parts[1] + " = ?");
                }
            }
        }
        if (index != null) {
            final OType idxFieldType = index.getDefinition().getTypes()[0];
            joinValue = OType.convert(joinValue, idxFieldType.getDefaultJavaType());
            result = index.get(joinValue);
        } else {
            if (sqlQuery instanceof OSQLSynchQuery)
                ((OSQLSynchQuery) sqlQuery).resetPagination();
            result = pipeline.getDocumentDatabase().query(sqlQuery, joinValue);
        }
        if (result != null && result instanceof Collection) {
            final Collection coll = (Collection) result;
            if (!coll.isEmpty()) {
                if (iReturnRIDS) {
                    // CONVERT COLLECTION OF RECORDS IN RIDS
                    final List<ORID> resultRIDs = new ArrayList<ORID>(coll.size());
                    for (Object o : coll) {
                        if (o instanceof OIdentifiable)
                            resultRIDs.add(((OIdentifiable) o).getIdentity());
                    }
                    result = resultRIDs;
                }
            } else
                result = null;
        } else if (result instanceof OIdentifiable) {
            if (iReturnRIDS)
                result = ((OIdentifiable) result).getIdentity();
            else
                result = ((OIdentifiable) result).getRecord();
        }
    }
    return result;
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OType(com.orientechnologies.orient.core.metadata.schema.OType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) 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