Java Code Examples for com.baidu.hugegraph.util.E#checkNotNull()

The following examples show how to use com.baidu.hugegraph.util.E#checkNotNull() . 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: SchemaTransaction.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public void checkSchemaName(String name) {
    String illegalReg = this.params().configuration()
                            .get(CoreOptions.SCHEMA_ILLEGAL_NAME_REGEX);

    E.checkNotNull(name, "name");
    E.checkArgument(!name.isEmpty(), "The name can't be empty.");
    E.checkArgument(name.length() < 256,
                    "The length of name must less than 256 bytes.");
    E.checkArgument(!name.matches(illegalReg),
                    "Illegal schema name '%s'", name);

    final char[] filters = {'#', '>', ':', '!'};
    for (char c : filters) {
        E.checkArgument(name.indexOf(c) == -1,
                        "The name can't contain character '%s'.", c);
    }
}
 
Example 2
Source File: HugeConfig.java    From hugegraph-common with Apache License 2.0 6 votes vote down vote up
private static PropertiesConfiguration loadConfigFile(String path) {
    E.checkNotNull(path, "config path");
    E.checkArgument(!path.isEmpty(),
                    "The config path can't be empty");

    File file = new File(path);
    E.checkArgument(file.exists() && file.isFile() && file.canRead(),
                    "Need to specify a readable config, but got: %s",
                    file.toString());

    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setDelimiterParsingDisabled(true);
    try {
        config.load(file);
    } catch (ConfigurationException e) {
        throw new ConfigException("Unable to load config: %s", e, path);
    }
    return config;
}
 
Example 3
Source File: TableSerializer.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
public HugeIndex readIndex(HugeGraph graph, ConditionQuery query,
                           BackendEntry backendEntry) {
    E.checkNotNull(graph, "serializer graph");
    if (backendEntry == null) {
        return null;
    }

    TableBackendEntry entry = this.convertEntry(backendEntry);

    Object indexValues = entry.column(HugeKeys.FIELD_VALUES);
    Number indexLabelId = entry.column(HugeKeys.INDEX_LABEL_ID);
    Set<Object> elemIds = this.parseIndexElemIds(entry);
    Number expiredTime = entry.column(HugeKeys.EXPIRED_TIME);

    IndexLabel indexLabel = graph.indexLabel(this.toId(indexLabelId));
    HugeIndex index = new HugeIndex(graph, indexLabel);
    index.fieldValues(indexValues);
    long expired = index.hasTtl() ? expiredTime.longValue() : 0L;
    for (Object elemId : elemIds) {
        index.elementIds(this.readId(elemId), expired);
    }
    return index;
}
 
Example 4
Source File: SingleSourceShortestPathTraverser.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public NodeWithWeight weightedShortestPath(Id sourceV, Id targetV,
                                           Directions dir, String label,
                                           String weight, long degree,
                                           long skipDegree, long capacity) {
    E.checkNotNull(sourceV, "source vertex id");
    E.checkNotNull(dir, "direction");
    E.checkNotNull(weight, "weight property");
    checkDegree(degree);
    checkCapacity(capacity);
    checkSkipDegree(skipDegree, degree, capacity);

    Id labelId = this.getEdgeLabelId(label);
    Traverser traverser = new Traverser(sourceV, dir, labelId, weight,
                                        degree, skipDegree, capacity,
                                        NO_LIMIT);
    while (true) {
        traverser.forward();
        Map<Id, NodeWithWeight> results = traverser.shortestPaths();
        if (results.containsKey(targetV) || traverser.done()) {
            return results.get(targetV);
        }
        checkCapacity(traverser.capacity, traverser.size, "shortest path");
    }
}
 
Example 5
Source File: SingleSourceShortestPathAPI.java    From hugegraph-client with Apache License 2.0 6 votes vote down vote up
public WeightedPaths get(Object sourceId, Direction direction, String label,
                         String weight, long degree, long skipDegree,
                         long capacity, long limit, boolean withVertex) {
    this.client.checkApiVersion("0.51", "single source shortest path");
    String source = GraphAPI.formatVertexId(sourceId, false);

    E.checkNotNull(weight, "weight");
    checkDegree(degree);
    checkCapacity(capacity);
    checkSkipDegree(skipDegree, degree, capacity);
    checkLimit(limit);

    Map<String, Object> params = new LinkedHashMap<>();
    params.put("source", source);
    params.put("direction", direction);
    params.put("label", label);
    params.put("weight", weight);
    params.put("max_degree", degree);
    params.put("skip_degree", skipDegree);
    params.put("capacity", capacity);
    params.put("limit", limit);
    params.put("with_vertex", withVertex);
    RestResult result = this.client.get(this.path(), params);
    return result.readObject(WeightedPaths.class);
}
 
Example 6
Source File: OffheapCache.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static ValueType valueOf(Object object) {
    E.checkNotNull(object, "object");
    Class<? extends Object> clazz = object.getClass();
    if (Collection.class.isAssignableFrom(clazz)) {
        return ValueType.LIST;
    } else if (clazz == HugeVertex.class) {
        return ValueType.VERTEX;
    } else if (clazz == HugeEdge.class) {
        return ValueType.EDGE;
    } else {
        for (ValueType type : values()) {
            if (clazz == type.dataType().clazz()) {
                return type;
            }
        }
    }
    return ValueType.UNKNOWN;
}
 
Example 7
Source File: Vertex.java    From hugegraph-client with Apache License 2.0 6 votes vote down vote up
@Override
public Vertex removeProperty(String key) {
    E.checkNotNull(key, "The property name can not be null");
    if (!this.properties.containsKey(key)) {
        throw new InvalidOperationException(
                  "The vertex '%s' doesn't have the property '%s'",
                  this.id, key);
    }
    Vertex vertex = new Vertex(this.label);
    vertex.id(this.id);
    Object value = this.properties.get(key);
    vertex.property(key, value);
    this.manager.eliminateVertexProperty(vertex);

    this.properties().remove(key);
    return this;
}
 
Example 8
Source File: HugeAuthenticator.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private boolean matchResource(HugePermission required,
                              ResourceObject<?> resourceObject) {
    E.checkNotNull(resourceObject, "resource object");

    /*
     * Is resource allowed to access by anyone?
     * TODO: only allowed resource of related type(USER/TASK/VAR),
     *       such as role VAR is allowed to access '~variables' label
     */
    if (HugeResource.allowed(resourceObject)) {
        return true;
    }

    String owner = resourceObject.graph();
    Map<HugePermission, Object> permissions = this.roles.get(owner);
    if (permissions == null) {
        return false;
    }
    Object permission = matchedAction(required, permissions);
    if (permission == null) {
        // Deny all if no specified permission
        return false;
    }
    List<HugeResource> ress;
    if (permission instanceof List) {
        @SuppressWarnings("unchecked")
        List<HugeResource> list = (List<HugeResource>) permission;
        ress = list;
    } else {
        ress = HugeResource.parseResources(permission.toString());
    }
    for (HugeResource res : ress) {
        if (res.filter(resourceObject)) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: ShortestPathTraverser.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public Path shortestPath(Id sourceV, Id targetV, Directions dir,
                         String label, int depth, long degree,
                         long skipDegree, long capacity) {
    E.checkNotNull(sourceV, "source vertex id");
    E.checkNotNull(targetV, "target vertex id");
    E.checkNotNull(dir, "direction");
    checkPositive(depth, "max depth");
    checkDegree(degree);
    checkCapacity(capacity);
    checkSkipDegree(skipDegree, degree, capacity);

    if (sourceV.equals(targetV)) {
        return new Path(ImmutableList.of(sourceV));
    }

    Id labelId = this.getEdgeLabelId(label);
    Traverser traverser = new Traverser(sourceV, targetV, dir, labelId,
                                        degree, skipDegree, capacity);
    PathSet paths;
    while (true) {
        // Found, reach max depth or reach capacity, stop searching
        if (!(paths = traverser.forward(false)).isEmpty() ||
            --depth <= 0) {
            break;
        }
        checkCapacity(traverser.capacity, traverser.size, "shortest path");

        if (!(paths = traverser.backward(false)).isEmpty() ||
            --depth <= 0) {
            Path path = paths.iterator().next();
            Collections.reverse(path.vertices());
            break;
        }
        checkCapacity(traverser.capacity, traverser.size, "shortest path");
    }
    return paths.isEmpty() ? Path.EMPTY_PATH : paths.iterator().next();
}
 
Example 10
Source File: MysqlStore.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public MysqlStore(final BackendStoreProvider provider,
                  final String database, final String store) {
    E.checkNotNull(database, "database");
    E.checkNotNull(store, "store");
    this.provider = provider;
    this.database = database;
    this.store = store;

    this.sessions = null;
    this.tables = new ConcurrentHashMap<>();

    this.registerMetaHandlers();
    LOG.debug("Store loaded: {}", store);
}
 
Example 11
Source File: ResourceObject.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public ResourceObject(String graph, ResourceType type, V operated) {
    E.checkNotNull(graph, "graph");
    E.checkNotNull(type, "type");
    E.checkNotNull(operated, "operated");
    this.graph = graph;
    this.type = type;
    this.operated = operated;
}
 
Example 12
Source File: IdGenerator.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Id other) {
    E.checkNotNull(other, "compare id");
    if (other instanceof UuidId) {
        return this.uuid.compareTo(((UuidId) other).uuid);
    }
    return Bytes.compare(this.asBytes(), other.asBytes());
}
 
Example 13
Source File: RocksDBStore.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void open(HugeConfig config) {
    LOG.debug("Store open: {}", this.store);

    E.checkNotNull(config, "config");

    if (this.sessions != null && !this.sessions.closed()) {
        LOG.debug("Store {} has been opened before", this.store);
        this.sessions.useSession();
        return;
    }

    List<Future<?>> futures = new ArrayList<>();
    ExecutorService openPool = ExecutorUtil.newFixedThreadPool(
                               OPEN_POOL_THREADS, DB_OPEN);
    // Open base disk
    futures.add(openPool.submit(() -> {
        this.sessions = this.open(config, this.tableNames());
    }));

    // Open tables with optimized disk
    Map<String, String> disks = config.getMap(RocksDBOptions.DATA_DISKS);
    Set<String> openedDisks = new HashSet<>();
    if (!disks.isEmpty()) {
        String dataPath = config.get(RocksDBOptions.DATA_PATH);
        this.parseTableDiskMapping(disks, dataPath);
        for (Entry<HugeType, String> e : this.tableDiskMapping.entrySet()) {
            String table = this.table(e.getKey()).table();
            String disk = e.getValue();
            if (openedDisks.contains(disk)) {
                continue;
            }
            openedDisks.add(disk);
            futures.add(openPool.submit(() -> {
                this.open(config, disk, disk, Arrays.asList(table));
            }));
        }
    }
    waitOpenFinish(futures, openPool);
}
 
Example 14
Source File: ConfigConvOption.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public ConfigConvOption(String name, boolean required, String desc,
                        Predicate<T> pred, Function<T, R> convert,
                        T value) {
    super(name, required, desc, pred, (Class<T>) value.getClass(), value);
    E.checkNotNull(convert, "convert");
    this.converter = convert;
}
 
Example 15
Source File: EntityManager.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public EntityManager(HugeGraphParams graph, String label,
                     Function<Vertex, T> dser) {
    E.checkNotNull(graph, "graph");

    this.graph = graph;
    this.label = label;
    this.deser = dser;
}
 
Example 16
Source File: ScyllaDBStoreProvider.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public BackendStore loadGraphStore(String name) {
    LOG.debug("ScyllaDBStoreProvider load GraphStore '{}'", name);

    if (!this.stores.containsKey(name)) {
        BackendStore s = new ScyllaDBGraphStore(this, keyspace(), name);
        this.stores.putIfAbsent(name, s);
    }

    BackendStore store = this.stores.get(name);
    E.checkNotNull(store, "store");
    E.checkState(store instanceof ScyllaDBGraphStore,
                 "GraphStore must be an instance of ScyllaDBGraphStore");
    return store;
}
 
Example 17
Source File: Condition.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
public boolean test(HugeElement element) {
    E.checkNotNull(element, "element");
    Object value = element.sysprop(this.key);
    return this.relation.test(value, this.value());
}
 
Example 18
Source File: PageInfo.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public PageInfo(int offset, String page) {
    E.checkArgument(offset >= 0, "The offset must be >= 0");
    E.checkNotNull(page, "page");
    this.offset = offset;
    this.page = page;
}
 
Example 19
Source File: QueryResults.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
private void addQuery(Query query) {
    E.checkNotNull(query, "query");
    this.queries.add(query);
}
 
Example 20
Source File: AbstractTransaction.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
protected void doAction(Action action, BackendEntry entry) {
    LOG.debug("Transaction {} entry {}", action, entry);
    E.checkNotNull(entry, "entry");
    this.mutation.add(entry, action);
}