Search in sources :

Example 6 with IProperty

use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.

the class OrmShape method initModel.

/**
 * creates children of the shape,
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void initModel() {
    Object ormElement = getOrmElement();
    if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfRootClass()) {
        IPersistentClass rootClass = (IPersistentClass) ormElement;
        IProperty identifierProperty = rootClass.getIdentifierProperty();
        if (identifierProperty != null) {
            addChild(new Shape(identifierProperty, getConsoleConfigName()));
        }
        IValue identifier = rootClass.getIdentifier();
        if (identifier != null && identifier.isComponent()) {
            IValue component = identifier;
            if (component.isEmbedded()) {
                Iterator<IProperty> iterator = identifier.getPropertyIterator();
                while (iterator.hasNext()) {
                    IProperty property = iterator.next();
                    addChild(new Shape(property, getConsoleConfigName()));
                }
            }
        }
        Iterator<IProperty> iterator = rootClass.getPropertyIterator();
        while (iterator.hasNext()) {
            IProperty field = iterator.next();
            if (!field.isBackRef()) {
                if (!field.isComposite()) {
                    final IValue val = field.getValue();
                    Shape bodyOrmShape = null;
                    if (val.isSimpleValue() && val.isTypeSpecified()) {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    } else {
                        if (val.isCollection()) {
                            bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
                        } else {
                            IType type = getTypeUsingExecContext(val);
                            if (type != null && type.isEntityType()) {
                                bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                            } else {
                                bodyOrmShape = new Shape(field, getConsoleConfigName());
                            }
                        }
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
    } else if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfSubclass()) {
        IPersistentClass rootClass = ((IPersistentClass) ormElement).getRootClass();
        IProperty identifierProperty = rootClass.getIdentifierProperty();
        if (identifierProperty != null) {
            addChild(new Shape(identifierProperty, getConsoleConfigName()));
        }
        IValue identifier = rootClass.getIdentifier();
        if (identifier.isComponent()) {
            Iterator<IProperty> iterator = identifier.getPropertyIterator();
            while (iterator.hasNext()) {
                IProperty property = iterator.next();
                addChild(new Shape(property, getConsoleConfigName()));
            }
        }
        Iterator<IProperty> iterator = rootClass.getPropertyIterator();
        while (iterator.hasNext()) {
            IProperty field = iterator.next();
            if (!field.isBackRef()) {
                if (!field.isComposite()) {
                    IValue fieldValue = field.getValue();
                    boolean typeIsAccessible = true;
                    if (fieldValue.isSimpleValue() && fieldValue.isTypeSpecified()) {
                        try {
                            field.getValue().getType();
                        } catch (Exception e) {
                            typeIsAccessible = false;
                        }
                    }
                    Shape bodyOrmShape = null;
                    if (typeIsAccessible && field.getValue().isSimpleValue()) {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    } else if (typeIsAccessible && field.getValue().getType().isEntityType()) {
                        bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    } else if (typeIsAccessible && field.getValue().getType().isCollectionType()) {
                        bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
                    } else {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
        Iterator<IProperty> iter = ((IPersistentClass) ormElement).getPropertyIterator();
        while (iter.hasNext()) {
            IProperty property = iter.next();
            if (!property.isBackRef()) {
                if (!property.isComposite()) {
                    boolean typeIsAccessible = true;
                    IValue propertyValue = property.getValue();
                    if (propertyValue.isSimpleValue() && propertyValue.isTypeSpecified()) {
                        try {
                            property.getValue().getType();
                        } catch (Exception e) {
                            typeIsAccessible = false;
                        }
                    }
                    Shape bodyOrmShape = null;
                    if (typeIsAccessible && property.getValue().getType().isEntityType()) {
                        bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
                    } else if (typeIsAccessible && property.getValue().getType().isCollectionType()) {
                        bodyOrmShape = new ComponentShape(property, getConsoleConfigName());
                    } else {
                        bodyOrmShape = new Shape(property, getConsoleConfigName());
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
    } else if (ormElement instanceof ITable) {
        Iterator iterator = ((ITable) getOrmElement()).getColumnIterator();
        while (iterator.hasNext()) {
            IColumn column = (IColumn) iterator.next();
            Shape bodyOrmShape = new Shape(column, getConsoleConfigName());
            addChild(bodyOrmShape);
        }
    }
}
Also used : IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IType(org.jboss.tools.hibernate.runtime.spi.IType) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Iterator(java.util.Iterator) ITable(org.jboss.tools.hibernate.runtime.spi.ITable)

Example 7 with IProperty

use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.

the class ShapeEditPart method getSelectionColor.

protected Color getSelectionColor() {
    Color result = ResourceManager.getInstance().getColor(new RGB(255, 0, 0));
    final Object el = getElement();
    if (el instanceof IPersistentClass || el instanceof IProperty) {
        result = ResourceManager.getInstance().getColor(new RGB(112, 161, 99));
    } else if (el instanceof IValue) {
        IValue value = (IValue) el;
        if (value.isSimpleValue() || value.isOneToMany()) {
            result = ResourceManager.getInstance().getColor(new RGB(112, 161, 99));
        }
    } else if (el instanceof ITable || el instanceof IColumn) {
        result = ResourceManager.getInstance().getColor(new RGB(66, 173, 247));
    }
    return result;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Color(org.eclipse.swt.graphics.Color) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) RGB(org.eclipse.swt.graphics.RGB) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 8 with IProperty

use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.

the class HbmExporterTest method testList.

public void testList() {
    // $NON-NLS-1$
    IConfiguration config = getConfigurationFor("pack.A");
    // $NON-NLS-1$ //$NON-NLS-2$
    checkClassesMaped(config, "pack.A", "pack.B");
    // $NON-NLS-1$
    IPersistentClass a = config.getClassMapping("pack.A");
    // $NON-NLS-1$
    IPersistentClass b = config.getClassMapping("pack.B");
    // $NON-NLS-1$
    IProperty listProp = a.getProperty("list");
    assertNotNull(listProp.getValue());
    IValue value = listProp.getValue();
    assertTrue("Expected to get List-type mapping", value.isList());
    assertTrue(value.getCollectionElement().isOneToMany());
    assertTrue(value.getCollectionTable().equals(b.getTable()));
    assertNotNull(value.getIndex());
    assertNotNull(value.getKey());
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 9 with IProperty

use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.

the class HbmExporterTest method testMap.

public void testMap() {
    // $NON-NLS-1$
    IConfiguration config = getConfigurationFor("pack.A");
    // $NON-NLS-1$ //$NON-NLS-2$
    checkClassesMaped(config, "pack.A", "pack.B");
    // $NON-NLS-1$
    IPersistentClass a = config.getClassMapping("pack.A");
    // $NON-NLS-1$
    IPersistentClass b = config.getClassMapping("pack.B");
    // $NON-NLS-1$
    IProperty mapValue = a.getProperty("mapValue");
    assertNotNull(mapValue.getValue());
    IValue value = mapValue.getValue();
    assertTrue("Expected to get Map-type mapping", value.isMap());
    assertTrue(value.getCollectionElement().isOneToMany());
    assertTrue(value.getCollectionTable().equals(b.getTable()));
    assertNotNull(value.getKey());
    // $NON-NLS-1$
    assertEquals("string", value.getKey().getType().getName());
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 10 with IProperty

use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.

the class HbmExporterTest method testId.

public void testId() {
    // $NON-NLS-1$
    IConfiguration config = getConfigurationFor("pack.A");
    // $NON-NLS-1$ //$NON-NLS-2$
    checkClassesMaped(config, "pack.A", "pack.B");
    // $NON-NLS-1$
    IPersistentClass a = config.getClassMapping("pack.A");
    // $NON-NLS-1$
    IPersistentClass b = config.getClassMapping("pack.B");
    IProperty aId = a.getIdentifierProperty();
    IProperty bId = b.getIdentifierProperty();
    assertNotNull(aId);
    assertNotNull(bId);
    // $NON-NLS-1$
    assertEquals("id", aId.getName());
    // $NON-NLS-1$
    assertEquals("id", bId.getName());
}
Also used : IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Aggregations

IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)93 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)53 Property (org.hibernate.mapping.Property)40 Test (org.junit.Test)33 RootClass (org.hibernate.mapping.RootClass)27 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)20 PersistentClass (org.hibernate.mapping.PersistentClass)18 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)12 SimpleValue (org.hibernate.mapping.SimpleValue)12 AbstractPropertyFacade (org.jboss.tools.hibernate.runtime.common.AbstractPropertyFacade)12 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)12 FileNotFoundException (java.io.FileNotFoundException)9 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)9 Component (org.hibernate.mapping.Component)8 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)8 IEditorPart (org.eclipse.ui.IEditorPart)7 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)7 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 Mappings (org.hibernate.cfg.Mappings)6 PartInitException (org.eclipse.ui.PartInitException)5