Search in sources :

Example 1 with NamingStrategy

use of org.hibernate.cfg.NamingStrategy in project jbosstools-hibernate by jbosstools.

the class SchemaExport method main.

public static void main(String[] args) {
    try {
        Configuration cfg = new Configuration();
        boolean script = true;
        boolean drop = false;
        boolean create = false;
        boolean halt = false;
        boolean export = true;
        String outFile = null;
        String importFile = DEFAULT_IMPORT_FILE;
        String propFile = null;
        boolean format = false;
        String delim = null;
        for (int i = 0; i < args.length; i++) {
            if (args[i].startsWith("--")) {
                if (args[i].equals("--quiet")) {
                    script = false;
                } else if (args[i].equals("--drop")) {
                    drop = true;
                } else if (args[i].equals("--create")) {
                    create = true;
                } else if (args[i].equals("--haltonerror")) {
                    halt = true;
                } else if (args[i].equals("--text")) {
                    export = false;
                } else if (args[i].startsWith("--output=")) {
                    outFile = args[i].substring(9);
                } else if (args[i].startsWith("--import=")) {
                    importFile = args[i].substring(9);
                } else if (args[i].startsWith("--properties=")) {
                    propFile = args[i].substring(13);
                } else if (args[i].equals("--format")) {
                    format = true;
                } else if (args[i].startsWith("--delimiter=")) {
                    delim = args[i].substring(12);
                } else if (args[i].startsWith("--config=")) {
                    cfg.configure(args[i].substring(9));
                } else if (args[i].startsWith("--naming=")) {
                    cfg.setNamingStrategy((NamingStrategy) ReflectHelper.classForName(args[i].substring(9)).newInstance());
                }
            } else {
                String filename = args[i];
                if (filename.endsWith(".jar")) {
                    cfg.addJar(new File(filename));
                } else {
                    cfg.addFile(filename);
                }
            }
        }
        if (propFile != null) {
            Properties props = new Properties();
            props.putAll(cfg.getProperties());
            props.load(new FileInputStream(propFile));
            cfg.setProperties(props);
        }
        if (importFile != null) {
            cfg.setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES, importFile);
        }
        StandardServiceRegistryImpl serviceRegistry = createServiceRegistry(cfg.getProperties());
        try {
            SchemaExport se = new SchemaExport(serviceRegistry, cfg).setHaltOnError(halt).setOutputFile(outFile).setDelimiter(delim).setImportSqlCommandExtractor(serviceRegistry.getService(ImportSqlCommandExtractor.class));
            if (format) {
                se.setFormat(true);
            }
            se.execute(script, export, drop, create);
        } finally {
            serviceRegistry.destroy();
        }
    } catch (Exception e) {
        LOG.unableToCreateSchema(e);
        e.printStackTrace();
    }
}
Also used : NamingStrategy(org.hibernate.cfg.NamingStrategy) Configuration(org.hibernate.cfg.Configuration) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) StandardServiceRegistryImpl(org.hibernate.service.internal.StandardServiceRegistryImpl) HibernateException(org.hibernate.HibernateException)

Example 2 with NamingStrategy

use of org.hibernate.cfg.NamingStrategy in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testSetNamingStrategy.

@Test
public void testSetNamingStrategy() {
    NamingStrategy dns = new DefaultNamingStrategy();
    INamingStrategy namingStrategy = FACADE_FACTORY.createNamingStrategy(dns);
    Assert.assertNotSame(dns, configuration.getNamingStrategy());
    configurationFacade.setNamingStrategy(namingStrategy);
    Assert.assertSame(dns, configuration.getNamingStrategy());
}
Also used : NamingStrategy(org.hibernate.cfg.NamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Example 3 with NamingStrategy

use of org.hibernate.cfg.NamingStrategy in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testGetNamingStrategy.

@Test
public void testGetNamingStrategy() {
    NamingStrategy firstStrategy = new DefaultNamingStrategy();
    configuration.setNamingStrategy(firstStrategy);
    INamingStrategy firstStrategyFacade = configurationFacade.getNamingStrategy();
    Assert.assertSame(firstStrategy, ((IFacade) firstStrategyFacade).getTarget());
    NamingStrategy secondStrategy = new DefaultNamingStrategy();
    configuration.setNamingStrategy(secondStrategy);
    INamingStrategy secondStrategyFacade = configurationFacade.getNamingStrategy();
    Assert.assertNotSame(secondStrategy, ((IFacade) secondStrategyFacade).getTarget());
}
Also used : NamingStrategy(org.hibernate.cfg.NamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Example 4 with NamingStrategy

use of org.hibernate.cfg.NamingStrategy in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testSetNamingStrategy.

@Test
public void testSetNamingStrategy() {
    NamingStrategy dns = new DefaultNamingStrategy();
    INamingStrategy namingStrategy = FACADE_FACTORY.createNamingStrategy(dns);
    Assert.assertNotSame(dns, configuration.getNamingStrategy());
    configurationFacade.setNamingStrategy(namingStrategy);
    Assert.assertSame(dns, configuration.getNamingStrategy());
}
Also used : NamingStrategy(org.hibernate.cfg.NamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Example 5 with NamingStrategy

use of org.hibernate.cfg.NamingStrategy in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateNamingStrategy.

@Test
public void testCreateNamingStrategy() {
    NamingStrategy namingStrategy = new DefaultNamingStrategy();
    INamingStrategy facade = facadeFactory.createNamingStrategy(namingStrategy);
    Assert.assertSame(namingStrategy, ((IFacade) facade).getTarget());
}
Also used : DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) NamingStrategy(org.hibernate.cfg.NamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.Test)

Aggregations

NamingStrategy (org.hibernate.cfg.NamingStrategy)10 DefaultNamingStrategy (org.hibernate.cfg.DefaultNamingStrategy)9 INamingStrategy (org.jboss.tools.hibernate.runtime.spi.INamingStrategy)9 Test (org.junit.Test)9 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Properties (java.util.Properties)1 HibernateException (org.hibernate.HibernateException)1 Configuration (org.hibernate.cfg.Configuration)1 StandardServiceRegistryImpl (org.hibernate.service.internal.StandardServiceRegistryImpl)1