Search in sources :

Example 1 with MetaAttribute

use of org.hibernate.mapping.MetaAttribute in project hibernate-orm by hibernate.

the class NonReflectiveBinderTest method testNonMutatedInheritance.

@Test
@TestForIssue(jiraKey = "HBX-718")
public void testNonMutatedInheritance() {
    PersistentClass cm = metadata.getEntityBinding("org.hibernate.test.legacy.Wicked");
    MetaAttribute metaAttribute = cm.getMetaAttribute("globalmutated");
    assertNotNull(metaAttribute);
    /*assertEquals( metaAttribute.getValues().size(), 2 );		
		assertEquals( "top level", metaAttribute.getValues().get(0) );*/
    assertEquals("wicked level", metaAttribute.getValue());
    Property property = cm.getProperty("component");
    MetaAttribute propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 3 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );*/
    assertEquals("monetaryamount level", propertyAttribute.getValue());
    org.hibernate.mapping.Component component = (Component) property.getValue();
    property = component.getProperty("x");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 4 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
		assertEquals( "monetaryamount level", propertyAttribute.getValues().get(2) );*/
    assertEquals("monetaryamount x level", propertyAttribute.getValue());
    property = cm.getProperty("sortedEmployee");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 3 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );*/
    assertEquals("sortedemployee level", propertyAttribute.getValue());
    property = cm.getProperty("anotherSet");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 2 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );*/
    assertEquals("wicked level", propertyAttribute.getValue());
    Bag bag = (Bag) property.getValue();
    component = (Component) bag.getElement();
    assertEquals(4, component.getMetaAttributes().size());
    metaAttribute = component.getMetaAttribute("globalmutated");
    /*assertEquals( metaAttribute.getValues().size(), 3 );
		assertEquals( "top level", metaAttribute.getValues().get(0) );
		assertEquals( "wicked level", metaAttribute.getValues().get(1) );*/
    assertEquals("monetaryamount anotherSet composite level", metaAttribute.getValue());
    property = component.getProperty("emp");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 4 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
		assertEquals( "monetaryamount anotherSet composite level", propertyAttribute.getValues().get(2) );*/
    assertEquals("monetaryamount anotherSet composite property emp level", propertyAttribute.getValue());
    property = component.getProperty("empinone");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 4 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
		assertEquals( "monetaryamount anotherSet composite level", propertyAttribute.getValues().get(2) );*/
    assertEquals("monetaryamount anotherSet composite property empinone level", propertyAttribute.getValue());
}
Also used : Component(org.hibernate.mapping.Component) Bag(org.hibernate.mapping.Bag) MetaAttribute(org.hibernate.mapping.MetaAttribute) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with MetaAttribute

use of org.hibernate.mapping.MetaAttribute in project hibernate-orm by hibernate.

the class NonReflectiveBinderTest method testMetaInheritance.

@Test
public void testMetaInheritance() {
    PersistentClass cm = metadata.getEntityBinding("org.hibernate.test.legacy.Wicked");
    Map m = cm.getMetaAttributes();
    assertNotNull(m);
    assertNotNull(cm.getMetaAttribute("global"));
    assertNull(cm.getMetaAttribute("globalnoinherit"));
    MetaAttribute metaAttribute = cm.getMetaAttribute("implements");
    assertNotNull(metaAttribute);
    assertEquals("implements", metaAttribute.getName());
    assertTrue(metaAttribute.isMultiValued());
    assertEquals(3, metaAttribute.getValues().size());
    assertEquals("java.lang.Observer", metaAttribute.getValues().get(0));
    assertEquals("java.lang.Observer", metaAttribute.getValues().get(1));
    assertEquals("org.foo.BogusVisitor", metaAttribute.getValues().get(2));
    /*Property property = cm.getIdentifierProperty();
		property.getMetaAttribute(null);*/
    Iterator propertyIterator = cm.getPropertyIterator();
    while (propertyIterator.hasNext()) {
        Property element = (Property) propertyIterator.next();
        System.out.println(element);
        Map ma = element.getMetaAttributes();
        assertNotNull(ma);
        assertNotNull(element.getMetaAttribute("global"));
        MetaAttribute metaAttribute2 = element.getMetaAttribute("implements");
        assertNotNull(metaAttribute2);
        assertNull(element.getMetaAttribute("globalnoinherit"));
    }
    Property element = cm.getProperty("component");
    Map ma = element.getMetaAttributes();
    assertNotNull(ma);
    assertNotNull(element.getMetaAttribute("global"));
    assertNotNull(element.getMetaAttribute("componentonly"));
    assertNotNull(element.getMetaAttribute("allcomponent"));
    assertNull(element.getMetaAttribute("globalnoinherit"));
    MetaAttribute compimplements = element.getMetaAttribute("implements");
    assertNotNull(compimplements);
    assertEquals(compimplements.getValue(), "AnotherInterface");
    Property xp = ((Component) element.getValue()).getProperty("x");
    MetaAttribute propximplements = xp.getMetaAttribute("implements");
    assertNotNull(propximplements);
    assertEquals(propximplements.getValue(), "AnotherInterface");
}
Also used : Iterator(java.util.Iterator) MetaAttribute(org.hibernate.mapping.MetaAttribute) Component(org.hibernate.mapping.Component) Map(java.util.Map) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 3 with MetaAttribute

use of org.hibernate.mapping.MetaAttribute in project ACS by ACS-Community.

the class AbstractReverseEngineeringStrategy method tableToMetaAttributes.

@SuppressWarnings("unchecked")
@Override
public Map tableToMetaAttributes(TableIdentifier tableIdentifier) {
    Map map = super.tableToMetaAttributes(tableIdentifier);
    if (map == null)
        map = new HashMap<String, MetaAttribute>();
    // Check if table contains a XMLCLOB column
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        String tableName = tableIdentifier.getName();
        if (inheritanceTranslators[i].hasXmlClobType(tableName)) {
            MetaAttribute mattr = new MetaAttribute(HAS_XML_CLOB_TYPE);
            mattr.addValue("true");
            map.put(HAS_XML_CLOB_TYPE, mattr);
            break;
        }
    }
    // Check if table has a generated ID, necessary to generate the GenericGenerator custom annotation
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        String tableName = tableIdentifier.getName();
        String sequence = inheritanceTranslators[i].getSequenceForTable(tableName);
        if (sequence != null) {
            MetaAttribute mattr = new MetaAttribute(ORACLE_SEQUENCE);
            mattr.addValue(sequence);
            map.put(ORACLE_SEQUENCE, mattr);
            break;
        }
    }
    // Check all CHECK constraints for this table
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        String tableName = tableIdentifier.getName().toLowerCase();
        Map<String, String> typesForTable = inheritanceTranslators[i].getEnumTypesForTable(tableName);
        if (typesForTable == null || typesForTable.size() == 0)
            continue;
        else {
            MetaAttribute mattr2 = new MetaAttribute(HAS_ENUM_TYPES);
            mattr2.addValue("true");
            map.put(HAS_ENUM_TYPES, mattr2);
            mattr2 = new MetaAttribute(ENUM_TYPES);
            Iterator<Map.Entry<String, String>> it = typesForTable.entrySet().iterator();
            StringBuilder sb = new StringBuilder();
            while (it.hasNext()) {
                Map.Entry<String, String> entry = it.next();
                sb.append(entry.getKey());
                sb.append("|");
                sb.append(entry.getValue());
                if (it.hasNext())
                    sb.append(",");
            }
            mattr2.addValue(sb.toString());
            map.put(ENUM_TYPES, mattr2);
        }
    }
    // Check whether table is "Identifiable"
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        String tableName = tableIdentifier.getName().toLowerCase();
        if (inheritanceTranslators[i].isIdentifiable(tableName)) {
            MetaAttribute mattr3 = new MetaAttribute(MetaAttributeConstants.IMPLEMENTS);
            mattr3.addValue("alma.tmcdb.history.Identifiable");
            map.put("implements", mattr3);
        }
    }
    // Check whether table is "Backloggable"
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        String tableName = tableIdentifier.getName().toLowerCase();
        if (inheritanceTranslators[i].isBackloggable(tableName)) {
            MetaAttribute mattr4 = new MetaAttribute(MetaAttributeConstants.IMPLEMENTS);
            mattr4.addValue("alma.tmcdb.history.Backloggable");
            map.put("implements", mattr4);
        }
    }
    // Check if table is superclass or child class
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        String tableName = tableIdentifier.getName().toLowerCase();
        String superClass = inheritanceTranslators[i].getSuperTable(tableName);
        if (superClass != null) {
            MetaAttribute mattr = new MetaAttribute(MetaAttributeConstants.EXTENDS);
            mattr.addValue(superClass);
            map.put("extends", mattr);
            return map;
        } else {
            MetaAttribute mattr = new MetaAttribute(MetaAttributeConstants.EXTENDS);
            mattr.addValue("alma.acs.tmcdb.translator.TmcdbObject");
            map.put("extends", mattr);
            for (int j = 0; j != inheritanceTranslators.length; j++) {
                if (inheritanceTranslators[j].isSuperClass(tableName)) {
                    mattr = new MetaAttribute(IS_SUPER_CLASS);
                    mattr.addValue("true");
                    map.put(IS_SUPER_CLASS, mattr);
                    return map;
                }
            }
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) MetaAttribute(org.hibernate.mapping.MetaAttribute) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with MetaAttribute

use of org.hibernate.mapping.MetaAttribute in project ACS by ACS-Community.

the class AbstractReverseEngineeringStrategy method columnToMetaAttributes.

@SuppressWarnings("unchecked")
@Override
public Map columnToMetaAttributes(TableIdentifier identifier, String column) {
    Map map = super.columnToMetaAttributes(identifier, column);
    if (map == null)
        map = new HashMap<String, MetaAttribute>();
    String tableName = identifier.getName().toLowerCase();
    // Don't generate getter/setters for inheritance-related fields
    MetaAttribute mattr = new MetaAttribute(MetaAttributeConstants.GEN_PROPERTY);
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        List<String> columns = inheritanceTranslators[i].getPkFkCombinationColumns(tableName);
        if (columns != null && columns.contains(column.toLowerCase())) {
            mattr.addValue("false");
            map.put("gen-property", mattr);
            return map;
        }
    }
    // Make everything protected
    mattr.addValue("protected");
    map.put("scope-field", mattr);
    // Check for special XMLCLOB types, they get a specific annotation generated
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        if (inheritanceTranslators[i].hasXmlClobType(tableName)) {
            if (inheritanceTranslators[i].isXmlClobType(tableName, column)) {
                MetaAttribute mattr2 = new MetaAttribute(IS_XML_CLOB_TYPE);
                mattr2.addValue("true");
                map.put(IS_XML_CLOB_TYPE, mattr2);
                break;
            }
        }
    }
    for (int i = 0; i < inheritanceTranslators.length; i++) {
        if (inheritanceTranslators[i].isKeyPiece(tableName, column)) {
            MetaAttribute mattr2 = new MetaAttribute("use-in-equals");
            mattr2.addValue("true");
            map.put("use-in-equals", mattr2);
            break;
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) MetaAttribute(org.hibernate.mapping.MetaAttribute) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MetaAttribute (org.hibernate.mapping.MetaAttribute)4 Map (java.util.Map)3 HashMap (java.util.HashMap)2 Component (org.hibernate.mapping.Component)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 Property (org.hibernate.mapping.Property)2 Test (org.junit.Test)2 Iterator (java.util.Iterator)1 Bag (org.hibernate.mapping.Bag)1 TestForIssue (org.hibernate.testing.TestForIssue)1