Search in sources :

Example 26 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.

the class OClassImpl method firePropertyNameMigration.

public void firePropertyNameMigration(final ODatabaseDocument database, final String propertyName, final String newPropertyName, final OType type) {
    final boolean strictSQL = ((ODatabaseInternal) database).getStorage().getConfiguration().isStrictSql();
    database.query(new OSQLAsynchQuery<Object>("select from " + getEscapedName(name, strictSQL) + " where " + getEscapedName(propertyName, strictSQL) + " is not null ", new OCommandResultListener() {

        @Override
        public boolean result(Object iRecord) {
            final ODocument record = ((OIdentifiable) iRecord).getRecord();
            record.setFieldType(propertyName, type);
            record.field(newPropertyName, record.field(propertyName), type);
            database.save(record);
            return true;
        }

        @Override
        public void end() {
        }

        @Override
        public Object getResult() {
            return null;
        }
    }));
}
Also used : ODatabaseInternal(com.orientechnologies.orient.core.db.ODatabaseInternal) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 27 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.

the class OGlobalPropertyImpl method toDocument.

@Override
public ODocument toDocument() {
    final ODocument doc = new ODocument();
    doc.field("name", name);
    doc.field("type", type.name());
    doc.field("id", id);
    return doc;
}
Also used : ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 28 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.

the class OClassIndexManager method checkIndexes.

private ODocument checkIndexes(ODocument document, TYPE hookType) {
    document = checkForLoading(document);
    ODocument replaced = null;
    final OClass cls = ODocumentInternal.getImmutableSchemaClass(document);
    if (cls != null) {
        final Collection<OIndex<?>> indexes = cls.getIndexes();
        switch(hookType) {
            case BEFORE_CREATE:
                replaced = checkIndexedPropertiesOnCreation(document, indexes);
                break;
            case BEFORE_UPDATE:
                checkIndexedPropertiesOnUpdate(document, indexes);
                break;
            default:
                throw new IllegalArgumentException("Invalid hook type: " + hookType);
        }
    }
    return replaced;
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 29 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.

the class OCompositeIndexDefinition method serializeToStream.

@Override
protected void serializeToStream() {
    super.serializeToStream();
    final List<ODocument> inds = new ArrayList<ODocument>(indexDefinitions.size());
    final List<String> indClasses = new ArrayList<String>(indexDefinitions.size());
    document.field("className", className);
    for (final OIndexDefinition indexDefinition : indexDefinitions) {
        final ODocument indexDocument = indexDefinition.toStream();
        inds.add(indexDocument);
        indClasses.add(indexDefinition.getClass().getName());
    }
    document.field("indexDefinitions", inds, OType.EMBEDDEDLIST);
    document.field("indClasses", indClasses, OType.EMBEDDEDLIST);
    document.field("nullValuesIgnored", isNullValuesIgnored());
}
Also used : ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 30 with ODocument

use of com.orientechnologies.orient.core.record.impl.ODocument 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)

Aggregations

ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2200 Test (org.testng.annotations.Test)651 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)426 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)422 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)277 Test (org.junit.Test)267 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)257 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)244 ORID (com.orientechnologies.orient.core.id.ORID)196 ORecordId (com.orientechnologies.orient.core.id.ORecordId)139 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)122 ArrayList (java.util.ArrayList)118 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)103 HashMap (java.util.HashMap)103 HashSet (java.util.HashSet)96 ORecord (com.orientechnologies.orient.core.record.ORecord)80 Set (java.util.Set)76 OETLBaseTest (com.orientechnologies.orient.etl.OETLBaseTest)75 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)68 Collection (java.util.Collection)55