use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class ModelBinder method bindEntityVersion.
private void bindEntityVersion(MappingDocument sourceDocument, EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
final VersionAttributeSource versionAttributeSource = hierarchySource.getVersionAttributeSource();
final SimpleValue versionValue = new SimpleValue(sourceDocument.getMetadataCollector(), rootEntityDescriptor.getTable());
versionValue.makeVersion();
bindSimpleValueType(sourceDocument, versionAttributeSource.getTypeInformation(), versionValue);
relationalObjectBinder.bindColumnsAndFormulas(sourceDocument, versionAttributeSource.getRelationalValueSources(), versionValue, false, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
return implicitNamingStrategy.determineBasicColumnName(versionAttributeSource);
}
});
Property prop = new Property();
prop.setValue(versionValue);
bindProperty(sourceDocument, versionAttributeSource, prop);
// but just to make sure...
if (prop.getValueGenerationStrategy() != null) {
if (prop.getValueGenerationStrategy().getGenerationTiming() == GenerationTiming.INSERT) {
throw new MappingException("'generated' attribute cannot be 'insert' for version/timestamp property", sourceDocument.getOrigin());
}
}
if (versionAttributeSource.getUnsavedValue() != null) {
versionValue.setNullValue(versionAttributeSource.getUnsavedValue());
} else {
versionValue.setNullValue("undefined");
}
rootEntityDescriptor.setVersion(prop);
rootEntityDescriptor.setDeclaredVersion(prop);
rootEntityDescriptor.addProperty(prop);
}
use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class ModelBinder method bindJoinedSubclassEntity.
private void bindJoinedSubclassEntity(JoinedSubclassEntitySourceImpl entitySource, JoinedSubclass entityDescriptor) {
MappingDocument mappingDocument = entitySource.sourceMappingDocument();
bindBasicEntityValues(mappingDocument, entitySource, entityDescriptor);
final Table primaryTable = bindEntityTableSpecification(mappingDocument, entitySource.getPrimaryTable(), null, entitySource, entityDescriptor);
entityDescriptor.setTable(primaryTable);
if (log.isDebugEnabled()) {
log.debugf("Mapping joined-subclass: %s -> %s", entityDescriptor.getEntityName(), primaryTable.getName());
}
// KEY
final SimpleValue keyBinding = new DependantValue(mappingDocument.getMetadataCollector(), primaryTable, entityDescriptor.getIdentifier());
if (mappingDocument.getBuildingOptions().useNationalizedCharacterData()) {
keyBinding.makeNationalized();
}
entityDescriptor.setKey(keyBinding);
keyBinding.setCascadeDeleteEnabled(entitySource.isCascadeDeleteEnabled());
relationalObjectBinder.bindColumns(mappingDocument, entitySource.getPrimaryKeyColumnSources(), keyBinding, false, new RelationalObjectBinder.ColumnNamingDelegate() {
int count = 0;
@Override
public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
final Column column = primaryTable.getPrimaryKey().getColumn(count++);
return database.toIdentifier(column.getQuotedName());
}
});
keyBinding.setForeignKeyName(entitySource.getExplicitForeignKeyName());
// model.getKey().setType( new Type( model.getIdentifier() ) );
entityDescriptor.createPrimaryKey();
entityDescriptor.createForeignKey();
// todo : tooling hints
bindAllEntityAttributes(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
bindJoinedSubclassEntities(entitySource, entityDescriptor);
}
use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class CollectionCompositeElementExplicitConversionTest method checkComposite.
private void checkComposite(Component composite) throws Exception {
// check `eyeColor`
final Property eyeColorProperty = composite.getProperty("eyeColor");
final SimpleValue eyeColorValueMapping = (SimpleValue) eyeColorProperty.getValue();
assertThat(simpleValueAttributeConverterDescriptorField.get(eyeColorValueMapping), CoreMatchers.notNullValue());
// check `hairColor`
final Property hairColorProperty = composite.getProperty("hairColor");
final SimpleValue hairColorValueMapping = (SimpleValue) hairColorProperty.getValue();
assertThat(simpleValueAttributeConverterDescriptorField.get(hairColorValueMapping), CoreMatchers.notNullValue());
}
use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicOrmXmlConverterApplication.
@Test
@TestForIssue(jiraKey = "HHH-8462")
public void testBasicOrmXmlConverterApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).addURL(ConfigHelper.findAsResource("org/hibernate/test/converter/orm.xml")).getMetadataBuilder().build();
PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter not applied");
}
AttributeConverterTypeAdapter basicType = assertTyping(AttributeConverterTypeAdapter.class, type);
assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicConverterDisableApplication.
@Test
public void testBasicConverterDisableApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester2.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
PersistentClass tester = metadata.getEntityBinding(Tester2.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
if (AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter applied (should not have been)");
}
AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
assertEquals(Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations