Example usage for org.hibernate.boot MetadataSources addPackage

List of usage examples for org.hibernate.boot MetadataSources addPackage

Introduction

In this page you can find the example usage for org.hibernate.boot MetadataSources addPackage.

Prototype

public MetadataSources addPackage(Package packageRef) 

Source Link

Document

Read package-level metadata.

Usage

From source file:com.evolveum.midpoint.repo.sql.SchemaTest.java

License:Apache License

private void createSQLSchema(String fileName, String dialect) {
    File file = new File(fileName);
    if (file.exists()) {
        file.delete();//  w w  w. j  a v a 2  s .c  o  m
    }

    MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder()
            .applySetting("hibernate.implicit_naming_strategy", new MidPointImplicitNamingStrategy())
            .applySetting("hibernate.physical_naming_strategy", new MidPointPhysicalNamingStrategy())
            .applySetting("hibernate.dialect", dialect).build());

    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common", metadata);
    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.container", metadata);
    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.any", metadata);
    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.embedded", metadata);
    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.enums", metadata);
    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.id", metadata);
    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.other", metadata);
    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.type", metadata);
    addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.audit", metadata);

    metadata.addPackage("com.evolveum.midpoint.repo.sql.type");

    SchemaExport export = new SchemaExport();
    export.setOutputFile(fileName);
    export.setDelimiter(";");
    //        export.setFormat(true);
    export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata.buildMetadata());
}

From source file:org.unitedinternet.cosmo.db.DbInitializer.java

License:Apache License

/**
 * Schema validation//from  w  ww . j  a va2s .  c  o  m
 */
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;
    }
}