use of org.eclipse.persistence.descriptors.SingleTableMultitenantPolicy 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);
}
}
}
use of org.eclipse.persistence.descriptors.SingleTableMultitenantPolicy in project eclipselink by eclipse-ee4j.
the class MetadataAccessor method processPrimaryKeyJoinColumns.
/**
* INTERNAL:
* Process the primary key join columms for this accessors annotated element.
*/
protected List<PrimaryKeyJoinColumnMetadata> processPrimaryKeyJoinColumns(List<PrimaryKeyJoinColumnMetadata> primaryKeyJoinColumns) {
// this call will add any defaulted columns as necessary.
if (primaryKeyJoinColumns.isEmpty()) {
if (getDescriptor().hasCompositePrimaryKey()) {
// key. Foreign and primary key to have the same name.
for (DatabaseField primaryKeyField : getDescriptor().getPrimaryKeyFields()) {
PrimaryKeyJoinColumnMetadata primaryKeyJoinColumn = new PrimaryKeyJoinColumnMetadata(getProject());
primaryKeyJoinColumn.setReferencedColumnName(primaryKeyField.getName());
primaryKeyJoinColumn.setName(primaryKeyField.getName());
primaryKeyJoinColumns.add(primaryKeyJoinColumn);
}
} else {
// Add a default one for the single case, not setting any
// foreign and primary key names. They will default based
// on which accessor is using them.
primaryKeyJoinColumns.add(new PrimaryKeyJoinColumnMetadata(getProject()));
}
} else {
// add the multitenant primary key tenant discriminator fields.
if (getDescriptor().hasSingleTableMultitenant() && primaryKeyJoinColumns.size() != getDescriptor().getPrimaryKeyFields().size()) {
SingleTableMultitenantPolicy policy = (SingleTableMultitenantPolicy) getDescriptor().getClassDescriptor().getMultitenantPolicy();
Map<DatabaseField, String> tenantFields = policy.getTenantDiscriminatorFields();
// Go through the key sets ...
for (DatabaseField tenantField : tenantFields.keySet()) {
if (tenantField.isPrimaryKey()) {
PrimaryKeyJoinColumnMetadata primaryKeyJoinColumn = new PrimaryKeyJoinColumnMetadata();
primaryKeyJoinColumn.setName(tenantField.getName());
primaryKeyJoinColumn.setReferencedColumnName(tenantField.getName());
primaryKeyJoinColumn.setProject(getProject());
primaryKeyJoinColumns.add(primaryKeyJoinColumn);
}
}
}
}
// Now validate what we have.
if (getDescriptor().hasCompositePrimaryKey()) {
// key columns since we allow joining to partials.
for (PrimaryKeyJoinColumnMetadata pkJoinColumn : primaryKeyJoinColumns) {
if (pkJoinColumn.isPrimaryKeyFieldNotSpecified() || pkJoinColumn.isForeignKeyFieldNotSpecified()) {
throw ValidationException.incompletePrimaryKeyJoinColumnsSpecified(getAnnotatedElement());
}
}
} else {
if (primaryKeyJoinColumns.size() > 1) {
throw ValidationException.excessivePrimaryKeyJoinColumnsSpecified(getAnnotatedElement());
}
}
return primaryKeyJoinColumns;
}
Aggregations