Search in sources :

Example 11 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 12 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 13 with OType

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

the class OCompositeIndexDefinition method toCreateIndexDDL.

/**
   * {@inheritDoc}
   */
public String toCreateIndexDDL(final String indexName, final String indexType, String engine) {
    final StringBuilder ddl = new StringBuilder("create index ");
    ddl.append(indexName).append(" on ").append(className).append(" ( ");
    final Iterator<String> fieldIterator = getFieldsToIndex().iterator();
    if (fieldIterator.hasNext()) {
        ddl.append(fieldIterator.next());
        while (fieldIterator.hasNext()) {
            ddl.append(", ").append(fieldIterator.next());
        }
    }
    ddl.append(" ) ").append(indexType).append(' ');
    if (engine != null)
        ddl.append(OCommandExecutorSQLCreateIndex.KEYWORD_ENGINE + " " + engine).append(' ');
    if (multiValueDefinitionIndex == -1) {
        boolean first = true;
        for (OType oType : getTypes()) {
            if (first)
                first = false;
            else
                ddl.append(", ");
            ddl.append(oType.name());
        }
    }
    return ddl.toString();
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType)

Example 14 with OType

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

the class OIndexAbstract method loadMetadataInternal.

public static OIndexMetadata loadMetadataInternal(final ODocument config, final String type, final String algorithm, final String valueContainerAlgorithm) {
    final String indexName = config.field(OIndexInternal.CONFIG_NAME);
    final ODocument indexDefinitionDoc = config.field(OIndexInternal.INDEX_DEFINITION);
    OIndexDefinition loadedIndexDefinition = null;
    if (indexDefinitionDoc != null) {
        try {
            final String indexDefClassName = config.field(OIndexInternal.INDEX_DEFINITION_CLASS);
            final Class<?> indexDefClass = Class.forName(indexDefClassName);
            loadedIndexDefinition = (OIndexDefinition) indexDefClass.getDeclaredConstructor().newInstance();
            loadedIndexDefinition.fromStream(indexDefinitionDoc);
        } catch (final ClassNotFoundException e) {
            throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
        } catch (final NoSuchMethodException e) {
            throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
        } catch (final InvocationTargetException e) {
            throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
        } catch (final InstantiationException e) {
            throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
        } catch (final IllegalAccessException e) {
            throw OException.wrapException(new OIndexException("Error during deserialization of index definition"), e);
        }
    } else {
        // @COMPATIBILITY 1.0rc6 new index model was implemented
        final Boolean isAutomatic = config.field(OIndexInternal.CONFIG_AUTOMATIC);
        OIndexFactory factory = OIndexes.getFactory(type, algorithm);
        if (Boolean.TRUE.equals(isAutomatic)) {
            final int pos = indexName.lastIndexOf('.');
            if (pos < 0)
                throw new OIndexException("Cannot convert from old index model to new one. " + "Invalid index name. Dot (.) separator should be present");
            final String className = indexName.substring(0, pos);
            final String propertyName = indexName.substring(pos + 1);
            final String keyTypeStr = config.field(OIndexInternal.CONFIG_KEYTYPE);
            if (keyTypeStr == null)
                throw new OIndexException("Cannot convert from old index model to new one. " + "Index key type is absent");
            final OType keyType = OType.valueOf(keyTypeStr.toUpperCase(Locale.ENGLISH));
            loadedIndexDefinition = new OPropertyIndexDefinition(className, propertyName, keyType);
            config.removeField(OIndexInternal.CONFIG_AUTOMATIC);
            config.removeField(OIndexInternal.CONFIG_KEYTYPE);
        } else if (config.field(OIndexInternal.CONFIG_KEYTYPE) != null) {
            final String keyTypeStr = config.field(OIndexInternal.CONFIG_KEYTYPE);
            final OType keyType = OType.valueOf(keyTypeStr.toUpperCase(Locale.ENGLISH));
            loadedIndexDefinition = new OSimpleKeyIndexDefinition(factory.getLastVersion(), keyType);
            config.removeField(OIndexInternal.CONFIG_KEYTYPE);
        }
    }
    final Set<String> clusters = new HashSet<String>((Collection<String>) config.field(CONFIG_CLUSTERS, OType.EMBEDDEDSET));
    return new OIndexMetadata(indexName, loadedIndexDefinition, clusters, type, algorithm, valueContainerAlgorithm);
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) InvocationTargetException(java.lang.reflect.InvocationTargetException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 15 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)

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