use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.
the class UnaryMinus method generateExpression.
/**
* INTERNAL
* Generate the expression.
*/
@Override
public Expression generateExpression(GenerationContext context) {
Expression whereClause = new ConstantExpression(0, new ExpressionBuilder());
whereClause = ExpressionMath.subtract(whereClause, getLeft().generateExpression(context));
return whereClause;
}
use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.
the class SubQueryImpl method integrateRoot.
@Override
protected void integrateRoot(RootImpl root) {
if (this.roots.isEmpty()) {
TypeImpl type = ((MetamodelImpl) this.metamodel).getType(this.queryType);
if ((type != null && type.getPersistenceType() == PersistenceType.ENTITY) || queryType.equals(ClassConstants.OBJECT)) {
// this is the first root, set return type and selection and query type
if (this.selection == null) {
this.selection = root;
this.subQuery.getItems().clear();
this.subQuery.addAttribute("", new ConstantExpression(1, root.getCurrentNode().getBuilder()));
this.queryResult = ResultType.ENTITY;
}
}
this.subQuery.setReferenceClass(root.getJavaType());
this.subQuery.setExpressionBuilder(root.getCurrentNode().getBuilder());
this.queryType = root.getJavaType();
this.currentNode.setBaseExpression(((CommonAbstractCriteriaImpl) this.parent).getBaseExpression());
}
// assign the baseExpression based on the SubQuery's roots - Bug 509693
if (!this.roots.contains(root) && this.parent instanceof CriteriaQueryImpl && ((CriteriaQueryImpl) this.parent).getRoots().size() > 1) {
this.currentNode.setBaseExpression(((CriteriaQueryImpl) this.parent).getBaseExpression(root));
}
super.integrateRoot(root);
}
use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.
the class AbstractPersistenceUnitResource method getQuery.
private Query getQuery(DatabaseQuery query, PersistenceContext context) {
String method = query.isReadQuery() ? "get" : "post";
String jpql = query.getJPQLString() == null ? "" : query.getJPQLString();
StringBuilder parameterString = new StringBuilder();
Iterator<String> argumentsIterator = query.getArguments().iterator();
while (argumentsIterator.hasNext()) {
String argument = argumentsIterator.next();
parameterString.append(";");
parameterString.append(argument).append("={").append(argument).append("}");
}
String version = context.getVersion();
Query returnQuery = null;
if (version != null) {
returnQuery = new Query(query.getName(), jpql, new LinkTemplate("execute", method, context.getBaseURI() + version + "/" + context.getName() + "/query/" + query.getName() + parameterString));
} else {
returnQuery = new Query(query.getName(), jpql, new LinkTemplate("execute", method, context.getBaseURI() + context.getName() + "/query/" + query.getName() + parameterString));
}
if (query.isReportQuery()) {
query.checkPrepare((AbstractSession) context.getServerSession(), new DatabaseRecord());
for (ReportItem item : ((ReportQuery) query).getItems()) {
if (item.getMapping() != null) {
if (item.getAttributeExpression() != null && item.getAttributeExpression().isMapEntryExpression()) {
if (((MapEntryExpression) item.getAttributeExpression()).shouldReturnMapEntry()) {
returnQuery.getReturnTypes().add(Map.Entry.class.getSimpleName());
} else {
returnQuery.getReturnTypes().add(((Class<?>) item.getMapping().getContainerPolicy().getKeyType()).getSimpleName());
}
} else {
returnQuery.getReturnTypes().add(item.getMapping().getAttributeClassification().getSimpleName());
}
} else if (item.getResultType() != null) {
returnQuery.getReturnTypes().add(item.getResultType().getSimpleName());
} else if (item.getDescriptor() != null) {
returnQuery.getReturnTypes().add(item.getDescriptor().getJavaClass().getSimpleName());
} else if (item.getAttributeExpression() != null && item.getAttributeExpression().isConstantExpression()) {
returnQuery.getReturnTypes().add(((ConstantExpression) item.getAttributeExpression()).getValue().getClass().getSimpleName());
} else {
// Use Object.class by default.
returnQuery.getReturnTypes().add(ClassConstants.OBJECT.getSimpleName());
}
}
} else {
returnQuery.getReturnTypes().add(query.getReferenceClassName() == null ? "" : query.getReferenceClass().getSimpleName());
}
return returnQuery;
}
use of org.eclipse.persistence.internal.expressions.ConstantExpression in project eclipselink by eclipse-ee4j.
the class MetadataResource method buildQuerySchema.
private ResourceSchema buildQuerySchema(PersistenceContext context, DatabaseQuery query) {
final ResourceSchema schema = new ResourceSchema();
schema.setTitle(query.getName());
schema.setSchema(HrefHelper.buildQueryMetadataHref(context, query.getName()) + "#");
schema.addAllOf(new Reference(HrefHelper.buildBaseRestSchemaRef("#/collectionBaseResource")));
// Link
final String method = query.isReadQuery() ? "GET" : "POST";
schema.setLinks((new ItemLinksBuilder()).addExecute(HrefHelper.buildQueryHref(context, query.getName(), getQueryParamString(query)), method).getList());
// Definitions
if (query.isReportQuery()) {
// In case of report query we need to define a returned type
final ResourceSchema returnType = new ResourceSchema();
query.checkPrepare((AbstractSession) context.getServerSession(), new DatabaseRecord());
for (ReportItem item : ((ReportQuery) query).getItems()) {
final Property property;
if (item.getMapping() != null) {
if (item.getAttributeExpression() != null && item.getAttributeExpression().isMapEntryExpression()) {
if (((MapEntryExpression) item.getAttributeExpression()).shouldReturnMapEntry()) {
property = buildProperty(context, Map.Entry.class);
} else {
property = buildProperty(context, ((Class<?>) item.getMapping().getContainerPolicy().getKeyType()));
}
} else {
property = buildProperty(context, item.getMapping().getAttributeClassification());
}
} else if (item.getResultType() != null) {
property = buildProperty(context, item.getResultType());
} else if (item.getDescriptor() != null) {
property = buildProperty(context, item.getDescriptor().getJavaClass());
} else if (item.getAttributeExpression() != null && item.getAttributeExpression().isConstantExpression()) {
property = buildProperty(context, ((ConstantExpression) item.getAttributeExpression()).getValue().getClass());
} else {
// Use Object.class by default.
property = buildProperty(context, Object.class);
}
returnType.addProperty(item.getName(), property);
}
schema.addDefinition("result", returnType);
final Property items = new Property();
items.setType("array");
items.setItems(new Property("#/definitions/result"));
schema.addProperty("items", items);
} else {
// Read all query. Each item is an entity. Make a JSON pointer.
if (query.getReferenceClassName() != null) {
final Property items = new Property();
items.setType("array");
items.setItems(new Property(HrefHelper.buildEntityMetadataHref(context, query.getReferenceClass().getSimpleName()) + "#"));
schema.addProperty("items", items);
}
}
return schema;
}
Aggregations