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();
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations