Search in sources :

Example 26 with ISchemaExport

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

the class FacadeFactoryTest method testCreateSchemaExport.

@Test
public void testCreateSchemaExport() {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    SchemaExport schemaExport = new SchemaExport();
    ISchemaExport facade = facadeFactory.createSchemaExport(schemaExport);
    Assert.assertTrue(facade instanceof SchemaExportFacadeImpl);
    Assert.assertSame(schemaExport, ((IFacade) facade).getTarget());
}
Also used : IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Configuration(org.hibernate.cfg.Configuration) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 27 with ISchemaExport

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

the class SchemaExportFacadeTest method testGetExceptions.

@SuppressWarnings("unchecked")
@Test
public void testGetExceptions() throws Throwable {
    SchemaExport schemaExport = new SchemaExport();
    ISchemaExport schemaExportFacade = new SchemaExportFacadeImpl(FACADE_FACTORY, schemaExport);
    Assert.assertTrue(schemaExportFacade.getExceptions().isEmpty());
    schemaExport.getExceptions().add(new HibernateException("blah"));
    Assert.assertFalse(schemaExportFacade.getExceptions().isEmpty());
}
Also used : HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 28 with ISchemaExport

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

the class FacadeFactoryTest method testCreateSchemaExport.

@Test
public void testCreateSchemaExport() {
    SchemaExport schemaExport = new SchemaExport();
    ISchemaExport facade = facadeFactory.createSchemaExport(schemaExport);
    Assert.assertTrue(facade instanceof SchemaExportFacadeImpl);
    Assert.assertSame(schemaExport, ((IFacade) facade).getTarget());
}
Also used : ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 29 with ISchemaExport

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

the class ServiceImplTest method testNewSchemaExport.

@Test
public void testNewSchemaExport() {
    IConfiguration configuration = service.newDefaultConfiguration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    ISchemaExport schemaExport = service.newSchemaExport(configuration);
    Assert.assertNotNull(schemaExport);
}
Also used : ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Test(org.junit.Test)

Example 30 with ISchemaExport

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

the class SchemaExportAction method doRun.

public void doRun() {
    for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext(); ) {
        Object node = i.next();
        if (!(node instanceof ConsoleConfiguration)) {
            continue;
        }
        final ConsoleConfiguration config = (ConsoleConfiguration) node;
        try {
            config.execute(new Command() {

                public Object execute() {
                    final IConfiguration cfg = config.getConfiguration();
                    if (cfg == null) {
                        return null;
                    }
                    String out = NLS.bind(HibernateConsoleMessages.SchemaExportAction_sure_run_schemaexport, config.getName());
                    boolean res = openWarningYesNoDlg(viewer.getControl().getShell(), HibernateConsoleMessages.SchemaExportAction_run_schemaexport, out);
                    if (!res) {
                        return null;
                    }
                    IService service = config.getHibernateExtension().getHibernateService();
                    ISchemaExport export = service.newSchemaExport(cfg);
                    export.create();
                    if (!export.getExceptions().isEmpty()) {
                        Iterator<Throwable> iterator = export.getExceptions().iterator();
                        int cnt = 1;
                        while (iterator.hasNext()) {
                            Throwable element = iterator.next();
                            String outStr = NLS.bind(HibernateConsoleMessages.SchemaExportAction_errornum_while_performing_schemaexport, cnt++);
                            HibernateConsolePlugin.getDefault().logErrorMessage(outStr, element);
                        }
                        HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), NLS.bind(HibernateConsoleMessages.SchemaExportAction_error_while_performing_schemaexport, cnt - 1), (Throwable) null);
                    }
                    return null;
                }
            });
            // todo: should we do it here or should
            viewer.refresh(node);
        // the view just react to config being
        // build ?
        } catch (Exception he) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.SchemaExportAction_exception_running_schemaexport, he);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Command(org.hibernate.console.execution.ExecutionContext.Command) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) Iterator(java.util.Iterator) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Aggregations

ISchemaExport (org.jboss.tools.hibernate.runtime.spi.ISchemaExport)30 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)25 Test (org.junit.Test)24 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)13 Configuration (org.hibernate.cfg.Configuration)8 Connection (java.sql.Connection)5 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)3 HibernateException (org.jboss.tools.hibernate.runtime.spi.HibernateException)3 Iterator (java.util.Iterator)1 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)1 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)1 Command (org.hibernate.console.execution.ExecutionContext.Command)1 IService (org.jboss.tools.hibernate.runtime.spi.IService)1