/** * INTERNAL: * Indicates if multitenant metadata has been processed for this descriptor. */ public boolean hasMultitenant() { return m_descriptor.hasMultitenantPolicy(); }
/** * PUBLIC * @return true if this descriptor is configured with a table per tenant policy. */ public boolean hasTablePerMultitenantPolicy() { return hasMultitenantPolicy() && getMultitenantPolicy().isTablePerMultitenantPolicy(); }
/** * PUBLIC * @return true if this descriptor is configured with a table per tenant policy. */ public boolean hasTablePerMultitenantPolicy() { return hasMultitenantPolicy() && getMultitenantPolicy().isTablePerMultitenantPolicy(); }
/** * PUBLIC: * Return the descriptor for the alias. * @param alias The descriptor alias. * @return The descriptor for the alias or {@code null} if no descriptor was found. */ @Override public ClassDescriptor getDescriptorForAlias(final String alias) { // If we have a descriptors list return our sessions descriptor and // not that of the project since we may be dealing with a multitenant // descriptor which will have been initialized locally on the session. // The project descriptor will be not initialized. final ClassDescriptor desc = project.getDescriptorForAlias(alias); if (desc != null && desc.hasMultitenantPolicy() && this.descriptors != null) { return this.descriptors.get(desc.getJavaClass()); } else { return desc; } }
/** * PUBLIC: * Return the descriptor for the alias. * @param alias The descriptor alias. * @param The descriptor for the alias or {@code null} if no descriptor was found. */ @Override public ClassDescriptor getDescriptorForAlias(final String alias) { // If we have a descriptors list return our sessions descriptor and // not that of the project since we may be dealing with a multitenant // descriptor which will have been initialized locally on the session. // The project descriptor will be not initialized. final ClassDescriptor desc = project.getDescriptorForAlias(alias); if (desc != null && desc.hasMultitenantPolicy() && this.descriptors != null) { return this.descriptors.get(desc.getJavaClass()); } else { return desc; } }
/** * INTERNAL: * Prepare the receiver for execution in a session. */ @Override public void prepareForExecution() throws QueryException { super.prepareForExecution(); this.containerPolicy.prepareForExecution(); // Modifying the translation row here will modify it on the original // query which is not good. So we have to clone the translation row if // we are going to append tenant discriminator fields to it. if (descriptor.hasMultitenantPolicy()) { translationRow = translationRow.clone(); descriptor.getMultitenantPolicy().addFieldsToRow(translationRow, getSession()); } }
/** * INTERNAL: * Prepare the receiver for execution in a session. */ @Override public void prepareForExecution() throws QueryException { super.prepareForExecution(); this.containerPolicy.prepareForExecution(); // Modifying the translation row here will modify it on the original // query which is not good. So we have to clone the translation row if // we are going to append tenant discriminator fields to it. if (descriptor.hasMultitenantPolicy()) { translationRow = translationRow.clone(); descriptor.getMultitenantPolicy().addFieldsToRow(translationRow, getSession()); } }
/** * Build the row representation of an object. * This is only used for aggregates. */ public AbstractRecord buildRowWithChangeSet(AbstractRecord databaseRow, ObjectChangeSet objectChangeSet, AbstractSession session, WriteType writeType) { List<ChangeRecord> changes = (List)objectChangeSet.getChanges(); int size = changes.size(); for (int index = 0; index < size; index++) { ChangeRecord changeRecord = changes.get(index); DatabaseMapping mapping = changeRecord.getMapping(); mapping.writeFromObjectIntoRowWithChangeRecord(changeRecord, databaseRow, session, writeType); } // If this descriptor is involved in inheritance add the class type. if (this.descriptor.hasInheritance()) { this.descriptor.getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If the session uses multi-tenancy, add the tenant id field. if (getDescriptor().hasMultitenantPolicy()) { getDescriptor().getMultitenantPolicy().addFieldsToRow(databaseRow, session); } return databaseRow; }
/** * Build the row representation of an object. * This is only used for aggregates. */ public AbstractRecord buildRowWithChangeSet(AbstractRecord databaseRow, ObjectChangeSet objectChangeSet, AbstractSession session, WriteType writeType) { List<ChangeRecord> changes = (List)objectChangeSet.getChanges(); int size = changes.size(); for (int index = 0; index < size; index++) { ChangeRecord changeRecord = changes.get(index); DatabaseMapping mapping = changeRecord.getMapping(); mapping.writeFromObjectIntoRowWithChangeRecord(changeRecord, databaseRow, session, writeType); } // If this descriptor is involved in inheritance add the class type. if (this.descriptor.hasInheritance()) { this.descriptor.getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If the session uses multi-tenancy, add the tenant id field. if (getDescriptor().hasMultitenantPolicy()) { getDescriptor().getMultitenantPolicy().addFieldsToRow(databaseRow, session); } return databaseRow; }
if (getDescriptor().hasMultitenantPolicy()) { getDescriptor().getMultitenantPolicy().addFieldsToRow(databaseRow, query.getExecutionSession());
if (getDescriptor().hasMultitenantPolicy()) { getDescriptor().getMultitenantPolicy().addFieldsToRow(databaseRow, query.getExecutionSession());
/** * Build the row representation of the object for update. The row built does not * contain entries for uninstantiated attributes. */ public AbstractRecord buildRowForShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = this.descriptor.getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); mapping.writeFromObjectIntoRowForShallowInsert(object, databaseRow, session); } // If this descriptor is involved in inheritance add the class type. if (this.descriptor.hasInheritance()) { this.descriptor.getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!this.descriptor.isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow, object, session); } // If the session uses multi-tenancy, add the tenant id field. if (getDescriptor().hasMultitenantPolicy()) { getDescriptor().getMultitenantPolicy().addFieldsToRow(databaseRow, session); } return databaseRow; }
/** * Build the row representation of the object for update. The row built does not * contain entries for uninstantiated attributes. */ public AbstractRecord buildRowForShallowInsert(AbstractRecord databaseRow, Object object, AbstractSession session) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = this.descriptor.getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); mapping.writeFromObjectIntoRowForShallowInsert(object, databaseRow, session); } // If this descriptor is involved in inheritance add the class type. if (this.descriptor.hasInheritance()) { this.descriptor.getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!this.descriptor.isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow, object, session); } // If the session uses multi-tenancy, add the tenant id field. if (getDescriptor().hasMultitenantPolicy()) { getDescriptor().getMultitenantPolicy().addFieldsToRow(databaseRow, session); } return databaseRow; }
/** * Build the row representation of an object. */ public AbstractRecord buildRow(AbstractRecord databaseRow, Object object, AbstractSession session, WriteType writeType) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = this.descriptor.getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); mapping.writeFromObjectIntoRow(object, databaseRow, session, writeType); } // If this descriptor is involved in inheritance add the class type. if (this.descriptor.hasInheritance()) { this.descriptor.getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (this.descriptor.hasMultipleTables() && !this.descriptor.isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow, object, session); } // If the session uses multi-tenancy, add the tenant id field. if (getDescriptor().hasMultitenantPolicy()) { getDescriptor().getMultitenantPolicy().addFieldsToRow(databaseRow, session); } return databaseRow; } /**
/** * Build the row representation of an object. */ public AbstractRecord buildRow(AbstractRecord databaseRow, Object object, AbstractSession session, WriteType writeType) { // PERF: Avoid synchronized enumerator as is concurrency bottleneck. List mappings = this.descriptor.getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); mapping.writeFromObjectIntoRow(object, databaseRow, session, writeType); } // If this descriptor is involved in inheritance add the class type. if (this.descriptor.hasInheritance()) { this.descriptor.getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (this.descriptor.hasMultipleTables() && !this.descriptor.isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow, object, session); } // If the session uses multi-tenancy, add the tenant id field. if (getDescriptor().hasMultitenantPolicy()) { getDescriptor().getMultitenantPolicy().addFieldsToRow(databaseRow, session); } return databaseRow; } /**
public void buildTemplateInsertRow(AbstractSession session, AbstractRecord databaseRow) { for (Iterator mappings = this.descriptor.getMappings().iterator(); mappings.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)mappings.next(); mapping.writeInsertFieldsIntoRow(databaseRow, session); } // If this descriptor is involved in inheritance add the class type. if (this.descriptor.hasInheritance()) { this.descriptor.getInheritancePolicy().addClassIndicatorFieldToInsertRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!this.descriptor.isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow); } if (this.descriptor.usesOptimisticLocking()) { this.descriptor.getOptimisticLockingPolicy().addLockFieldsToUpdateRow(databaseRow, session); } // If the session uses multi-tenancy, add the tenant id field. if (this.descriptor.hasMultitenantPolicy()) { this.descriptor.getMultitenantPolicy().addFieldsToRow(databaseRow, session); } if (this.descriptor.hasSerializedObjectPolicy()) { databaseRow.put(this.descriptor.getSerializedObjectPolicy().getField(), null); } // remove any fields from the databaseRow trimFieldsForInsert(session, databaseRow); }
if (this.descriptor.hasMultitenantPolicy()) { this.descriptor.getMultitenantPolicy().addFieldsToRow(databaseRow, session);
/** * INTERNAL: * Add the query the session. Table per tenant queries should not be added * to the regular query list as these queries may need to be initialized * per EM. */ protected void addJPAQuery(JPAQuery query, AbstractSession session) { if (query.isJPQLQuery()) { List<ClassDescriptor> descriptors = new JPQLQueryHelper().getClassDescriptors(query.getJPQLString(), session); for (ClassDescriptor descriptor : descriptors) { // If we find one descriptor that has table per tenant multitenancy, // then add it to the multitenant query list. These queries may // need to be initialized per EM rather than straight up at the // EMF level. if (descriptor.hasMultitenantPolicy() && descriptor.getMultitenantPolicy().isTablePerMultitenantPolicy()) { // Store the descriptors so we don't have to parse them again. query.setDescriptors(descriptors); session.addJPATablePerTenantQuery(query); return; } } } session.addJPAQuery(query); }
/** * INTERNAL: * Prepare the receiver for execution in a session. */ public void prepareForExecution() throws QueryException { super.prepareForExecution(); // For bug 2989998 the translation row now sometimes set earlier in prepare. if (shouldPrepare()) { if (this.selectionId != null) { // Row must come from the key. this.translationRow = this.descriptor.getObjectBuilder().buildRowFromPrimaryKeyValues(this.selectionId, getSession()); } else if (this.selectionObject != null) { // The expression is set in the prepare as params. this.translationRow = this.descriptor.getObjectBuilder().buildRowForTranslation(this.selectionObject, getSession()); } } // If we have tenant discriminator fields we need to add them to the // database row when doing a primary key query. // Modifying the translation row here will modify it on the original // query which is not good (will append the tenant field to the sql call // for subsequent queries) The translation row must be cloned to isolate // this. if (getDescriptor().hasMultitenantPolicy()) { this.translationRow = this.translationRow.clone(); getDescriptor().getMultitenantPolicy().addFieldsToRow(this.translationRow, getSession()); } }
/** * INTERNAL: * Prepare the receiver for execution in a session. */ public void prepareForExecution() throws QueryException { super.prepareForExecution(); // For bug 2989998 the translation row now sometimes set earlier in prepare. if (shouldPrepare()) { if (this.selectionId != null) { // Row must come from the key. this.translationRow = this.descriptor.getObjectBuilder().buildRowFromPrimaryKeyValues(this.selectionId, getSession()); } else if (this.selectionObject != null) { // The expression is set in the prepare as params. this.translationRow = this.descriptor.getObjectBuilder().buildRowForTranslation(this.selectionObject, getSession()); } } // If we have tenant discriminator fields we need to add them to the // database row when doing a primary key query. // Modifying the translation row here will modify it on the original // query which is not good (will append the tenant field to the sql call // for subsequent queries) The translation row must be cloned to isolate // this. if (getDescriptor().hasMultitenantPolicy()) { this.translationRow = this.translationRow.clone(); getDescriptor().getMultitenantPolicy().addFieldsToRow(this.translationRow, getSession()); } }