Search in sources :

Example 1 with VPDMultitenantPolicy

use of org.eclipse.persistence.descriptors.VPDMultitenantPolicy in project eclipselink by eclipse-ee4j.

the class MultitenantMetadata method process.

/**
 * INTERNAL:
 */
public void process(MetadataDescriptor descriptor) {
    ClassDescriptor classDescriptor = descriptor.getClassDescriptor();
    MultitenantPolicy policy;
    if (m_type == null || m_type.equals(MultitenantType.SINGLE_TABLE.name()) || m_type.equals(MultitenantType.VPD.name())) {
        if (m_type == null || m_type.equals(MultitenantType.SINGLE_TABLE.name())) {
            policy = new SingleTableMultitenantPolicy(classDescriptor);
            // As soon as we find one entity that is multitenant, turn off
            // native SQL queries Users can set the property on their
            // persistence unit if they want it back on. Or per query.
            getProject().setAllowNativeSQLQueries(false);
        } else {
            policy = new VPDMultitenantPolicy(classDescriptor);
            // Within VPD, we must ensure we are using an Always exclusive mode.
            ((ServerSession) getProject().getSession()).getDefaultConnectionPolicy().setExclusiveMode(ConnectionPolicy.ExclusiveMode.Always);
        }
        // Set the include criteria flag on the query manager (in VPD this will be false).
        ((SingleTableMultitenantPolicy) policy).setIncludeTenantCriteria(includeCriteria());
        // Single table multi-tenancy (perhaps using VPD).
        processTenantDiscriminators(descriptor, (SingleTableMultitenantPolicy) policy);
    } else {
        // Initialize the policy.
        policy = new TablePerMultitenantPolicy(classDescriptor);
        // Process the tenant table discriminator.
        processTenantTableDiscriminator(descriptor, (TablePerMultitenantPolicy) policy);
    }
    // Set the policy on the descriptor.
    classDescriptor.setMultitenantPolicy(policy);
    // we are sharing an EMF.
    if (getProject().usesMultitenantSharedEmf()) {
        if (getProject().usesMultitenantSharedCache()) {
            // Caching details are processed before multitenant metadata.
            if (classDescriptor.isSharedIsolation()) {
                classDescriptor.setCacheIsolation(CacheIsolationType.PROTECTED);
            }
        } else {
            classDescriptor.setCacheIsolation(CacheIsolationType.ISOLATED);
        }
    }
}
Also used : VPDMultitenantPolicy(org.eclipse.persistence.descriptors.VPDMultitenantPolicy) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) MultitenantPolicy(org.eclipse.persistence.descriptors.MultitenantPolicy) TablePerMultitenantPolicy(org.eclipse.persistence.descriptors.TablePerMultitenantPolicy) VPDMultitenantPolicy(org.eclipse.persistence.descriptors.VPDMultitenantPolicy) SingleTableMultitenantPolicy(org.eclipse.persistence.descriptors.SingleTableMultitenantPolicy) SingleTableMultitenantPolicy(org.eclipse.persistence.descriptors.SingleTableMultitenantPolicy) TablePerMultitenantPolicy(org.eclipse.persistence.descriptors.TablePerMultitenantPolicy)

Aggregations

ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 MultitenantPolicy (org.eclipse.persistence.descriptors.MultitenantPolicy)1 SingleTableMultitenantPolicy (org.eclipse.persistence.descriptors.SingleTableMultitenantPolicy)1 TablePerMultitenantPolicy (org.eclipse.persistence.descriptors.TablePerMultitenantPolicy)1 VPDMultitenantPolicy (org.eclipse.persistence.descriptors.VPDMultitenantPolicy)1