use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class ManagementSystem method createCompositeIndex.
private TitanGraphIndex createCompositeIndex(String indexName, ElementCategory elementCategory, boolean unique, TitanSchemaType constraint, PropertyKey... keys) {
checkIndexName(indexName);
Preconditions.checkArgument(keys != null && keys.length > 0, "Need to provide keys to index [%s]", indexName);
Preconditions.checkArgument(!unique || elementCategory == ElementCategory.VERTEX, "Unique indexes can only be created on vertices [%s]", indexName);
boolean allSingleKeys = true;
boolean oneNewKey = false;
for (PropertyKey key : keys) {
Preconditions.checkArgument(key != null && key instanceof PropertyKeyVertex, "Need to provide valid keys: %s", key);
if (key.cardinality() != Cardinality.SINGLE)
allSingleKeys = false;
if (key.isNew())
oneNewKey = true;
else
updatedTypes.add((PropertyKeyVertex) key);
}
Cardinality indexCardinality;
if (unique)
indexCardinality = Cardinality.SINGLE;
else
indexCardinality = (allSingleKeys ? Cardinality.SET : Cardinality.LIST);
TypeDefinitionMap def = new TypeDefinitionMap();
def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, true);
def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
def.setValue(TypeDefinitionCategory.BACKING_INDEX, Token.INTERNAL_INDEX_NAME);
def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, indexCardinality);
def.setValue(TypeDefinitionCategory.STATUS, oneNewKey ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX, indexName, def);
for (int i = 0; i < keys.length; i++) {
Parameter[] paras = { ParameterType.INDEX_POSITION.getParameter(i) };
addSchemaEdge(indexVertex, keys[i], TypeDefinitionCategory.INDEX_FIELD, paras);
}
Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
if (constraint != null) {
addSchemaEdge(indexVertex, (TitanSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
}
updateSchemaVertex(indexVertex);
TitanGraphIndexWrapper index = new TitanGraphIndexWrapper(indexVertex.asIndexType());
if (!oneNewKey)
updateIndex(index, SchemaAction.REGISTER_INDEX);
return index;
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class ManagementSystem method updateIndex.
/* --------------
Schema Update
--------------- */
@Override
public IndexJobFuture updateIndex(TitanIndex index, SchemaAction updateAction) {
Preconditions.checkArgument(index != null, "Need to provide an index");
Preconditions.checkArgument(updateAction != null, "Need to provide update action");
TitanSchemaVertex schemaVertex = getSchemaVertex(index);
Set<TitanSchemaVertex> dependentTypes;
Set<PropertyKeyVertex> keySubset = ImmutableSet.of();
if (index instanceof RelationTypeIndex) {
dependentTypes = ImmutableSet.of((TitanSchemaVertex) ((InternalRelationType) schemaVertex).getBaseType());
if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
return null;
} else if (index instanceof TitanGraphIndex) {
IndexType indexType = schemaVertex.asIndexType();
dependentTypes = Sets.newHashSet();
if (indexType.isCompositeIndex()) {
if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
return null;
for (PropertyKey key : ((TitanGraphIndex) index).getFieldKeys()) {
dependentTypes.add((PropertyKeyVertex) key);
}
} else {
keySubset = Sets.newHashSet();
MixedIndexType cindexType = (MixedIndexType) indexType;
Set<SchemaStatus> applicableStatus = updateAction.getApplicableStatus();
for (ParameterIndexField field : cindexType.getFieldKeys()) {
if (applicableStatus.contains(field.getStatus()))
keySubset.add((PropertyKeyVertex) field.getFieldKey());
}
if (keySubset.isEmpty())
return null;
dependentTypes.addAll(keySubset);
}
} else
throw new UnsupportedOperationException("Updates not supported for index: " + index);
IndexIdentifier indexId = new IndexIdentifier(index);
StandardScanner.Builder builder;
IndexJobFuture future;
switch(updateAction) {
case REGISTER_INDEX:
setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
updatedTypes.add(schemaVertex);
updatedTypes.addAll(dependentTypes);
setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.REGISTERED, keySubset));
future = new EmptyIndexJobFuture();
break;
case REINDEX:
builder = graph.getBackend().buildEdgeScanJob();
builder.setFinishJob(indexId.getIndexJobFinisher(graph, SchemaAction.ENABLE_INDEX));
builder.setJobId(indexId);
builder.setJob(VertexJobConverter.convert(graph, new IndexRepairJob(indexId.indexName, indexId.relationTypeName)));
try {
future = builder.execute();
} catch (BackendException e) {
throw new TitanException(e);
}
break;
case ENABLE_INDEX:
setStatus(schemaVertex, SchemaStatus.ENABLED, keySubset);
updatedTypes.add(schemaVertex);
if (!keySubset.isEmpty())
updatedTypes.addAll(dependentTypes);
future = new EmptyIndexJobFuture();
break;
case DISABLE_INDEX:
setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
updatedTypes.add(schemaVertex);
if (!keySubset.isEmpty())
updatedTypes.addAll(dependentTypes);
setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.DISABLED, keySubset));
future = new EmptyIndexJobFuture();
break;
case REMOVE_INDEX:
if (index instanceof RelationTypeIndex) {
builder = graph.getBackend().buildEdgeScanJob();
} else {
TitanGraphIndex gindex = (TitanGraphIndex) index;
if (gindex.isMixedIndex())
throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
builder = graph.getBackend().buildGraphIndexScanJob();
}
builder.setFinishJob(indexId.getIndexJobFinisher());
builder.setJobId(indexId);
builder.setJob(new IndexRemoveJob(graph, indexId.indexName, indexId.relationTypeName));
try {
future = builder.execute();
} catch (BackendException e) {
throw new TitanException(e);
}
break;
default:
throw new UnsupportedOperationException("Update action not supported: " + updateAction);
}
return future;
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class ModificationDeserializer method parseRelation.
public static InternalRelation parseRelation(TransactionLogHeader.Modification modification, StandardTitanTx tx) {
Change state = modification.state;
assert state.isProper();
long outVertexId = modification.outVertexId;
Entry relEntry = modification.relationEntry;
InternalVertex outVertex = tx.getInternalVertex(outVertexId);
//Special relation parsing, compare to {@link RelationConstructor}
RelationCache relCache = tx.getEdgeSerializer().readRelation(relEntry, false, tx);
assert relCache.direction == Direction.OUT;
InternalRelationType type = (InternalRelationType) tx.getExistingRelationType(relCache.typeId);
assert type.getBaseType() == null;
InternalRelation rel;
if (type.isPropertyKey()) {
if (state == Change.REMOVED) {
rel = new StandardVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), ElementLifeCycle.Removed);
} else {
rel = new CacheVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), relEntry);
}
} else {
assert type.isEdgeLabel();
InternalVertex otherVertex = tx.getInternalVertex(relCache.getOtherVertexId());
if (state == Change.REMOVED) {
rel = new StandardEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, ElementLifeCycle.Removed);
} else {
rel = new CacheEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, relEntry);
}
}
if (state == Change.REMOVED && relCache.hasProperties()) {
//copy over properties
for (LongObjectCursor<Object> entry : relCache) {
rel.setPropertyDirect(tx.getExistingPropertyKey(entry.key), entry.value);
}
}
return rel;
}
use of com.thinkaurelius.titan.core.PropertyKey in project incubator-atlas by apache.
the class Titan0GraphManagement method createExactMatchIndex.
@Override
public void createExactMatchIndex(String propertyName, boolean enforceUniqueness, List<AtlasPropertyKey> propertyKeys) {
TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
for (AtlasPropertyKey key : propertyKeys) {
PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
indexBuilder.addKey(titanKey);
}
if (enforceUniqueness) {
indexBuilder.unique();
}
indexBuilder.buildCompositeIndex();
}
use of com.thinkaurelius.titan.core.PropertyKey in project incubator-atlas by apache.
the class Titan0GraphManagement method createFullTextIndex.
@Override
public void createFullTextIndex(String indexName, AtlasPropertyKey propertyKey, String backingIndex) {
PropertyKey fullText = TitanObjectFactory.createPropertyKey(propertyKey);
management.buildIndex(indexName, Vertex.class).addKey(fullText, com.thinkaurelius.titan.core.schema.Parameter.of("mapping", Mapping.TEXT)).buildMixedIndex(backingIndex);
}
Aggregations