Search in sources :

Example 86 with IProperty

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

the class HQLScratchpadAction method generateQuery.

/* (non-Javadoc)
	 * @see org.hibernate.eclipse.console.actions.OpenQueryEditorAction#generateQuery(org.eclipse.jface.viewers.TreePath)
	 */
protected String generateQuery(TreePath path) {
    Object node = path.getLastSegment();
    if (node instanceof IPersistentClass) {
        String name = ((IPersistentClass) node).getEntityName();
        // $NON-NLS-1$
        return "from " + name;
    } else if (node instanceof IProperty) {
        String prName = ((IProperty) node).getName();
        IPersistentClass pClass = ((IProperty) node).getPersistentClass();
        // $NON-NLS-1$
        String enName = "";
        if (pClass != null) {
            enName = pClass.getEntityName();
            enName = enName.substring(enName.lastIndexOf('.') + 1);
        } else {
            // Generate script for Component property
            for (int i = path.getSegmentCount() - 2; i > 0; i--) {
                if (path.getSegment(i) instanceof IPersistentClass) {
                    enName = ((IPersistentClass) path.getSegment(i)).getEntityName();
                    enName = enName.substring(enName.lastIndexOf('.') + 1);
                } else if (path.getSegment(i) instanceof IProperty) {
                    // $NON-NLS-1$
                    prName = ((IProperty) path.getSegment(i)).getName() + "." + prName;
                }
            }
        }
        // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        return "select o." + prName + " from " + enName + " o";
    } else if (node instanceof BaseNode) {
        BaseNode baseNode = (BaseNode) node;
        ConsoleConfiguration consoleConfiguration = baseNode.getConsoleConfiguration();
        if (consoleConfiguration.isSessionFactoryCreated()) {
            return baseNode.getHQL();
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) BaseNode(org.hibernate.console.node.BaseNode) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 87 with IProperty

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

the class OpenMappingAction method run.

/**
 * @param consoleConfig
 * @param selection
 * @param selectionParent
 * @throws JavaModelException
 * @throws PartInitException
 * @throws PresistanceClassNotFoundException
 * @throws FileNotFoundException
 */
public static IEditorPart run(ConsoleConfiguration consoleConfig, Object selection, Object selectionParent) throws PartInitException, JavaModelException, FileNotFoundException {
    IEditorPart editorPart = null;
    IFile file = null;
    if (selection instanceof IProperty) {
        IProperty p = (IProperty) selection;
        if (p.getPersistentClass() != null) {
            // use PersistentClass to open editor
            file = OpenMappingUtils.searchFileToOpen(consoleConfig, p.getPersistentClass());
        }
    } else {
        if (selectionParent != null) {
            file = OpenMappingUtils.searchFileToOpen(consoleConfig, selectionParent);
        } else {
            file = OpenMappingUtils.searchFileToOpen(consoleConfig, selection);
        }
    }
    if (file != null) {
        editorPart = OpenMappingUtils.openFileInEditor(file);
        IService service = consoleConfig.getHibernateExtension().getHibernateService();
        boolean updateRes = updateEditorSelection(editorPart, selection, service);
        if (!updateRes && selectionParent != null) {
            // if it is not possible to select object, try to select it's parent
            updateRes = updateEditorSelection(editorPart, selectionParent, service);
        }
    }
    if (editorPart == null) {
        // try to find hibernate-annotations
        IPersistentClass rootClass = null;
        if (selection instanceof IPersistentClass) {
            rootClass = (IPersistentClass) selection;
        } else if (selection instanceof IProperty) {
            IProperty p = (IProperty) selection;
            if (p.getPersistentClass() != null) {
                rootClass = p.getPersistentClass();
            }
        }
        if (rootClass != null) {
            if (OpenMappingUtils.hasConfigXMLMappingClassAnnotation(consoleConfig, rootClass)) {
                String fullyQualifiedName = rootClass.getClassName();
                editorPart = OpenSourceAction.run(consoleConfig, selection, fullyQualifiedName);
            }
        }
    }
    if (editorPart == null) {
        final String title = HibernateConsoleMessages.OpenMappingAction_open_mapping_file;
        final String msg = NLS.bind(HibernateConsoleMessages.OpenMappingAction_mapping_for_not_found, selection);
        MessageDialog.openError(null, title, msg);
        throw new FileNotFoundException(msg);
    }
    return editorPart;
}
Also used : IFile(org.eclipse.core.resources.IFile) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) FileNotFoundException(java.io.FileNotFoundException) IEditorPart(org.eclipse.ui.IEditorPart) IService(org.jboss.tools.hibernate.runtime.spi.IService) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 88 with IProperty

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

the class PersistentClassWorkbenchAdapter method getChildren.

public Object[] getChildren(Object o) {
    IPersistentClass pc = (IPersistentClass) o;
    IProperty identifierProperty = pc.getIdentifierProperty();
    List<IProperty> properties = new ArrayList<IProperty>();
    if (identifierProperty != null) {
        properties.add(identifierProperty);
    }
    Iterator<IProperty> propertyClosureIterator = new JoinedIterator<IProperty>(properties.iterator(), pc.getPropertyClosureIterator());
    return BasicWorkbenchAdapter.toArray(propertyClosureIterator, IProperty.class, null);
}
Also used : IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) ArrayList(java.util.ArrayList) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) JoinedIterator(org.hibernate.eclipse.utils.JoinedIterator)

Example 89 with IProperty

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

the class PropertyWorkbenchAdapter method getLabel.

public String getLabel(Object o) {
    IProperty property = ((IProperty) o);
    IValue value = property.getValue();
    String typeName = (String) (new ValueTypeNameHelper(true).getTypeName(value));
    if (typeName != null) {
        // $NON-NLS-1$
        return property.getName() + " : " + typeName;
    }
    return property.getName();
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty)

Example 90 with IProperty

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

the class TypeVisitor method endVisit.

@Override
public void endVisit(TypeDeclaration node) {
    if (currentType == node && rootClass.getIdentifierProperty() == null) {
        // root class should always has id
        IValue sValue = service.newSimpleValue();
        // $NON-NLS-1$
        sValue.addColumn(service.newColumn("id".toUpperCase()));
        sValue.setTypeName(Long.class.getName());
        IProperty prop = service.newProperty();
        // $NON-NLS-1$
        prop.setName("id");
        prop.setValue(sValue);
        rootClass.setIdentifierProperty(prop);
    }
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty)

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