Search in sources :

Example 51 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class JPQLQueryHelper method getConstructorQueryMappings.

/**
 * Retrieves the class names and the attribute names mapped to their types that are used in the
 * constructor expressions defined in the <code><b>SELECT</b></code> clause.
 * <br>
 * For instance, from the following JPQL query:
 * <br>
 * <pre><code> SELECT new test.example.Employee(e.name, e.id),
 *        new test.example.Address(a.zipcode)
 * FROM Employee e, Address a</code></pre>
 * <br>
 * The return object is
 * <pre><code> |- test.example.Employee
 * |-   |- name : String
 * |-   |- id : int
 * |- test.example.Address
 *      |- zipcode : int</code></pre>
 *
 * @param session The {@link AbstractSession} is used to retrieve the mappings used in the
 * constructor items
 * @return The holder of the result
 */
public List<ConstructorQueryMappings> getConstructorQueryMappings(AbstractSession session) {
    List<ConstructorQueryMappings> allMappings = new LinkedList<>();
    for (DatabaseQuery query : session.getJPAQueries()) {
        ConstructorQueryMappings mappings = getConstructorQueryMappings(session, query);
        allMappings.add(mappings);
    }
    return allMappings;
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) LinkedList(java.util.LinkedList)

Example 52 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class AbstractSession method processJPAQuery.

/**
 * INTERNAL:
 * Process the JPA named query into an EclipseLink Session query. This
 * method is called after descriptor initialization.
 */
protected void processJPAQuery(DatabaseQuery jpaQuery) {
    // They need to be initialized after login, as the database platform must be known.
    try {
        jpaQuery.prepareInternal(this);
    } catch (RuntimeException re) {
        // will be thrown at runtime if a user attempts to use it.
        if (!tolerateInvalidJPQL) {
            throw re;
        }
    }
    DatabaseQuery databaseQuery = (DatabaseQuery) jpaQuery.getProperty("databasequery");
    databaseQuery = (databaseQuery == null) ? jpaQuery : databaseQuery;
    // this should be true but for backward compatibility it
    addQuery(databaseQuery, false);
// is set to false.
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery)

Example 53 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class AbstractSession method copyDescriptorNamedQueries.

/**
 * INTERNAL:
 * This method will be used to copy all EclipseLink named queries defined in descriptors into the session.
 * @param allowSameQueryNameDiffArgsCopyToSession  if the value is true, it allow
 * multiple queries of the same name but different arguments to be copied to the session.
 */
public void copyDescriptorNamedQueries(boolean allowSameQueryNameDiffArgsCopyToSession) {
    for (ClassDescriptor descriptor : getProject().getOrderedDescriptors()) {
        Map<String, List<DatabaseQuery>> queries = descriptor.getQueryManager().getQueries();
        if ((queries != null) && (queries.size() > 0)) {
            for (Iterator<Map.Entry<String, List<DatabaseQuery>>> keyValueItr = queries.entrySet().iterator(); keyValueItr.hasNext(); ) {
                Map.Entry<String, List<DatabaseQuery>> entry = keyValueItr.next();
                List<DatabaseQuery> thisQueries = entry.getValue();
                if ((thisQueries != null) && (thisQueries.size() > 0)) {
                    for (Iterator<DatabaseQuery> thisQueriesItr = thisQueries.iterator(); thisQueriesItr.hasNext(); ) {
                        DatabaseQuery queryToBeAdded = thisQueriesItr.next();
                        if (allowSameQueryNameDiffArgsCopyToSession) {
                            addQuery(queryToBeAdded, false);
                        } else {
                            if (getQuery(queryToBeAdded.getName()) == null) {
                                addQuery(queryToBeAdded, false);
                            } else {
                                log(SessionLog.WARNING, SessionLog.PROPERTIES, "descriptor_named_query_cannot_be_added", new Object[] { queryToBeAdded, queryToBeAdded.getName(), queryToBeAdded.getArgumentTypes() });
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SessionLogEntry(org.eclipse.persistence.logging.SessionLogEntry) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) List(java.util.List) ArrayList(java.util.ArrayList) ExposedNodeLinkedList(org.eclipse.persistence.internal.helper.linkedlist.ExposedNodeLinkedList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class AbstractSession method updateTablePerTenantDescriptors.

/**
 * INTERNAL:
 * Set the table per tenant. This should be called per client session after
 * the start of a transaction. From JPA this method is called on the entity
 * manager by setting the multitenant table per tenant property.
 */
public void updateTablePerTenantDescriptors(String property, Object value) {
    // When all the table per tenant descriptors are set, we should initialize them.
    boolean shouldInitializeDescriptors = hasTablePerTenantDescriptors();
    for (ClassDescriptor descriptor : getTablePerTenantDescriptors()) {
        TablePerMultitenantPolicy policy = (TablePerMultitenantPolicy) descriptor.getMultitenantPolicy();
        if ((!policy.hasContextTenant()) && policy.usesContextProperty(property)) {
            policy.setContextTenant((String) value);
        }
        shouldInitializeDescriptors = shouldInitializeDescriptors && policy.hasContextTenant();
    }
    if (shouldInitializeDescriptors) {
        // descriptors, we can go through the initialization phases safely.
        try {
            // First initialize basic properties (things that do not depend on anything else)
            for (ClassDescriptor descriptor : tablePerTenantDescriptors) {
                descriptor.preInitialize(this);
            }
            // Second initialize basic mappings
            for (ClassDescriptor descriptor : tablePerTenantDescriptors) {
                descriptor.initialize(this);
            }
            // Third initialize child dependencies
            for (ClassDescriptor descriptor : tablePerTenantDescriptors) {
                descriptor.postInitialize(this);
            }
            if (getIntegrityChecker().hasErrors()) {
                handleSevere(new IntegrityException(getIntegrityChecker()));
            }
        } finally {
            clearIntegrityChecker();
        }
        getCommitManager().initializeCommitOrder();
        // once all the descriptors have been initialized.
        if (hasTablePerTenantQueries()) {
            for (DatabaseQuery query : getTablePerTenantQueries()) {
                processJPAQuery(query);
            }
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) TablePerMultitenantPolicy(org.eclipse.persistence.descriptors.TablePerMultitenantPolicy) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException)

Example 55 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class AbstractSession method preReleaseConnection.

/**
 * INTERNAL:
 * This method rises appropriate for the session event(s)
 * right before the connection is released.
 */
public void preReleaseConnection(Accessor accessor) {
    if (getProject().hasVPDIdentifier(this)) {
        if (getPlatform().supportsVPD()) {
            DatabaseQuery query = getPlatform().getVPDClearIdentifierQuery(getProject().getVPDIdentifier());
            List argValues = new ArrayList();
            query.addArgument(getProject().getVPDIdentifier());
            argValues.add(getProperty(getProject().getVPDIdentifier()));
            executeQuery(query, argValues);
        } else {
            throw ValidationException.vpdNotSupported(getPlatform().getClass().getName());
        }
    }
    if (this.eventManager != null) {
        this.eventManager.preReleaseConnection(accessor);
    }
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ExposedNodeLinkedList(org.eclipse.persistence.internal.helper.linkedlist.ExposedNodeLinkedList)

Aggregations

DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)86 ArrayList (java.util.ArrayList)18 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)15 List (java.util.List)14 Vector (java.util.Vector)12 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)12 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)12 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)8 EntityManager (jakarta.persistence.EntityManager)6 HashMap (java.util.HashMap)6 QName (javax.xml.namespace.QName)6 EJBQueryImpl (org.eclipse.persistence.internal.jpa.EJBQueryImpl)6 PersistenceContext (org.eclipse.persistence.jpa.rs.PersistenceContext)6 DataReadQuery (org.eclipse.persistence.queries.DataReadQuery)6 Session (org.eclipse.persistence.sessions.Session)6 Test (org.junit.Test)6 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)5 ReadQuery (org.eclipse.persistence.queries.ReadQuery)5 ReportQuery (org.eclipse.persistence.queries.ReportQuery)5 PersistenceException (jakarta.persistence.PersistenceException)4