Search in sources :

Example 11 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 12 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class OrmLabelProvider method getConsoleConfig.

protected ConsoleConfiguration getConsoleConfig() {
    final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
    ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
    return consoleConfig;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) KnownConfigurations(org.hibernate.console.KnownConfigurations)

Example 13 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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)

Example 14 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class BaseTestSetCase method getPersistenceClasses.

public Object[] getPersistenceClasses(boolean resetCC) {
    final ConsoleConfiguration consCFG = getConsoleConfig();
    if (resetCC) {
        consCFG.reset();
        consCFG.build();
    }
    assertTrue(consCFG.hasConfiguration());
    if (resetCC) {
        consCFG.buildMappings();
    }
    Object[] configs = null;
    Object[] persClasses = null;
    try {
        configs = ccWorkbenchAdapter.getChildren(consCFG);
        assertNotNull(configs);
        assertEquals(3, configs.length);
        assertTrue(configs[0] instanceof IConfiguration);
        persClasses = configWorkbenchAdapter.getChildren(configs[0]);
    } catch (Exception ex) {
        String out = NLS.bind(ConsoleTestMessages.OpenMappingDiagramTest_mapping_diagrams_for_package_cannot_be_opened, new Object[] { testPackage.getElementName(), ex.getMessage() });
        fail(out);
    }
    return persClasses;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 15 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class BaseTestSetCase method getConsoleConfig.

public ConsoleConfiguration getConsoleConfig() {
    KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
    final ConsoleConfiguration consCFG = knownConfigurations.find(consoleConfigName);
    assertNotNull(consCFG);
    return consCFG;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) KnownConfigurations(org.hibernate.console.KnownConfigurations)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6