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 2012 Orient Technologies.
*
* 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.
*/
package com.orientechnologies.orient.core.index;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.index.engine.OSBTreeIndexEngine;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
import com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage;
/**
* Default OrientDB index factory for indexes based on MVRBTree.
* Supports index types :
*
*
UNIQUE
*
NOTUNIQUE
*
FULLTEXT
*
DICTIONARY
*
*/
public class ODefaultIndexFactory implements OIndexFactory {
public static final String SBTREE_ALGORITHM = "SBTREE";
public static final String SBTREEBONSAI_VALUE_CONTAINER = "SBTREEBONSAISET";
public static final String NONE_VALUE_CONTAINER = "NONE";
private static final Set TYPES;
private static final Set ALGORITHMS;
static {
final Set types = new HashSet();
types.add(OClass.INDEX_TYPE.UNIQUE.toString());
types.add(OClass.INDEX_TYPE.NOTUNIQUE.toString());
types.add(OClass.INDEX_TYPE.FULLTEXT.toString());
types.add(OClass.INDEX_TYPE.DICTIONARY.toString());
TYPES = Collections.unmodifiableSet(types);
}
static {
final Set algorithms = new HashSet();
algorithms.add(SBTREE_ALGORITHM);
ALGORITHMS = Collections.unmodifiableSet(algorithms);
}
public static boolean isMultiValueIndex(final String indexType) {
switch (OClass.INDEX_TYPE.valueOf(indexType)) {
case UNIQUE:
case UNIQUE_HASH_INDEX:
case DICTIONARY:
case DICTIONARY_HASH_INDEX:
return false;
}
return true;
}
/**
* Index types :
*
*
UNIQUE
*
NOTUNIQUE
*
FULLTEXT
*
DICTIONARY
*
*/
public Set getTypes() {
return TYPES;
}
public Set getAlgorithms() {
return ALGORITHMS;
}
public OIndexInternal createIndex(String name, ODatabaseDocumentInternal database, String indexType, String algorithm,
String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException {
if (valueContainerAlgorithm == null)
valueContainerAlgorithm = NONE_VALUE_CONTAINER;
if (SBTREE_ALGORITHM.equals(algorithm))
return createSBTreeIndex(name, indexType, valueContainerAlgorithm, metadata, (OAbstractPaginatedStorage) database
.getStorage().getUnderlying(), version);
throw new OConfigurationException("Unsupported type : " + indexType);
}
private OIndexInternal createSBTreeIndex(String name, String indexType, String valueContainerAlgorithm, ODocument metadata,
OAbstractPaginatedStorage storage, int version) {
Boolean durableInNonTxMode;
Object durable = null;
if (metadata != null) {
durable = metadata.field("durableInNonTxMode");
}
if (durable instanceof Boolean)
durableInNonTxMode = (Boolean) durable;
else
durableInNonTxMode = null;
if (OClass.INDEX_TYPE.UNIQUE.toString().equals(indexType)) {
return new OIndexUnique(indexType, SBTREE_ALGORITHM, new OSBTreeIndexEngine(name, durableInNonTxMode, storage,
version), valueContainerAlgorithm, metadata);
} else if (OClass.INDEX_TYPE.NOTUNIQUE.toString().equals(indexType)) {
return new OIndexNotUnique(indexType, SBTREE_ALGORITHM, new OSBTreeIndexEngine>(name, durableInNonTxMode,
storage, version), valueContainerAlgorithm, metadata);
} else if (OClass.INDEX_TYPE.FULLTEXT.toString().equals(indexType)) {
return new OIndexFullText(indexType, SBTREE_ALGORITHM, new OSBTreeIndexEngine>(name, durableInNonTxMode,
storage, version), valueContainerAlgorithm, metadata);
} else if (OClass.INDEX_TYPE.DICTIONARY.toString().equals(indexType)) {
return new OIndexDictionary(indexType, SBTREE_ALGORITHM, new OSBTreeIndexEngine(name, durableInNonTxMode,
storage, version), valueContainerAlgorithm, metadata);
}
throw new OConfigurationException("Unsupported type : " + indexType);
}
}