List of usage examples for org.hibernate.tool.hbm2ddl SchemaExport create
public void create(EnumSet<TargetType> targetTypes, Metadata metadata)
From source file:gov.nih.nci.cabig.ctms.acegi.csm.AbstractCSMTestCase.java
License:BSD License
public void setUp() throws Exception { Configuration cfg = new Configuration().configure(new File("src/test/resources/hibernate.cfg.xml")); SchemaExport se = new SchemaExport(cfg); try {//from w ww . j a v a 2 s . c o m se.drop(false, true); } catch (Exception ex) { } se.create(false, true); super.setUp(); }
From source file:hib.TableCreater.java
public static void main(String[] args) { Configuration cfg = new Configuration(); //cfg.addAnnotatedClass(table.MiniProject.class); //cfg.addAnnotatedClass(table.Employee.class); //cfg.addAnnotatedClass(table.MajorProject.class); //cfg.addAnnotatedClass(table.LiveProject.class); //cfg.addAnnotatedClass(table.Candidate.class); cfg.addAnnotatedClass(Table.User.class); //cfg.addAnnotatedClass(Table.Profile.class); cfg.configure();//from w w w . j av a2s. c o m SchemaExport se = new SchemaExport(cfg); se.create(true, true); System.out.println("TABLE CREATED!!"); }
From source file:modelo.utils.HibernateUtil.java
License:Apache License
/** * Mtodo main que inicializa a configurao do nosso hibernateUtil. * @param args// w w w . ja v a2 s . c om */ public static void main(String[] args) { System.out.println("Inicio"); Configuration cfg = new Configuration(); cfg.configure(); SchemaExport se = new SchemaExport(cfg); se.create(true, true); System.out.println("Fim"); }
From source file:net.commerce.zocalo.hibernate.HibernateSingletonTest.java
License:Open Source License
public void xtestSchemaUpdate() { Configuration config = new Configuration(); HibernateTestUtil.addClasses(config); SchemaExport export = new SchemaExport(config); export.create(true, false); assertEquals(0, export.getExceptions().size()); }
From source file:nl.strohalm.cyclos.setup.CreateDataBase.java
License:Open Source License
/** * Create the database//from w w w . j a v a 2 s . c o m */ public void run() { Setup.out.println(bundle.getString("create-database.start")); final SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.create(false, true); Setup.out.println(bundle.getString("create-database.end")); }
From source file:nl.strohalm.cyclos.setup.ExportScript.java
License:Open Source License
/** * Export the script for creating the database *///from w w w .j a v a 2 s .c o m public void run() { if (!exportTo.isAbsolute()) { exportTo = new File(SystemUtils.getUserDir(), exportTo.getPath()); } // Resolve the file name if (exportTo.isDirectory()) { exportTo = new File(exportTo, "cyclos.ddl"); } // Create the directory if needed final File dir = exportTo.getParentFile(); if (!dir.exists()) { if (!dir.mkdirs()) { throw new IllegalStateException("Could not create directory: " + dir); } } final String fileName = exportTo.getAbsolutePath(); Setup.out.println(bundle.getString("export-script.start")); final SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.setDelimiter(";"); schemaExport.setOutputFile(fileName); schemaExport.create(true, false); Setup.out.println(bundle.getString("export-script.end") + " " + fileName); }
From source file:org.codehaus.mojo.hibernate3.exporter.Hbm2DDLExporterMojo.java
License:Apache License
/** * Overrides the default implementation of executing this goal. * * @throws MojoExecutionException if there is an error executing the goal *///from w w w . j a va2 s .co m protected void doExecute() throws MojoExecutionException { boolean scriptToConsole = getComponentProperty("console", true); boolean exportToDatabase = getComponentProperty("export", true); boolean haltOnError = getComponentProperty("haltonerror", false); boolean drop = getComponentProperty("drop", false); boolean create = getComponentProperty("create", true); String implementation = getComponentProperty("implementation", getComponent().getImplementation()); Configuration configuration = getComponentConfiguration(implementation).getConfiguration(this); if (getComponentProperty("update", false)) { SchemaUpdate update = new SchemaUpdate(configuration); update.execute(scriptToConsole, exportToDatabase); } else { SchemaExport export = new SchemaExport(configuration); export.setDelimiter(getComponentProperty("delimiter", ";")); export.setHaltOnError(haltOnError); export.setFormat(getComponentProperty("format", false)); String outputFilename = getComponentProperty("outputfilename"); if (outputFilename != null) { File outputFile = HibernateUtils.prepareFile( new File(getProject().getBasedir(), getComponent().getOutputDirectory()), outputFilename, "outputfilename"); export.setOutputFile(outputFile.toString()); } if (drop && create) { export.create(scriptToConsole, exportToDatabase); } else { export.execute(scriptToConsole, exportToDatabase, drop, create); } if (export.getExceptions().size() > 0) { Iterator iterator = export.getExceptions().iterator(); int cnt = 1; getLog().warn(export.getExceptions().size() + " errors occurred while performing <hbm2ddl>."); while (iterator.hasNext()) { getLog().error("Error #" + cnt + ": " + iterator.next().toString()); } if (haltOnError) { throw new MojoExecutionException("Errors while performing <hbm2ddl>"); } } } }
From source file:org.eclipsetrader.repository.hibernate.HibernateRepository.java
License:Open Source License
public void startUp(IProgressMonitor monitor) { properties.put("hibernate.query.factory_class", "org.hibernate.hql.classic.ClassicQueryTranslatorFactory"); properties.put("hibernate.connection.pool_size", "5"); properties.put("hibernate.jdbc.batch_size", "20"); properties.put("hibernate.show_sql", "false"); // Build suitable defaults for file-based databases (Apache Derby and HSQL) if (!properties.containsKey("hibernate.connection.url") && Activator.getDefault() != null) { if ("org.apache.derby.jdbc.EmbeddedDriver" .equals(properties.get("hibernate.connection.driver_class"))) { properties.put("hibernate.connection.url", "jdbc:derby:" + Activator.getDefault().getStateLocation().toOSString() + "/.derby;create=true"); }/*from w w w .j a va2 s . c o m*/ if ("org.hsqldb.jdbcDriver".equals(properties.get("hibernate.connection.driver_class"))) { properties.put("hibernate.connection.url", "jdbc:hsqldb:file:" + Activator.getDefault().getStateLocation().toOSString() + "/.hsqldb"); } } AnnotationConfiguration cfg = buildConfiguration(); try { initializeDatabase(cfg); } catch (Exception e) { String message = NLS.bind("Error initializing repository '{1}' ({0})", new Object[] { schema, name }); Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, message, e); Activator.log(status); int userChoice = new RepositoryValidator(name, cfg).validate(); switch (userChoice) { case RepositoryValidator.UPDATE_ID: SchemaUpdate schemaUpdate = new SchemaUpdate(cfg); schemaUpdate.execute(true, true); if (schemaUpdate.getExceptions().size() != 0) { MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 0, new IStatus[0], ERROR_MESSAGE, null); for (Object o : schemaUpdate.getExceptions()) { multiStatus.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, null, (Exception) o)); } Activator.log(multiStatus); } break; case RepositoryValidator.CREATE_ID: SchemaExport schemaExport = new SchemaExport(cfg); schemaExport.create(true, true); if (schemaExport.getExceptions().size() != 0) { MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 0, new IStatus[0], ERROR_MESSAGE, null); for (Object o : schemaExport.getExceptions()) { multiStatus.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, null, (Exception) o)); } Activator.log(multiStatus); } break; } } initializeDatabase(cfg); }
From source file:org.evolizer.core.hibernate.session.EvolizerSessionHandler.java
License:Apache License
/** * Creates the database schema based on the o/r mappings (e.g. the Hibernate/ejb3-annotations). Can only be executed * when session is closed./*from w w w .j a v a 2 s .com*/ * * @param properties Database connection properties * @throws EvolizerException */ public void createSchema(Properties properties) throws EvolizerException { try { AnnotationConfiguration configuration = configureDataBaseConnection(properties); SchemaExport exporter = new SchemaExport(configuration); exporter.create(false, true); } catch (HibernateException he) { throw new EvolizerException(he); } }
From source file:org.geolatte.common.cql.hibernate.HibernateUtil.java
License:Open Source License
public void createDatabase() { SchemaExport e = new SchemaExport(configuration); e.drop(true, true); e.create(true, true); }