use of org.eclipse.persistence.internal.expressions.MapEntryExpression in project eclipselink by eclipse-ee4j.
the class MapEntryNode method generateExpression.
/**
* INTERNAL
* Generate the a new EclipseLink TableEntryExpression for this node.
*/
@Override
public Expression generateExpression(GenerationContext context) {
Expression owningExpression = getLeft().generateExpression(context);
MapEntryExpression whereClause = new MapEntryExpression(owningExpression);
whereClause.returnMapEntry();
return whereClause;
}
use of org.eclipse.persistence.internal.expressions.MapEntryExpression 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.MapEntryExpression 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