use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.
the class SchemaService method collectIndexLabels.
public static List<IndexLabel> collectIndexLabels(SchemaLabelEntity entity, HugeClient client) {
List<PropertyIndex> propertyIndexes = entity.getPropertyIndexes();
if (CollectionUtils.isEmpty(propertyIndexes)) {
return Collections.emptyList();
}
boolean isVertex = entity.getSchemaType().isVertexLabel();
String baseValue = entity.getName();
SchemaManager schema = client.schema();
List<IndexLabel> indexLabels = new ArrayList<>(propertyIndexes.size());
for (PropertyIndex index : propertyIndexes) {
String[] fields = toStringArray(index.getFields());
IndexLabel indexLabel = schema.indexLabel(index.getName()).on(isVertex, baseValue).indexType(index.getType()).by(fields).build();
indexLabels.add(indexLabel);
}
return indexLabels;
}
use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.
the class PropertyIndexService method list.
public List<PropertyIndex> list(Collection<String> names, int connId, boolean emptyAsAll) {
HugeClient client = this.client(connId);
List<IndexLabel> indexLabels;
if (CollectionUtils.isEmpty(names)) {
if (emptyAsAll) {
indexLabels = client.schema().getIndexLabels();
} else {
indexLabels = new ArrayList<>();
}
} else {
indexLabels = client.schema().getIndexLabels(new ArrayList<>(names));
}
List<PropertyIndex> results = new ArrayList<>(indexLabels.size());
indexLabels.forEach(indexLabel -> {
results.add(convert(indexLabel));
});
return results;
}
use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.
the class SchemaController method checkPropertyIndexes.
public static void checkPropertyIndexes(SchemaLabelEntity entity, int connId) {
List<PropertyIndex> propertyIndexes = entity.getPropertyIndexes();
if (propertyIndexes != null) {
for (PropertyIndex propertyIndex : propertyIndexes) {
Ex.check(propertyIndex.getOwner() == null, "common.param.must-be-null", "property_index.owner");
Ex.check(propertyIndex.getName() != null, "common.param.cannot-be-null", "property_index.name");
Ex.check(propertyIndex.getSchemaType() != null, "common.param.cannot-be-null", "property_index.type");
Ex.check(propertyIndex.getFields() != null, "common.param.cannot-be-null", "property_index.fields");
}
}
}
use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.
the class PropertyIndexService method checkConflict.
public void checkConflict(List<PropertyIndex> entities, ConflictDetail detail, int connId, boolean compareEachOther) {
if (CollectionUtils.isEmpty(entities)) {
return;
}
Map<String, PropertyIndex> originEntities = new HashMap<>();
for (PropertyIndex entity : this.list(connId)) {
originEntities.put(entity.getName(), entity);
}
for (PropertyIndex entity : entities) {
if (detail.anyPropertyKeyConflict(entity.getFields())) {
detail.add(entity, ConflictStatus.DEP_CONFLICT);
continue;
}
PropertyIndex originEntity = originEntities.get(entity.getName());
ConflictStatus status = SchemaEntity.compare(entity, originEntity);
detail.add(entity, status);
}
// Compare resued entities with each other
if (compareEachOther) {
compareWithEachOther(detail, SchemaType.PROPERTY_INDEX);
}
}
use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.
the class PropertyIndexService method list.
public IPage<PropertyIndex> list(int connId, HugeType type, int pageNo, int pageSize) {
HugeClient client = this.client(connId);
List<IndexLabel> indexLabels = client.schema().getIndexLabels();
List<PropertyIndex> results = new ArrayList<>();
for (IndexLabel indexLabel : indexLabels) {
if (!indexLabel.baseType().equals(type)) {
continue;
}
// Collect all indexlabels
results.add(convert(indexLabel));
}
// Sort by owner name a-z, then index name a-z
results.sort((o1, o2) -> {
String owner1 = o1.getOwner();
String owner2 = o2.getOwner();
if (!owner1.equals(owner2)) {
return owner1.compareTo(owner2);
}
return o1.getName().compareTo(o2.getName());
});
return PageUtil.page(results, pageNo, pageSize);
}
Aggregations