use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class PersistenceContext method constructQuery.
protected Query constructQuery(EntityManager em, String name, Map<?, ?> parameters, Map<String, ?> hints) {
Query query = em.createNamedQuery(name);
DatabaseQuery dbQuery = ((EJBQueryImpl<?>) query).getDatabaseQuery();
if (parameters != null) {
Iterator<?> i = parameters.entrySet().iterator();
while (i.hasNext()) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) i.next();
String key = (String) entry.getKey();
Class<?> parameterClass = null;
int index = dbQuery.getArguments().indexOf(key);
if (index >= 0) {
parameterClass = dbQuery.getArgumentTypes().get(index);
}
Object parameter = entry.getValue();
if (parameterClass != null) {
parameter = ConversionManager.getDefaultManager().convertObject(parameter, parameterClass);
}
query.setParameter(key, parameter);
}
}
if (hints != null) {
for (Map.Entry<String, ?> entry : hints.entrySet()) {
query.setHint(entry.getKey(), entry.getValue());
}
}
return query;
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class EntityManagerImpl method createDescriptorNamedQuery.
@Override
public jakarta.persistence.Query createDescriptorNamedQuery(String queryName, Class<?> descriptorClass, List argumentTypes) {
try {
verifyOpen();
ClassDescriptor descriptor = this.databaseSession.getDescriptor(descriptorClass);
if (descriptor != null) {
DatabaseQuery query = descriptor.getQueryManager().getLocalQueryByArgumentTypes(queryName, argumentTypes);
if (query != null) {
return new EJBQueryImpl(query, this);
}
}
return null;
} catch (RuntimeException e) {
setRollbackOnly();
throw e;
}
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class EntityManagerImpl method createQuery.
/**
* This method is used to create a query using a EclipseLink Expression and
* the return type.
*/
@Override
public jakarta.persistence.Query createQuery(Expression expression, Class<?> resultType) {
try {
verifyOpen();
DatabaseQuery query = createQueryInternal(expression, resultType);
return new EJBQueryImpl(query, this);
} catch (RuntimeException e) {
setRollbackOnly();
throw e;
}
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class EntityManagerFactoryImpl method addNamedQuery.
@Override
public void addNamedQuery(String name, Query query) {
QueryImpl queryImpl = query.unwrap(QueryImpl.class);
DatabaseQuery unwrapped = (DatabaseQuery) queryImpl.getDatabaseQueryInternal().clone();
if (queryImpl.lockMode != null) {
((ObjectLevelReadQuery) unwrapped).setLockModeType(queryImpl.lockMode.name(), getServerSession());
}
if (unwrapped.isReadQuery()) {
((ReadQuery) unwrapped).setInternalMax((queryImpl.getMaxResultsInternal()));
((ReadQuery) unwrapped).setFirstResult((queryImpl.getFirstResult()));
}
this.getServerSession().addQuery(name, unwrapped, true);
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class AbstractPersistenceUnitResource method getQueryMetadataInternal.
protected Response getQueryMetadataInternal(String version, String persistenceUnit, String queryName, HttpHeaders headers, UriInfo uriInfo) {
JPARSLogger.entering(CLASS_NAME, "getQueryMetadataInternal", new Object[] { "GET", version, persistenceUnit, queryName, uriInfo.getRequestUri().toASCIIString() });
try {
PersistenceContext context = getPersistenceContext(persistenceUnit, null, uriInfo.getBaseUri(), version, null);
List<Query> returnQueries = new ArrayList<>();
Map<String, List<DatabaseQuery>> queries = context.getServerSession().getQueries();
if (queries.get(queryName) != null) {
for (DatabaseQuery query : queries.get(queryName)) {
returnQueries.add(getQuery(query, context));
}
}
String mediaType = StreamingOutputMarshaller.mediaType(headers.getAcceptableMediaTypes()).toString();
QueryList queryList = new QueryList();
queryList.setList(returnQueries);
String result = null;
if (mediaType.equals(MediaType.APPLICATION_JSON)) {
result = marshallMetadata(queryList.getList(), mediaType);
} else {
result = marshallMetadata(queryList, mediaType);
}
return Response.ok(new StreamingOutputMarshaller(null, result, headers.getAcceptableMediaTypes())).build();
} catch (Exception ex) {
throw JPARSException.exceptionOccurred(ex);
}
}
Aggregations