Java Code Examples for com.thinkaurelius.titan.core.PropertyKey#name()

The following examples show how to use com.thinkaurelius.titan.core.PropertyKey#name() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public void addIndexKey(final TitanGraphIndex index, final PropertyKey key, Parameter... parameters) {
    Preconditions.checkArgument(index != null && key != null && index instanceof TitanGraphIndexWrapper
            && !(key instanceof BaseKey), "Need to provide valid index and key");
    if (parameters == null) parameters = new Parameter[0];
    IndexType indexType = ((TitanGraphIndexWrapper) index).getBaseIndex();
    Preconditions.checkArgument(indexType instanceof MixedIndexType, "Can only add keys to an external index, not %s", index.name());
    Preconditions.checkArgument(indexType instanceof IndexTypeWrapper && key instanceof TitanSchemaVertex
            && ((IndexTypeWrapper) indexType).getSchemaBase() instanceof TitanSchemaVertex);

    TitanSchemaVertex indexVertex = (TitanSchemaVertex) ((IndexTypeWrapper) indexType).getSchemaBase();

    for (IndexField field : indexType.getFieldKeys())
        Preconditions.checkArgument(!field.getFieldKey().equals(key), "Key [%s] has already been added to index %s", key.name(), index.name());

    //Assemble parameters
    boolean addMappingParameter = !ParameterType.MAPPED_NAME.hasParameter(parameters);
    Parameter[] extendedParas = new Parameter[parameters.length + 1 + (addMappingParameter ? 1 : 0)];
    System.arraycopy(parameters, 0, extendedParas, 0, parameters.length);
    int arrPosition = parameters.length;
    if (addMappingParameter) extendedParas[arrPosition++] = ParameterType.MAPPED_NAME.getParameter(
            graph.getIndexSerializer().getDefaultFieldName(key, parameters, indexType.getBackingIndexName()));
    extendedParas[arrPosition++] = ParameterType.STATUS.getParameter(key.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);

    addSchemaEdge(indexVertex, key, TypeDefinitionCategory.INDEX_FIELD, extendedParas);
    updateSchemaVertex(indexVertex);
    indexType.resetCache();
    //Check to see if the index supports this
    if (!graph.getIndexSerializer().supports((MixedIndexType) indexType, ParameterIndexField.of(key, parameters))) {
        throw new TitanException("Could not register new index field '" + key.name() + "' with index backend as the data type, cardinality or parameter combination is not supported.");
    }

    try {
        IndexSerializer.register((MixedIndexType) indexType, key, transaction.getTxHandle());
    } catch (BackendException e) {
        throw new TitanException("Could not register new index field with index backend", e);
    }
    if (!indexVertex.isNew()) updatedTypes.add(indexVertex);
    if (!key.isNew()) updateIndex(index, SchemaAction.REGISTER_INDEX);
}
 
Example 2
Source File: PropertyKeyDefinition.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public PropertyKeyDefinition(PropertyKey key) {
    this(key.name(),key.longId(),key.cardinality(),key.dataType());
}