use of org.hibernate.mapping.Column in project hibernate-orm by hibernate.
the class AbstractFunctionalTest method afterMetadataBuilt.
@Override
protected void afterMetadataBuilt(Metadata metadata) {
if (addVersions) {
for (PersistentClass clazz : metadata.getEntityBindings()) {
if (clazz.getVersion() != null) {
continue;
}
try {
clazz.getMappedClass().getMethod("getVersion");
clazz.getMappedClass().getMethod("setVersion", long.class);
} catch (NoSuchMethodException e) {
continue;
}
RootClass rootClazz = clazz.getRootClass();
Property versionProperty = new Property();
versionProperty.setName("version");
SimpleValue value = new SimpleValue((MetadataImplementor) metadata, rootClazz.getTable());
value.setTypeName("long");
Column column = new Column();
column.setValue(value);
column.setName("version");
value.addColumn(column);
rootClazz.getTable().addColumn(column);
versionProperty.setValue(value);
rootClazz.setVersion(versionProperty);
rootClazz.addProperty(versionProperty);
}
}
}
use of org.hibernate.mapping.Column in project hibernate-orm by hibernate.
the class VersionsJoinTableRangeComponentNamingTest method testJoinColumnNamesComponent2.
@Test
public void testJoinColumnNamesComponent2() {
PersistentClass auditClass = metadata().getEntityBinding(COMPONENT_2_AUDIT_JOIN_TABLE_NAME);
assert auditClass != null;
@SuppressWarnings({ "unchecked" }) Iterator<Column> columns = auditClass.getTable().getColumnIterator();
boolean id1Found = false;
boolean id2Found = false;
while (columns.hasNext()) {
Column column = columns.next();
if ("VJTRCTE2_ID".equals(column.getName())) {
id1Found = true;
}
if ("VJTRTAE_ID".equals(column.getName())) {
id2Found = true;
}
}
assert id1Found && id2Found;
}
use of org.hibernate.mapping.Column in project hibernate-orm by hibernate.
the class VersionsJoinTableRangeComponentNamingTest method testOverrideNotAudited.
/**
* Verify that
* {@link VersionsJoinTableRangeComponentTestEntity#getComponent3()} is
* partially audited.
*/
@Test
public void testOverrideNotAudited() {
PersistentClass auditClass = metadata().getEntityBinding(VersionsJoinTableRangeComponentTestEntity.class.getName() + "_AUD");
assert auditClass != null;
@SuppressWarnings({ "unchecked" }) Iterator<Column> columns = auditClass.getTable().getColumnIterator();
boolean auditColumn1Found = false;
boolean auditColumn2Found = false;
while (columns.hasNext()) {
Column column = columns.next();
if ("STR1".equals(column.getName())) {
auditColumn1Found = true;
}
if ("STR2".equals(column.getName())) {
auditColumn2Found = true;
}
}
assert auditColumn1Found && !auditColumn2Found;
}
use of org.hibernate.mapping.Column in project hibernate-orm by hibernate.
the class VersionsJoinTableNaming method testJoinColumnName.
@SuppressWarnings({ "unchecked" })
@Test
public void testJoinColumnName() {
Iterator<Column> columns = metadata().getEntityBinding(MIDDLE_VERSIONS_ENTITY_NAME).getTable().getColumnIterator();
boolean id1Found = false;
boolean id2Found = false;
while (columns.hasNext()) {
Column column = columns.next();
if ("VJT_ID".equals(column.getName())) {
id1Found = true;
}
if ("STR_ID".equals(column.getName())) {
id2Found = true;
}
}
assert id1Found && id2Found;
}
use of org.hibernate.mapping.Column in project hibernate-orm by hibernate.
the class SingleAuditParentsTest method testCreatedAuditTable.
@Test
public void testCreatedAuditTable() {
Set<String> expectedColumns = TestTools.makeSet("child", "grandparent", "id");
Set<String> unexpectedColumns = TestTools.makeSet("parent", "relation_id", "notAudited");
Table table = metadata().getEntityBinding("org.hibernate.envers.test.integration.superclass.auditparents.ChildSingleParentEntity_AUD").getTable();
for (String columnName : expectedColumns) {
// Check whether expected column exists.
Assert.assertNotNull(table.getColumn(new Column(columnName)));
}
for (String columnName : unexpectedColumns) {
// Check whether unexpected column does not exist.
Assert.assertNull(table.getColumn(new Column(columnName)));
}
}
Aggregations