本文整理了Java中org.zstack.zql.ast.ZQLMetadata
类的一些代码示例,展示了ZQLMetadata
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZQLMetadata
类的具体详情如下:
包路径:org.zstack.zql.ast.ZQLMetadata
类名称:ZQLMetadata
暂无
代码示例来源:origin: zstackio/zstack
String toSQL() {
ZQLMetadata.InventoryMetadata metadata = ZQLMetadata.getInventoryMetadataByName(inventoryClass.getName());
if (metadata == null) {
throw new CloudRuntimeException(String.format("cannot find InventoryMetadata for class[%s]", inventoryClass));
}
Field primaryKey = EntityMetadata.getPrimaryKeyField(metadata.inventoryAnnotation.mappingVOClass());
Class mappingInventoryClass = annotation.mappingClass();
ZQLMetadata.InventoryMetadata mappingInventoryMetadata = ZQLMetadata.getInventoryMetadataByName(mappingInventoryClass.getName());
String mappingEntityName = mappingInventoryClass.getSimpleName();
return String.format("%s.%s IN (SELECT %s.%s FROM %s %s WHERE %s.%s %%s %%s)",
inventoryClass.getSimpleName(), primaryKey.getName(), mappingEntityName,
annotation.joinColumn().name(), mappingInventoryMetadata.inventoryAnnotation.mappingVOClass().getSimpleName(),
mappingEntityName, mappingEntityName, annotation.joinColumn().referencedColumnName());
}
}
代码示例来源:origin: zstackio/zstack
fillInventoryMetadata(clz,
!expandedQueries.isEmpty() ? expandedQueries : null,
!expandedQueryAliases.isEmpty() ? expandedQueryAliases : null,
fillInventoryMetadata(clz, asList(it), null, null, null);
});
fillInventoryMetadata(clz, null, asList(it), null, null);
});
代码示例来源:origin: zstackio/zstack
@Override
public List<String> targetFields() {
ZQLMetadata.InventoryMetadata inventory = ZQLMetadata.findInventoryMetadata(node.getTarget().getEntity());
List<String> fieldNames = node.getGroupBy() == null ? new ArrayList<>() : node.getGroupBy().getFields();
fieldNames.forEach(inventory::errorIfNoField);
return fieldNames;
}
}
代码示例来源:origin: zstackio/zstack
private Class getQueryTargetInventoryClass(APIQueryMessage msg, Class inventoryClass) {
Field tf = ZQLMetadata.getTypeFieldOfInventoryClass(inventoryClass);
if (tf == null) {
return inventoryClass;
}
Optional<QueryCondition> opt = msg.getConditions().stream().filter(c->c.getName().equals(tf.getName())).findFirst();
if (!opt.isPresent()) {
return inventoryClass;
}
QueryCondition condition = opt.get();
if (!condition.getOp().equals(QueryOp.EQ.toString())) {
return inventoryClass;
}
return ZQLMetadata.getChildInventoryClassByType(inventoryClass, condition.getValue());
}
代码示例来源:origin: zstackio/zstack
ZQLMetadata.InventoryMetadata src = ZQLMetadata.getInventoryMetadataByName(srcTargetName);
ZQLMetadata.InventoryMetadata dst = ZQLMetadata.findInventoryMetadata(node.getEntity());
代码示例来源:origin: zstackio/zstack
this.value = value;
List<ZQLMetadata.ChainQueryStruct> chainQueries = ZQLMetadata.createChainQuery(queryTargetInventoryName, conditionNames);
if (chainQueries.size() == 1) {
ZQLMetadata.FieldChainQuery fc = (ZQLMetadata.FieldChainQuery) chainQueries.get(0);
代码示例来源:origin: zstackio/zstack
@Override
public void verify() {
if (right != null) {
InventoryMetadata him = getInventoryMetadataByName(right.targetInventoryClass.getName());
if (!him.hasInventoryField(fieldName)) {
throw new CloudRuntimeException(String.format("inventory class[%s] not having field[%s]", him.selfInventoryClass, fieldName));
}
} else {
if (!self.hasInventoryField(fieldName)) {
throw new CloudRuntimeException(String.format("inventory class[%s] not having field[%s]", self.selfInventoryClass, fieldName));
}
}
}
代码示例来源:origin: zstackio/zstack
public AbstractQueryVisitorPlugin(ASTNode.Query node) {
super(node);
inventory = ZQLMetadata.findInventoryMetadata(node.getTarget().getEntity());
entityAlias = inventory.simpleInventoryName();
entityVOName = inventory.inventoryAnnotation.mappingVOClass().getSimpleName();
}
代码示例来源:origin: zstackio/zstack
private String createTagPatternSQL(Class invClz, String fieldName, boolean nestedQuery) {
ZQLMetadata.InventoryMetadata src = ZQLMetadata.getInventoryMetadataByName(invClz.getName());
String primaryKey = EntityMetadata.getPrimaryKeyField(src.inventoryAnnotation.mappingVOClass()).getName();
boolean reserve = TAG_FALSE_OP.containsKey(operator);
String op = reserve ? TAG_FALSE_OP.get(operator) : operator;
String subCondition = String.format("pattern.uuid %s ", op + (value == null ? "" : value));
String filterResourceUuidSQL = String.format("SELECT utag.resourceUuid FROM UserTagVO utag, TagPatternVO pattern" +
" WHERE %s and utag.tagPatternUuid = pattern.uuid", subCondition);
String weather_not_in = reserve ? "NOT" : "";
if (nestedQuery) {
return String.format("(SELECT %s.%s FROM %s %s WHERE %s.%s %s IN (%s))",
src.simpleInventoryName(), primaryKey, src.inventoryAnnotation.mappingVOClass().getSimpleName(), src.simpleInventoryName(),
src.simpleInventoryName(), primaryKey, weather_not_in, filterResourceUuidSQL);
} else {
return String.format("(%s.%s %s IN (%s))",
src.simpleInventoryName(), primaryKey, weather_not_in, filterResourceUuidSQL);
}
}
代码示例来源:origin: zstackio/zstack
@Override
public List<String> targetFields() {
ZQLMetadata.InventoryMetadata inventory = ZQLMetadata.findInventoryMetadata(node.getTarget().getEntity());
List<String> fieldNames = node.getTarget().getFields() == null ? new ArrayList<>() : node.getTarget().getFields();
fieldNames.forEach(inventory::errorIfNoField);
return fieldNames;
}
代码示例来源:origin: zstackio/zstack
em.self = self;
em.right = e;
self = getInventoryMetadataByName(em.right.targetInventoryClass.getName());
left = em.right;
ret.add(em);
代码示例来源:origin: zstackio/zstack
ZQLMetadata.InventoryMetadata inventory = ZQLMetadata.findInventoryMetadata(node.getTarget().getEntity());
ret.inventoryMetadata = inventory;
ZQLContext.pushQueryTargetInventoryName(inventory.fullInventoryName());
代码示例来源:origin: zstackio/zstack
ZQLMetadata.InventoryMetadata src = ZQLMetadata.getInventoryMetadataByName(context.getQueryTargetInventoryName());
代码示例来源:origin: zstackio/zstack
@Override
public String visit(ASTNode.SubQuery node) {
ZQLMetadata.InventoryMetadata inventory = ZQLMetadata.findInventoryMetadata(node.getTarget().getEntity());
ZQLContext.pushQueryTargetInventoryName(inventory.fullInventoryName());
String fieldName = node.getTarget().getFields() == null || node.getTarget().getFields().isEmpty() ? "" : node.getTarget().getFields().get(0);
if (fieldName != "") {
inventory.errorIfNoField(fieldName);
}
String entityAlias = inventory.simpleInventoryName();
String queryTarget = fieldName.equals("") ? entityAlias : String.format("%s.%s", inventory.simpleInventoryName(), fieldName);
String entityVOName = inventory.inventoryAnnotation.mappingVOClass().getSimpleName();
List<String> clauses = new ArrayList<>();
clauses.add(String.format("SELECT %s FROM %s %s", queryTarget, entityVOName, entityAlias));
String condition = makeConditions(node);
if (!condition.equals("")) {
clauses.add("WHERE");
clauses.add(condition);
}
ZQLContext.popQueryTargetInventoryName();
return String.format("(%s)", StringUtils.join(clauses, " "));
}
}
代码示例来源:origin: zstackio/zstack
@Override
public String visit(ASTNode.OrderBy node) {
if (!node.getDirection().equalsIgnoreCase("asc") && !node.getDirection().equalsIgnoreCase("desc")) {
throw new ZQLError(Platform.i18n("invalid order by clause, expect direction[asc,desc] but got %s", node.getDirection()));
}
String inventoryName = ZQLContext.peekQueryTargetInventoryName();
ZQLMetadata.InventoryMetadata m = ZQLMetadata.getInventoryMetadataByName(inventoryName);
if (!m.hasInventoryField(node.getField())) {
throw new ZQLError(Platform.i18n("invalid order by clause, inventory[%s] doesn't have field[%s]", m.simpleInventoryName(), node.getField()));
}
return String.format("ORDER BY %s %s", node.getField(), node.getDirection().toUpperCase());
}
}
代码示例来源:origin: zstackio/zstack
@Override
public String groupBy() {
if (node.getGroupBy() == null) {
return null;
}
List<String> fs = node.getGroupBy().getFields();
ZQLMetadata.InventoryMetadata inventory = ZQLMetadata.findInventoryMetadata(node.getTarget().getEntity());
fs.forEach(inventory::errorIfNoField);
return node.getGroupBy() == null ? null : (String) node.getGroupBy().accept(new GroupByVisitor());
}
}
代码示例来源:origin: zstackio/zstack
ZQLMetadata.InventoryMetadata src = ZQLMetadata.getInventoryMetadataByName(context.getQueryTargetInventoryName());
String accountUuid = context.getAPISession().getAccountUuid();
if (AccountConstant.INITIAL_SYSTEM_ADMIN_UUID.equals(accountUuid)) {
内容来源于网络,如有侵权,请联系作者删除!