当前位置: 首页>>代码示例>>Java>>正文


Java SchemaValidator类代码示例

本文整理汇总了Java中org.hibernate.tool.hbm2ddl.SchemaValidator的典型用法代码示例。如果您正苦于以下问题:Java SchemaValidator类的具体用法?Java SchemaValidator怎么用?Java SchemaValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SchemaValidator类属于org.hibernate.tool.hbm2ddl包,在下文中一共展示了SchemaValidator类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSchemaTools

import org.hibernate.tool.hbm2ddl.SchemaValidator; //导入依赖的package包/类
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 ");
	stat.execute("DROP SCHEMA sb ");
	stat.close();
	session.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:35,代码来源:TestSchemaTools.java

示例2: testSchemaToolsNonQuote

import org.hibernate.tool.hbm2ddl.SchemaValidator; //导入依赖的package包/类
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 ");
	stat.execute("DROP SCHEMA sb ");
	stat.close();
	session.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:35,代码来源:TestSchemaTools.java

示例3: testFailingQuoteValidation

import org.hibernate.tool.hbm2ddl.SchemaValidator; //导入依赖的package包/类
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 ");
	stat.execute("DROP SCHEMA sb ");
	stat.close();
	session.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:37,代码来源:TestSchemaTools.java

示例4: testFailingNonQuoteValidation

import org.hibernate.tool.hbm2ddl.SchemaValidator; //导入依赖的package包/类
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 ");
	stat.execute("DROP SCHEMA sb ");
	stat.close();
	session.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:37,代码来源:TestSchemaTools.java

示例5: validateSchema

import org.hibernate.tool.hbm2ddl.SchemaValidator; //导入依赖的package包/类
/**
 * Schema validation
 */
private void validateSchema() {
    try {
        StandardServiceRegistry registry = localSessionFactory.getConfiguration()
                .getStandardServiceRegistryBuilder().build();
        MetadataSources sources = new MetadataSources(registry);
        sources.addPackage("org.unitedinternet.cosmo.model.hibernate");
        Metadata metadata = sources.buildMetadata(registry);
        new SchemaValidator().validate(metadata);
        LOG.info("schema validation passed");
    } catch (HibernateException e) {
        LOG.error("error validating schema", e);
        throw e;
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:18,代码来源:DbInitializer.java

示例6: execute

import org.hibernate.tool.hbm2ddl.SchemaValidator; //导入依赖的package包/类
public static void execute(Dialect dialect, Class<?>... classes) {
    Configuration configuration = new Configuration();
    SchemaExport schemaExport = new SchemaExport(configuration);
    SchemaUpdate schemaUpdate = new SchemaUpdate(configuration);
    try {
        new SchemaValidator(configuration).validate();
    }
    catch (Exception e) {
        logger.error("Failed create the table: " + e.getMessage());
    }
}
 
开发者ID:windup,项目名称:windup-rulesets,代码行数:12,代码来源:SchemaDDLGenerator.java


注:本文中的org.hibernate.tool.hbm2ddl.SchemaValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。