use of org.hibernate.metamodel.mapping.SingularAttributeMapping in project hibernate-orm by hibernate.
the class CompoundNaturalIdMapping method extractNaturalIdFromEntityState.
@Override
public Object[] extractNaturalIdFromEntityState(Object[] state, SharedSessionContractImplementor session) {
if (state == null) {
return null;
}
if (state.length == attributes.size()) {
return state;
}
final Object[] values = new Object[attributes.size()];
for (int i = 0; i <= attributes.size() - 1; i++) {
final SingularAttributeMapping attributeMapping = attributes.get(i);
values[i] = state[attributeMapping.getStateArrayPosition()];
}
return values;
}
use of org.hibernate.metamodel.mapping.SingularAttributeMapping in project hibernate-orm by hibernate.
the class CompoundNaturalIdMapping method forEachJdbcValue.
@Override
public int forEachJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
assert value instanceof Object[];
final Object[] incoming = (Object[]) value;
assert incoming.length == attributes.size();
int span = 0;
for (int i = 0; i < attributes.size(); i++) {
final SingularAttributeMapping attribute = attributes.get(i);
span += attribute.forEachJdbcValue(incoming[i], clause, span + offset, valuesConsumer, session);
}
return span;
}
use of org.hibernate.metamodel.mapping.SingularAttributeMapping in project hibernate-orm by hibernate.
the class CompoundNaturalIdMapping method forEachDisassembledJdbcValue.
@Override
public int forEachDisassembledJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
assert value instanceof Object[];
final Object[] incoming = (Object[]) value;
assert incoming.length == attributes.size();
int span = 0;
for (int i = 0; i < attributes.size(); i++) {
final SingularAttributeMapping attribute = attributes.get(i);
span += attribute.forEachDisassembledJdbcValue(incoming[i], clause, span + offset, valuesConsumer, session);
}
return span;
}
use of org.hibernate.metamodel.mapping.SingularAttributeMapping in project hibernate-orm by hibernate.
the class CompoundNaturalIdMapping method verifyFlushState.
@Override
public void verifyFlushState(Object id, Object[] currentState, Object[] loadedState, SharedSessionContractImplementor session) {
if (isMutable()) {
// the natural id is mutable (!immutable), no need to do the checks
return;
}
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityPersister persister = getDeclaringType().getEntityPersister();
final Object[] naturalId = extractNaturalIdFromEntityState(currentState, session);
final Object snapshot = loadedState == null ? persistenceContext.getNaturalIdSnapshot(id, persister) : persister.getNaturalIdMapping().extractNaturalIdFromEntityState(loadedState, session);
final Object[] previousNaturalId = (Object[]) snapshot;
assert naturalId.length == getNaturalIdAttributes().size();
assert previousNaturalId.length == naturalId.length;
for (int i = 0; i < getNaturalIdAttributes().size(); i++) {
final SingularAttributeMapping attributeMapping = getNaturalIdAttributes().get(i);
final boolean updatable = attributeMapping.getAttributeMetadataAccess().resolveAttributeMetadata(persister).isUpdatable();
if (updatable) {
// property is updatable (mutable), there is nothing to check
continue;
}
final Object currentValue = naturalId[i];
final Object previousValue = previousNaturalId[i];
if (!attributeMapping.areEqual(currentValue, previousValue, session)) {
throw new HibernateException(String.format("An immutable attribute [%s] within compound natural identifier of entity %s was altered from `%s` to `%s`", attributeMapping.getAttributeName(), persister.getEntityName(), previousValue, currentValue));
}
}
}
use of org.hibernate.metamodel.mapping.SingularAttributeMapping in project hibernate-orm by hibernate.
the class BitSetJavaTypeTests method testResolution.
@Test
public void testResolution(SessionFactoryScope scope) {
final EntityPersister productType = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().findEntityDescriptor(Product.class);
final SingularAttributeMapping bitSetAttribute = (SingularAttributeMapping) productType.findAttributeMapping("bitSet");
// make sure BitSetTypeDescriptor was selected
assertThat(bitSetAttribute.getJavaType(), instanceOf(BitSetJavaType.class));
}
Aggregations