Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
*
* * Copyright 2010-2016 OrientDB LTD (http://orientdb.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://orientdb.com
*
*/
package com.orientechnologies.orient.core.index;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.OMultiValueChangeEvent;
import com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine;
import com.orientechnologies.orient.core.db.record.ORecordElement;
import com.orientechnologies.orient.core.db.record.OTrackedMultiValue;
import com.orientechnologies.orient.core.exception.ORecordNotFoundException;
import com.orientechnologies.orient.core.metadata.schema.OImmutableClass;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ODocumentInternal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Handles indexing when records change.
*
* @author Andrey Lomakin (a.lomakin-at-orientdb.com), Artem Orobets
*/
public class OClassIndexManager {
public static void checkIndexesAfterCreate(
ODocument document, ODatabaseDocumentInternal database) {
document = checkForLoading(document);
processIndexOnCreate(database, document);
}
public static void reIndex(ODocument document, ODatabaseDocumentInternal database, OIndex index) {
document = checkForLoading(document);
addIndexEntry(document, document.getIdentity(), index);
}
public static void processIndexOnCreate(ODatabaseDocumentInternal database, ODocument document) {
final OImmutableClass cls = ODocumentInternal.getImmutableSchemaClass(database, document);
if (cls != null) {
final Collection indexes = cls.getRawIndexes();
addIndexesEntries(database, document, indexes);
}
}
public static void checkIndexesAfterUpdate(
ODocument iDocument, ODatabaseDocumentInternal database) {
iDocument = checkForLoading(iDocument);
processIndexOnUpdate(database, iDocument);
}
public static void processIndexOnUpdate(ODatabaseDocumentInternal database, ODocument iDocument) {
final OImmutableClass cls = ODocumentInternal.getImmutableSchemaClass(database, iDocument);
if (cls == null) {
return;
}
final Collection indexes = cls.getRawIndexes();
if (!indexes.isEmpty()) {
final Set dirtyFields = new HashSet<>(Arrays.asList(iDocument.getDirtyFields()));
if (!dirtyFields.isEmpty())
for (final OIndex index : indexes) {
processIndexUpdate(iDocument, dirtyFields, index);
}
}
}
public static void checkIndexesAfterDelete(
ODocument iDocument, ODatabaseDocumentInternal database) {
processIndexOnDelete(database, iDocument);
}
protected static void putInIndex(OIndex index, Object key, OIdentifiable value) {
index.put(key, value);
}
protected static void removeFromIndex(OIndex index, Object key, OIdentifiable value) {
index.remove(key, value);
}
private static void processCompositeIndexUpdate(
final OIndex index, final Set dirtyFields, final ODocument iRecord) {
final OCompositeIndexDefinition indexDefinition =
(OCompositeIndexDefinition) index.getDefinition();
final List indexFields = indexDefinition.getFields();
final String multiValueField = indexDefinition.getMultiValueField();
for (final String indexField : indexFields) {
if (dirtyFields.contains(indexField)) {
final List