Search in sources :

Example 21 with IConfiguration

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

the class ElementsFactory method getOrCreateDatabaseTable.

@SuppressWarnings("rawtypes")
protected OrmShape getOrCreateDatabaseTable(ITable databaseTable) {
    OrmShape tableShape = null;
    if (databaseTable != null) {
        tableShape = getShape(databaseTable);
        if (tableShape == null) {
            tableShape = createShape(databaseTable);
            final IConfiguration config = getConfig();
            if (config != null) {
                Iterator iterator = config.getClassMappings();
                while (iterator.hasNext()) {
                    Object clazz = iterator.next();
                    if (clazz instanceof IPersistentClass && ((IPersistentClass) clazz).isInstanceOfRootClass()) {
                        IPersistentClass cls = (IPersistentClass) clazz;
                        if (databaseTable.equals(cls.getTable())) {
                            // create persistent class shape only for RootClass,
                            // which has same table reference
                            getOrCreatePersistentClass(cls, null);
                        }
                    }
                }
            }
        }
    }
    return tableShape;
}
Also used : Iterator(java.util.Iterator) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 22 with IConfiguration

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

the class OrmDiagram method recreateChildren.

public void recreateChildren() {
    deleteChildren();
    elements.clear();
    connections.clear();
    StringBuilder errorMessage = new StringBuilder();
    IConfiguration config = getConfig(errorMessage);
    final ElementsFactory factory = new ElementsFactory(consoleConfigName, elements, connections);
    for (int i = 0; i < roots.size(); i++) {
        IPersistentClass rc = roots.get(i);
        if (rc != null) {
            factory.getOrCreatePersistentClass(rc, null);
        }
    }
    updateChildrenList();
    factory.createChildren(this);
    factory.createForeingKeyConnections();
    updateChildrenList();
    if (getChildrenNumber() == 0) {
        String error = DiagramViewerMessages.MessageShape_warning;
        if (config != null) {
            if (consoleConfigName != null && consoleConfigName.length() > 0) {
                error = consoleConfigName;
                // $NON-NLS-1$
                error += ": ";
                error += DiagramViewerMessages.Diagram_no_items_or_incorrect_state;
            }
        }
        if (errorMessage.length() > 0) {
            error = errorMessage.toString();
        }
        addChild(new MessageShape(error, getConsoleConfigName()));
    }
}
Also used : IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Point(org.eclipse.draw2d.geometry.Point) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 23 with IConfiguration

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

the class OpenDiagramActionDelegate method run.

public void run(IAction action) {
    ObjectPluginAction objectPluginAction = (ObjectPluginAction) action;
    Map<ConsoleConfiguration, Set<IPersistentClass>> mapCC_PCs = new HashMap<ConsoleConfiguration, Set<IPersistentClass>>();
    TreePath[] paths = ((TreeSelection) objectPluginAction.getSelection()).getPaths();
    for (int i = 0; i < paths.length; i++) {
        final Object firstSegment = paths[i].getFirstSegment();
        if (!(firstSegment instanceof ConsoleConfiguration)) {
            continue;
        }
        final ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (firstSegment);
        Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfig);
        if (null == setPC) {
            setPC = new HashSet<IPersistentClass>();
            mapCC_PCs.put(consoleConfig, setPC);
        }
        Object last_el = paths[i].getLastSegment();
        if (last_el instanceof IPersistentClass) {
            IPersistentClass persClass = (IPersistentClass) last_el;
            setPC.add(persClass);
        } else if (last_el instanceof IConfiguration) {
            IConfiguration config = (IConfiguration) last_el;
            Iterator<IPersistentClass> it = config.getClassMappings();
            while (it.hasNext()) {
                setPC.add(it.next());
            }
        } else if (last_el instanceof ConsoleConfiguration) {
            IConfiguration config = consoleConfig.getConfiguration();
            if (config == null) {
                try {
                    consoleConfig.build();
                } catch (Exception he) {
                    HibernateConsolePlugin.getDefault().showError(HibernateConsolePlugin.getShell(), DiagramViewerMessages.OpenDiagramActionDelegate_could_not_load_configuration + ' ' + consoleConfig.getName(), he);
                }
                if (consoleConfig.hasConfiguration()) {
                    consoleConfig.buildMappings();
                }
                config = consoleConfig.getConfiguration();
            }
            if (config != null) {
                Iterator<IPersistentClass> it = config.getClassMappings();
                while (it.hasNext()) {
                    setPC.add(it.next());
                }
            }
        }
    }
    for (Iterator<ConsoleConfiguration> it = mapCC_PCs.keySet().iterator(); it.hasNext(); ) {
        ConsoleConfiguration consoleConfiguration = it.next();
        Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfiguration);
        try {
            openEditor(setPC, consoleConfiguration);
        } catch (PartInitException e) {
            // $NON-NLS-1$
            HibernateConsolePlugin.getDefault().logErrorMessage("Can't open mapping view.", e);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PartInitException(org.eclipse.ui.PartInitException) ObjectPluginAction(org.eclipse.ui.internal.ObjectPluginAction) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) PartInitException(org.eclipse.ui.PartInitException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 24 with IConfiguration

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

the class OrmLabelProvider method updateColumnSqlType.

/**
 * For correct label creation should update column sql type.
 * @param column
 * @return
 */
public boolean updateColumnSqlType(final IColumn column) {
    String sqlType = column.getSqlType();
    if (sqlType != null) {
        return false;
    }
    final IConfiguration config = getConfig();
    if (config != null) {
        final ConsoleConfiguration consoleConfig = getConsoleConfig();
        try {
            sqlType = (String) consoleConfig.execute(new ExecutionContext.Command() {

                public Object execute() {
                    return column.getSqlType(config);
                }
            });
        } catch (Exception e) {
            // do not ignore it - print in Error Log
            // $NON-NLS-1$
            HibernateConsolePlugin.getDefault().logErrorMessage("Exception: ", e);
        }
    }
    if (sqlType != null) {
        column.setSqlType(sqlType);
        return true;
    }
    return false;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ExecutionContext(org.hibernate.console.execution.ExecutionContext) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 25 with IConfiguration

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

the class WripperException method testHbmExportExceptionTest.

public void testHbmExportExceptionTest() throws Exception {
    try {
        Object[] persClassesInit = getPersistenceClasses(false);
        final ConsoleConfiguration consCFG = getConsoleConfig();
        IConfiguration config = consCFG.getConfiguration();
        // delete old hbm files
        assertNotNull(testPackage);
        int nDeleted = 0;
        if (testPackage.getNonJavaResources().length > 0) {
            Object[] ress = testPackage.getNonJavaResources();
            for (int i = 0; i < ress.length; i++) {
                if (ress[i] instanceof IFile) {
                    IFile res = (IFile) ress[i];
                    if (res.getName().endsWith(".hbm.xml")) {
                        // $NON-NLS-1$
                        res.delete(true, false, null);
                        nDeleted++;
                    }
                }
            }
        }
        IHibernateMappingExporter hce = service.newHibernateMappingExporter(config, getSrcFolder());
        try {
            hce.start();
            IArtifactCollector collector = service.newArtifactCollector();
            collector.formatFiles();
            try {
                // build generated configuration
                testPackage.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
                testPackage.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
                ConsoleConfigUtils.customizeCfgXmlForPack(testPackage);
                assertNotNull(consCFG);
                consCFG.reset();
                consCFG.build();
                assertTrue(consCFG.hasConfiguration());
                consCFG.getConfiguration().buildMappings();
                config = consCFG.getConfiguration();
            } catch (CoreException e) {
                String out = NLS.bind(ConsoleTestMessages.UpdateConfigurationTest_error_customising_file_for_package, new Object[] { ConsoleConfigUtils.CFG_FILE_NAME, testPackage.getPath(), e.getMessage() });
                fail(out);
            }
        } catch (Exception e) {
            throw (Exception) e.getCause();
        }
        // 
        Object[] persClassesReInit = getPersistenceClasses(false);
        // 
        int nCreated = 0;
        if (testPackage.getNonJavaResources().length > 0) {
            Object[] ress = testPackage.getNonJavaResources();
            for (int i = 0; i < ress.length; i++) {
                if (ress[i] instanceof IFile) {
                    IFile res = (IFile) ress[i];
                    if (res.getName().endsWith(".hbm.xml")) {
                        // $NON-NLS-1$
                        nCreated++;
                    }
                }
            }
        }
        // 
        assertTrue(persClassesInit.length == persClassesReInit.length);
        assertTrue(nCreated > 0);
        assertTrue(nDeleted >= 0 && persClassesInit.length > 0);
        assertTrue(nCreated <= persClassesInit.length);
    } catch (Exception e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        String newMessage = "\nPackage " + testPackage.getElementName() + ":";
        throw new WripperException(newMessage, e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IFile(org.eclipse.core.resources.IFile) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Aggregations

IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)137 Test (org.junit.Test)72 Configuration (org.hibernate.cfg.Configuration)65 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)29 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)25 File (java.io.File)19 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)17 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)16 Properties (java.util.Properties)13 CoreException (org.eclipse.core.runtime.CoreException)10 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)10 IJDBCReader (org.jboss.tools.hibernate.runtime.spi.IJDBCReader)9 FileWriter (java.io.FileWriter)8 IOException (java.io.IOException)8 JDBCReader (org.hibernate.cfg.reveng.JDBCReader)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)7 PartInitException (org.eclipse.ui.PartInitException)7 Ejb3Configuration (org.hibernate.ejb.Ejb3Configuration)7