use of org.eclipse.persistence.internal.sessions.AbstractSession in project che-server by eclipse-che.
the class DBInitializer method setUpInjectionManager.
@Inject
public void setUpInjectionManager(GuiceEntityListenerInjectionManager injManager, EntityManagerFactory emFactory) {
final AbstractSession session = emFactory.unwrap(AbstractSession.class);
session.setInjectionManager(injManager);
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project blaze-persistence by Blazebit.
the class EclipseLinkEntityManagerIntegrator method getRegisteredFunctions.
@Override
public Map<String, JpqlFunction> getRegisteredFunctions(EntityManagerFactory entityManagerFactory) {
AbstractSession session = entityManagerFactory.unwrap(JpaEntityManagerFactory.class).getDatabaseSession();
DatabasePlatform platform = session.getPlatform();
@SuppressWarnings("unchecked") Map<Integer, ExpressionOperator> platformOperators = platform.getPlatformOperators();
Map<String, JpqlFunction> functions = new HashMap<>(platformOperators.size());
for (ExpressionOperator op : platformOperators.values()) {
String name = (String) ExpressionOperator.getPlatformOperatorNames().get(op.getSelector());
if (name != null) {
if (op instanceof JpqlFunctionExpressionOperator) {
functions.put(name.toLowerCase(), ((JpqlFunctionExpressionOperator) op).unwrap());
} else {
int selector = op.getSelector();
// No support for these expressions
if (selector != ExpressionOperator.Union && selector != ExpressionOperator.UnionAll && selector != ExpressionOperator.Intersect && selector != ExpressionOperator.IntersectAll && selector != ExpressionOperator.Except && selector != ExpressionOperator.ExceptAll) {
functions.put(name.toLowerCase(), new ExpressionOperatorJpqlFunction(op));
}
}
}
}
// Eclipselink doesn't report all functions..
functions.put("count", new ExpressionOperatorJpqlFunction(ExpressionOperator.count()));
functions.put("sum", new ExpressionOperatorJpqlFunction(ExpressionOperator.sum()));
functions.put("avg", new ExpressionOperatorJpqlFunction(ExpressionOperator.average()));
functions.put("max", new ExpressionOperatorJpqlFunction(ExpressionOperator.maximum()));
functions.put("min", new ExpressionOperatorJpqlFunction(ExpressionOperator.minimum()));
functions.put("stddev", new ExpressionOperatorJpqlFunction(ExpressionOperator.standardDeviation()));
functions.put("var", new ExpressionOperatorJpqlFunction(ExpressionOperator.variance()));
return functions;
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class JPAQuery method processStoredProcedureQuery.
/**
* INTERNAL:
* Convert the StoredProc call into a DatabaseQuery.
*/
public DatabaseQuery processStoredProcedureQuery(Session session) {
DatabaseQuery query = null;
ClassLoader loader = session.getDatasourcePlatform().getConversionManager().getLoader();
if (resultClassNames != null) {
List<SQLResultSetMapping> resultSetMappings = new ArrayList<>();
for (String resultClass : resultClassNames) {
SQLResultSetMapping mapping = new SQLResultSetMapping(resultClass);
EntityResult entityResult = new EntityResult(resultClass);
mapping.addResult(entityResult);
resultSetMappings.add(mapping);
}
query = StoredProcedureQueryImpl.buildResultSetMappingQuery(resultSetMappings, call, hints, loader, (AbstractSession) session);
} else if (resultSetMappingNames != null) {
query = StoredProcedureQueryImpl.buildResultSetMappingNameQuery(resultSetMappingNames, call, hints, loader, (AbstractSession) session);
} else if (resultClassName != null) {
Class<?> clazz = session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(resultClassName);
query = StoredProcedureQueryImpl.buildStoredProcedureQuery(clazz, call, hints, loader, (AbstractSession) session);
} else {
// Neither a resultClass or resultSetMapping is specified so place in a temp query on the session.
if (call.isStoredFunctionCall() || call.isStoredPLSQLProcedureCall()) {
// If it is a function (plsql or not) or plsql procedure use the data read query.
query = StoredProcedureQueryImpl.buildStoredProcedureQuery(call, hints, loader, (AbstractSession) session);
} else {
// Otherwise use a result set mapping query for stored procedure calls so users can use the execute
// method on it (JPA 2.1 API). Will return the same result, that is, Object[] in this case.
query = StoredProcedureQueryImpl.buildResultSetMappingQuery(new ArrayList<>(), call, hints, loader, (AbstractSession) session);
}
}
query.setName(getName());
return query;
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class StoredProcedureQueryImpl method buildResultRecords.
/**
* Build the given result set into a list objects. Assumes there is an
* execute call available and therefore should not be called unless an
* execute statement was issued by the user.
*/
protected List buildResultRecords(ResultSet resultSet) {
try {
AbstractSession session = (AbstractSession) getActiveSession();
DatabaseAccessor accessor = (DatabaseAccessor) executeCall.getQuery().getAccessor();
executeCall.setFields(null);
executeCall.matchFieldOrder(resultSet, accessor, session);
ResultSetMetaData metaData = resultSet.getMetaData();
List<AbstractRecord> result = new Vector<>();
while (resultSet.next()) {
result.add(accessor.fetchRow(executeCall.getFields(), executeCall.getFieldsArray(), resultSet, metaData, session));
}
// The result set must be closed in case the statement is cached and not closed.
resultSet.close();
return result;
} catch (Exception e) {
setRollbackOnly();
throw new PersistenceException(e);
}
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class StoredProcedureQueryImpl method close.
/**
* Call this method to close any open connections to the database.
*/
@Override
public void close() {
if (executeCall != null) {
DatabaseQuery query = executeCall.getQuery();
AbstractSession session = query.getSession();
// Release the accessors acquired for the query.
for (Accessor accessor : query.getAccessors()) {
session.releaseReadConnection(accessor);
}
try {
if (executeStatement != null) {
DatabaseAccessor accessor = (DatabaseAccessor) query.getAccessor();
accessor.releaseStatement(executeStatement, query.getSQLString(), executeCall, session);
}
} catch (SQLException exception) {
// Catch the exception and log a message.
session.log(SessionLog.WARNING, SessionLog.CONNECTION, "exception_caught_closing_statement", exception);
}
}
executeCall = null;
executeStatement = null;
}
Aggregations