Package org.hibernate.tool.hbm2ddl

Examples of org.hibernate.tool.hbm2ddl.SchemaExport


   public void init( )
      throws HibernateException
   {
      Configuration cfg = new Configuration().configure();
      SchemaExport se = new SchemaExport(cfg);
      se.create(true, true);
   }
View Full Code Here


  protected void prepareTest() throws Exception {
    super.prepareTest();
    Connection conn = cp.getConnection();
    try {
      new SchemaExport( getCfg(), conn ).create( false, true );
    }
    finally {
      if ( conn != null ) {
        try {
          cp.closeConnection( conn );
View Full Code Here

  }

  protected void cleanupTest() throws Exception {
    Connection conn = cp.getConnection();
    try {
      new SchemaExport( getCfg(), conn ).drop( false, true );
    }
    finally {
      if ( conn != null ) {
        try {
          cp.closeConnection( conn );
View Full Code Here

 
  public void testSchemaTools() throws Exception{
    // database schema have been created thanks to the setUp method
    // we have 2 schemas SA et SB, SB must be set as the default schema
    // used by hibernate hibernate.default_schema SB
    SchemaExport se = new SchemaExport(getCfg());
    se.create(true,true);
   
    // here we modify the generated table in order to test SchemaUpdate
    Session session = openSession();
    Connection conn = session.connection();
    Statement stat = conn.createStatement();
    stat.execute("ALTER TABLE \"SB\".\"Team\" DROP COLUMN name ");
   
    // update schema
    SchemaUpdate su = new SchemaUpdate(getCfg());
    su.execute(true,true);
   
    // we can run schema validation. Note that in the setUp method a *wrong* table
    // has been created with different column names
    // if schema validator chooses the bad db schema, then the testcase will fail (exception)
    SchemaValidator sv = new SchemaValidator(getCfg());
    sv.validate();
   
    // it's time to clean our database
    se.drop(true,true);
   
    // then the schemas and false table.

    stat.execute("DROP TABLE \"SA\".\"Team\" ");
    stat.execute(" DROP SCHEMA sa ");
View Full Code Here

 
  public void testSchemaToolsNonQuote() throws Exception{
    // database schema have been created thanks to the setUp method
    // we have 2 schemas SA et SB, SB must be set as the default schema
    // used by hibernate hibernate.default_schema SB
    SchemaExport se = new SchemaExport(getCfg());
    se.create(true,true);
   
    // here we modify the generated table in order to test SchemaUpdate
    Session session = openSession();
    Connection conn = session.connection();
    Statement stat = conn.createStatement();
    stat.execute("ALTER TABLE \"SB\".\"TEAM\" DROP COLUMN xname ");
   
    // update schema
    SchemaUpdate su = new SchemaUpdate(getCfg());
    su.execute(true,true);
   
    // we can run schema validation. Note that in the setUp method a *wrong* table
    // has been created with different column names
    // if schema validator chooses the bad db schema, then the testcase will fail (exception)
    SchemaValidator sv = new SchemaValidator(getCfg());
    sv.validate();
   
    // it's time to clean our database
    se.drop(true,true);
   
    // then the schemas and false table.

    stat.execute("DROP TABLE \"SA\".\"Team\" ");
    stat.execute(" DROP SCHEMA sa ");
View Full Code Here

  }
  public void testFailingQuoteValidation() throws Exception{
    // database schema have been created thanks to the setUp method
    // we have 2 schemas SA et SB, SB must be set as the default schema
    // used by hibernate hibernate.default_schema SB
    SchemaExport se = new SchemaExport(getCfg());
    se.create(true,true);
   
    // here we modify the generated table in order to test SchemaUpdate
    Session session = openSession();
    Connection conn = session.connection();
    Statement stat = conn.createStatement();
    stat.execute("ALTER TABLE \"SB\".\"Team\" DROP COLUMN name ");
   
    // update schema
    //SchemaUpdate su = new SchemaUpdate(getCfg());
    //su.execute(true,true);
   
    try {
      SchemaValidator sv = new SchemaValidator(getCfg());
      sv.validate();
      fail("should fail since we mutated the current schema.");
    } catch(HibernateException he) {
     
    }
   
    // it's time to clean our database
    se.drop(true,true);
   
    // then the schemas and false table.

    stat.execute("DROP TABLE \"SA\".\"Team\" ");
    stat.execute(" DROP SCHEMA sa ");
View Full Code Here

  public void testFailingNonQuoteValidation() throws Exception{
    // database schema have been created thanks to the setUp method
    // we have 2 schemas SA et SB, SB must be set as the default schema
    // used by hibernate hibernate.default_schema SB
    SchemaExport se = new SchemaExport(getCfg());
    se.create(true,true);
   
    // here we modify the generated table in order to test SchemaUpdate
    Session session = openSession();
    Connection conn = session.connection();
    Statement stat = conn.createStatement();
    stat.execute("ALTER TABLE \"SB\".\"TEAM\" DROP COLUMN xname ");
   
    // update schema
    //SchemaUpdate su = new SchemaUpdate(getCfg());
    //su.execute(true,true);
   
    try {
      SchemaValidator sv = new SchemaValidator(getCfg());
      sv.validate();
      fail("should fail since we mutated the current schema.");
    } catch(HibernateException he) {
     
    }
   
    // it's time to clean our database
    se.drop(true,true);
   
    // then the schemas and false table.

    stat.execute("DROP TABLE \"SA\".\"Team\" ");
    stat.execute(" DROP SCHEMA sa ");
View Full Code Here

    String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml";
    String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml";

    Configuration v1cfg = new Configuration();
    v1cfg.addResource( resource1 );
    new SchemaExport( v1cfg ).execute( false, true, true, false );

    SchemaUpdate v1schemaUpdate = new SchemaUpdate( v1cfg );
    v1schemaUpdate.execute( true, true );

    assertEquals( 0, v1schemaUpdate.getExceptions().size() );

    Configuration v2cfg = new Configuration();
    v2cfg.addResource( resource2 );

    SchemaUpdate v2schemaUpdate = new SchemaUpdate( v2cfg );
    v2schemaUpdate.execute( true, true );
    assertEquals( 0, v2schemaUpdate.getExceptions().size() );
   
    new SchemaExport( v2cfg ).drop( false, true );

  }
View Full Code Here

   public void init( )
      throws HibernateException
   {
      Configuration cfg = new Configuration().configure();
      SchemaExport se = new SchemaExport(cfg);
      se.create(true, true);
   }
View Full Code Here

  public static synchronized void clearDatabase() {
    closeSession();
    clearHibernateCache();
    sessionFactory = null;
    try {
      new SchemaExport(new org.hibernate.cfg.Configuration().configure(hibernateParams)).create(false, true);
    } catch (Exception e) {
      logger.error("Failed to clear database because of an exception", e);
    }
  }
View Full Code Here

TOP

Related Classes of org.hibernate.tool.hbm2ddl.SchemaExport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.