org.janusgraph.core.PropertyKey Java Examples

The following examples show how to use org.janusgraph.core.PropertyKey. 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: AtlasJanusGraph.java    From atlas with Apache License 2.0 6 votes vote down vote up
public AtlasJanusGraph(JanusGraph graphInstance) {
    //determine multi-properties once at startup
    JanusGraphManagement mgmt = null;

    try {
        mgmt = graphInstance.openManagement();

        Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);

        for (PropertyKey key : keys) {
            if (key.cardinality() != Cardinality.SINGLE) {
                multiProperties.add(key.name());
            }
        }
    } finally {
        if (mgmt != null) {
            mgmt.rollback();
        }
    }

    janusGraph = (StandardJanusGraph) graphInstance;
}
 
Example #2
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public String addMixedIndex(String indexName, AtlasPropertyKey propertyKey, boolean isStringField) {
    PropertyKey     janusKey        = AtlasJanusObjectFactory.createPropertyKey(propertyKey);
    JanusGraphIndex janusGraphIndex = management.getGraphIndex(indexName);

    if(isStringField) {
        management.addIndexKey(janusGraphIndex, janusKey, Mapping.STRING.asParameter());
        LOG.debug("created a string type for {} with janueKey {}.", propertyKey.getName(), janusKey);
    } else {
        management.addIndexKey(janusGraphIndex, janusKey);
        LOG.debug("created a default type for {} with janueKey {}.", propertyKey.getName(), janusKey);
    }

    String encodedName = "";
    if(isStringField) {
        encodedName = graph.getIndexFieldName(propertyKey, janusGraphIndex, STRING_PARAMETER_ARRAY);
    } else {
        encodedName = graph.getIndexFieldName(propertyKey, janusGraphIndex);
    }


    LOG.info("property '{}' is encoded to '{}'.", propertyKey.getName(), encodedName);

    return encodedName;
}
 
Example #3
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public AtlasPropertyKey makePropertyKey(String propertyName, Class propertyClass, AtlasCardinality cardinality) {
    if (cardinality.isMany()) {
        newMultProperties.add(propertyName);
    }

    PropertyKeyMaker propertyKeyBuilder = management.makePropertyKey(propertyName).dataType(propertyClass);
    if (cardinality != null) {
        Cardinality janusCardinality = AtlasJanusObjectFactory.createCardinality(cardinality);
        propertyKeyBuilder.cardinality(janusCardinality);
    }

    PropertyKey propertyKey = propertyKeyBuilder.make();

    return GraphDbObjectFactory.createPropertyKey(propertyKey);
}
 
Example #4
Source File: GraphContextImpl.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private PropertyKey getOrCreatePropertyKey(JanusGraphManagement janusGraphManagement, String key, Class<?> dataType, Cardinality cardinality)
{
    PropertyKey propertyKey = janusGraphManagement.getPropertyKey(key);
    if (propertyKey == null)
    {
        propertyKey = janusGraphManagement.makePropertyKey(key).dataType(dataType).cardinality(cardinality).make();
    }
    return propertyKey;
}
 
Example #5
Source File: IndexingFactory.java    From egeria with Apache License 2.0 5 votes vote down vote up
private void createIndex(JanusGraphManagement management,
                         String indexName,
                         String propertyName,
                         String propertyKeyName,
                         boolean unique,
                         Class type) {

    String className = immutableCorePropertyTypes.get(propertyName);

    Class clazz;
    try {
        clazz = Class.forName(className);
    } catch (ClassNotFoundException e) {
        log.error("class not found for property {}", propertyName);
        log.error("NO INDEX created for property {}", propertyName);
        return;
    }

    PropertyKey propertyKey;
    boolean oldKey = false;
    PropertyKey existingPropertyKey = management.getPropertyKey(propertyKeyName);
    if (existingPropertyKey != null) {
        log.debug("property key already exists for property {}", propertyKeyName);
        propertyKey = existingPropertyKey;
        oldKey = true;
    } else {
        log.debug("make property key for property {}", propertyKeyName);
        propertyKey = management.makePropertyKey(propertyKeyName).dataType(clazz).make();
    }

    buildIndex(management,indexName,propertyKey,unique,oldKey,type);

}
 
Example #6
Source File: ScenarioTests.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 5 votes vote down vote up
private static void createHotelSchema(final JanusGraph graph) {
    //another issue, you should only try to create the schema once.
    //you use uniqueness constraints, so you need to define the schema up front with the unique() call,
    //but if you did not use uniqueness constraints, you could just let JanusGraph create the schema for you.
    final JanusGraphManagement mgmt = graph.openManagement();
    final PropertyKey brandtypePropertyKey = mgmt.makePropertyKey("brandtype").dataType(String.class).make();
    mgmt.buildIndex("brandtypeIndex", Vertex.class).addKey(brandtypePropertyKey).unique().buildCompositeIndex();
    final PropertyKey namePropertyKey = mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.buildIndex("nameIndex", Vertex.class).addKey(namePropertyKey).unique().buildCompositeIndex();
    mgmt.makeEdgeLabel(Relationship.hotelBrandType.name()).multiplicity(Multiplicity.MANY2ONE).make();
    mgmt.makeEdgeLabel(Relationship.instanceOf.name()).multiplicity(Multiplicity.MANY2ONE).make();
    mgmt.commit();
}
 
Example #7
Source File: CreateWeightIndex.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Create both <i>posts</i> and <i>follows</i> edges and related index.
 * <br/>
 *
 * Because the property and index for both follows and posts is the same we create them at the same point here.
 */
private void createWeightIndex() {
  LOGGER.info("create weight index");
  EdgeLabel follows = mgt.getEdgeLabel(Schema.FOLLOWS);
  PropertyKey weight = mgt.makePropertyKey(WEIGHT).dataType(Float.class).make();

  mgt.buildIndex(Schema.indexName(Schema.FOLLOWS, WEIGHT), Edge.class).
      addKey(weight).
      indexOnly(follows).
      buildMixedIndex(Schema.BACKING_INDEX);
}
 
Example #8
Source File: AtlasJanusGraph.java    From atlas with Apache License 2.0 5 votes vote down vote up
String getIndexFieldName(AtlasPropertyKey propertyKey, JanusGraphIndex graphIndex, Parameter ... parameters) {
    PropertyKey janusKey = AtlasJanusObjectFactory.createPropertyKey(propertyKey);
    if(parameters == null) {
        parameters = EMPTY_PARAMETER_ARRAY;
    }
    return janusGraph.getIndexSerializer().getDefaultFieldName(janusKey, parameters, graphIndex.getBackingIndex());
}
 
Example #9
Source File: GraphDbObjectFactory.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * @param propertyKey The Gremlin propertyKey.
 *
 */
public static AtlasJanusPropertyKey createPropertyKey(PropertyKey propertyKey) {
    if (propertyKey == null) {
        return null;
    }
    return new AtlasJanusPropertyKey(propertyKey);
}
 
Example #10
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createEdgeCompositeIndex(String propertyName, boolean isUnique, List<AtlasPropertyKey> propertyKeys) {
    IndexBuilder indexBuilder = management.buildIndex(propertyName, Edge.class);

    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey janusKey = AtlasJanusObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(janusKey);
    }

    if (isUnique) {
        indexBuilder.unique();
    }

    indexBuilder.buildCompositeIndex();
}
 
Example #11
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createVertexCompositeIndex(String propertyName, boolean isUnique, List<AtlasPropertyKey> propertyKeys) {
    IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);

    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey janusKey = AtlasJanusObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(janusKey);
    }

    if (isUnique) {
        indexBuilder.unique();
    }

    indexBuilder.buildCompositeIndex();
}
 
Example #12
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void deletePropertyKey(String propertyKey) {
    PropertyKey janusPropertyKey = management.getPropertyKey(propertyKey);

    if (null == janusPropertyKey) return;

    for (int i = 0;; i++) {
        String deletedKeyName = janusPropertyKey + "_deleted_" + i;

        if (null == management.getPropertyKey(deletedKeyName)) {
            management.changeName(janusPropertyKey, deletedKeyName);
            break;
        }
    }
}
 
Example #13
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createFullTextMixedIndex(String indexName, String backingIndex, List<AtlasPropertyKey> propertyKeys) {
    IndexBuilder indexBuilder = management.buildIndex(indexName, Vertex.class);

    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey janusKey = AtlasJanusObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(janusKey, org.janusgraph.core.schema.Parameter.of("mapping", Mapping.TEXT));
    }

    indexBuilder.buildMixedIndex(backingIndex);
}
 
Example #14
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createEdgeIndex(String label, String indexName, AtlasEdgeDirection edgeDirection, List<AtlasPropertyKey> propertyKeys) {
    EdgeLabel edgeLabel = management.getEdgeLabel(label);

    if (edgeLabel == null) {
        edgeLabel = management.makeEdgeLabel(label).make();
    }

    Direction     direction = AtlasJanusObjectFactory.createDirection(edgeDirection);
    PropertyKey[] keys      = AtlasJanusObjectFactory.createPropertyKeys(propertyKeys);

    if (management.getRelationIndex(edgeLabel, indexName) == null) {
        management.buildEdgeIndex(edgeLabel, indexName, direction, keys);
    }
}
 
Example #15
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createEdgeMixedIndex(String indexName, String backingIndex, List<AtlasPropertyKey> propertyKeys) {
    IndexBuilder indexBuilder = management.buildIndex(indexName, Edge.class);

    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey janusKey = AtlasJanusObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(janusKey);
    }

    indexBuilder.buildMixedIndex(backingIndex);
}
 
Example #16
Source File: AtlasJanusGraphManagement.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createVertexMixedIndex(String indexName, String backingIndex, List<AtlasPropertyKey> propertyKeys) {
    IndexBuilder indexBuilder = management.buildIndex(indexName, Vertex.class);

    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey janusKey = AtlasJanusObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(janusKey);
    }

    indexBuilder.buildMixedIndex(backingIndex);
}
 
Example #17
Source File: AtlasJanusObjectFactory.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static PropertyKey[] createPropertyKeys(List<AtlasPropertyKey> keys) {
    PropertyKey[] ret = new PropertyKey[keys.size()];

    int i = 0;
    for (AtlasPropertyKey key : keys) {
        ret[i] = createPropertyKey(key);

        i++;
    }

    return ret;
}
 
Example #18
Source File: AtlasJanusGraphIndex.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Set<AtlasPropertyKey> getFieldKeys() {
    PropertyKey[] keys = wrapped.getFieldKeys();
    Set<AtlasPropertyKey> result = new HashSet<AtlasPropertyKey>();
    for(PropertyKey key  : keys) {
        result.add(GraphDbObjectFactory.createPropertyKey(key));
    }
    return result;
}
 
Example #19
Source File: AtlasJanusObjectFactory.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static PropertyKey createPropertyKey(AtlasPropertyKey key) {
    return ((AtlasJanusPropertyKey)key).getWrappedPropertyKey();
}
 
Example #20
Source File: AtlasJanusPropertyKey.java    From atlas with Apache License 2.0 4 votes vote down vote up
/**
 * @return
 */
public PropertyKey getWrappedPropertyKey() {
    return wrapped;
}
 
Example #21
Source File: AtlasJanusPropertyKey.java    From atlas with Apache License 2.0 4 votes vote down vote up
public AtlasJanusPropertyKey(PropertyKey toWrap) {
    wrapped = toWrap;
}
 
Example #22
Source File: GraphOMRSGraphFactory.java    From egeria with Apache License 2.0 4 votes vote down vote up
private boolean createControlIndex() {

        final String methodName = "createControlIndex";


        // Prior to creating the control vertex - create an index to allow us to find it without a full scan
        JanusGraphManagement management = graph.openManagement();
        String indexName = "controlIndex";

        try {

            // Check if index exists
            JanusGraphIndex controlIndex = management.getGraphIndex(indexName);
            if (controlIndex == null) {
                log.info("{} index create {} for control vertex", methodName, indexName);
                // Property key should not already exist - but check it anyway.
                PropertyKey propertyKey = management.getPropertyKey(controlVertexIdPropertyName);

                if (propertyKey != null) {
                    // Somehow - despite this being a new graph - the property key already exists. Stop.
                    log.error("{} property key {} already exists", methodName, controlVertexIdPropertyName);
                    management.rollback();
                    return false;
                } else {
                    log.info("{} make property key {}", methodName, controlVertexIdPropertyName);
                    propertyKey = management.makePropertyKey(controlVertexIdPropertyName).dataType(String.class).make();
                }

                if (propertyKey == null) {
                    // Could not create property key. Stop.
                    log.error("{} property key {} could not be created", methodName, controlVertexIdPropertyName);
                    management.rollback();
                    return false;
                } else {
                    log.info("{} create index {}", methodName, indexName);
                    JanusGraphManagement.IndexBuilder indexBuilder = management.buildIndex(indexName, Vertex.class).addKey(propertyKey).unique();
                    JanusGraphIndex index = indexBuilder.buildCompositeIndex();
                    management.setConsistency(index, ConsistencyModifier.LOCK);
                    management.commit();
                    // Enable the index - set a relatively short timeout (10 s vs the default of 1 minute)
                    log.info("{} await ENABLED for {}", methodName, indexName);
                    ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.ENABLED).timeout(10, ChronoUnit.SECONDS).call();
                    return true;
                }
            } else {
                // That really should not be possible - a new graph should not have the index. Stop.
                log.error("{} control index already exists", methodName);
                management.rollback();
                return false;
            }
        } catch (Exception e) {
            log.error("{} caught interrupted exception from awaitGraphIndexStatus ENABLED {}", methodName, e);
            management.rollback();
            return false;
        }

    }