use of org.eclipse.persistence.internal.jpa.rs.metadata.model.LinkTemplate in project eclipselink by eclipse-ee4j.
the class AbstractPersistenceUnitResource method buildDescriptor.
private Descriptor buildDescriptor(PersistenceContext context, String persistenceUnit, ClassDescriptor descriptor, String baseUri) {
Descriptor returnDescriptor = new Descriptor();
String name = descriptor.getAlias();
returnDescriptor.setName(name);
String version = context.getVersion();
if (version != null) {
version = version + "/";
returnDescriptor.getLinkTemplates().add(new LinkTemplate("find", "get", baseUri + version + persistenceUnit + "/entity/" + descriptor.getAlias() + "/{primaryKey}"));
returnDescriptor.getLinkTemplates().add(new LinkTemplate("persist", "put", baseUri + version + persistenceUnit + "/entity/" + descriptor.getAlias()));
returnDescriptor.getLinkTemplates().add(new LinkTemplate("update", "post", baseUri + version + persistenceUnit + "/entity/" + descriptor.getAlias()));
returnDescriptor.getLinkTemplates().add(new LinkTemplate("delete", "delete", baseUri + version + persistenceUnit + "/entity/" + descriptor.getAlias() + "/{primaryKey}"));
} else {
returnDescriptor.getLinkTemplates().add(new LinkTemplate("find", "get", baseUri + persistenceUnit + "/entity/" + descriptor.getAlias() + "/{primaryKey}"));
returnDescriptor.getLinkTemplates().add(new LinkTemplate("persist", "put", baseUri + persistenceUnit + "/entity/" + descriptor.getAlias()));
returnDescriptor.getLinkTemplates().add(new LinkTemplate("update", "post", baseUri + persistenceUnit + "/entity/" + descriptor.getAlias()));
returnDescriptor.getLinkTemplates().add(new LinkTemplate("delete", "delete", baseUri + persistenceUnit + "/entity/" + descriptor.getAlias() + "/{primaryKey}"));
}
if (!descriptor.getMappings().isEmpty()) {
Iterator<DatabaseMapping> mappingIterator = descriptor.getMappings().iterator();
while (mappingIterator.hasNext()) {
DatabaseMapping mapping = mappingIterator.next();
addMapping(returnDescriptor, mapping);
}
}
addQueries(returnDescriptor.getQueries(), context, descriptor.getJavaClassName());
return returnDescriptor;
}
use of org.eclipse.persistence.internal.jpa.rs.metadata.model.LinkTemplate 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;
}
Aggregations