Search in sources :

Example 1 with Database

use of org.hibernate.boot.model.relational.Database in project hibernate-orm by hibernate.

the class Ejb3Column method addColumnBinding.

protected void addColumnBinding(SimpleValue value) {
    final String logicalColumnName;
    if (StringHelper.isNotEmpty(this.logicalColumnName)) {
        logicalColumnName = this.logicalColumnName;
    } else {
        final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
        final Database database = context.getMetadataCollector().getDatabase();
        final ImplicitNamingStrategy implicitNamingStrategy = context.getBuildingOptions().getImplicitNamingStrategy();
        final Identifier implicitName = normalizer.normalizeIdentifierQuoting(implicitNamingStrategy.determineBasicColumnName(new ImplicitBasicColumnNameSource() {

            @Override
            public AttributePath getAttributePath() {
                return AttributePath.parse(propertyName);
            }

            @Override
            public boolean isCollectionElement() {
                return false;
            }

            @Override
            public MetadataBuildingContext getBuildingContext() {
                return context;
            }
        }));
        logicalColumnName = implicitName.render(database.getDialect());
    }
    context.getMetadataCollector().addColumnNameBinding(value.getTable(), logicalColumnName, getMappingColumn());
}
Also used : ImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategy) Identifier(org.hibernate.boot.model.naming.Identifier) Database(org.hibernate.boot.model.relational.Database) ObjectNameNormalizer(org.hibernate.boot.model.naming.ObjectNameNormalizer) ImplicitBasicColumnNameSource(org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource)

Example 2 with Database

use of org.hibernate.boot.model.relational.Database in project hibernate-orm by hibernate.

the class SchemaUpdateTableBackedSequenceTest method testCreateTableOnUpdate.

@Test
public void testCreateTableOnUpdate() throws SQLException {
    Metadata metadata = new MetadataSources(ssr).buildMetadata();
    Database database = metadata.getDatabase();
    TableStructure tableStructure = new TableStructure(database.getJdbcEnvironment(), new QualifiedTableName(null, null, Identifier.toIdentifier("test_seq")), Identifier.toIdentifier("nextval"), 20, 30, Long.class);
    tableStructure.registerExportables(database);
    // lets make sure the InitCommand is there
    assertEquals(1, database.getDefaultNamespace().getTables().size());
    Table table = database.getDefaultNamespace().getTables().iterator().next();
    assertEquals(1, table.getInitCommands().size());
    final TargetImpl target = new TargetImpl();
    ssr.getService(SchemaManagementTool.class).getSchemaMigrator(Collections.emptyMap()).doMigration(metadata, new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return ssr.getService(ConfigurationService.class).getSettings();
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }
    }, new TargetDescriptor() {

        @Override
        public EnumSet<TargetType> getTargetTypes() {
            return EnumSet.of(TargetType.SCRIPT, TargetType.DATABASE);
        }

        @Override
        public ScriptTargetOutput getScriptTargetOutput() {
            return target;
        }
    });
    assertTrue(target.found);
    new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
Also used : QualifiedTableName(org.hibernate.boot.model.relational.QualifiedTableName) Table(org.hibernate.mapping.Table) EnumSet(java.util.EnumSet) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) TargetDescriptor(org.hibernate.tool.schema.spi.TargetDescriptor) ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) TableStructure(org.hibernate.id.enhanced.TableStructure) Database(org.hibernate.boot.model.relational.Database) ScriptTargetOutput(org.hibernate.tool.schema.spi.ScriptTargetOutput) Map(java.util.Map) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 3 with Database

use of org.hibernate.boot.model.relational.Database in project hibernate-orm by hibernate.

the class SequenceStyleConfigUnitTest method testDefaultOptimizerBasedOnIncrementBackedBySequence.

/**
 * Test default optimizer selection for sequence backed generators
 * based on the configured increment size; both in the case of the
 * dialect supporting pooled sequences (pooled) and not (hilo)
 */
@Test
public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
    // for dialects which do not support pooled sequences, we default to pooled+table
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, SequenceDialect.class.getName()).build();
    try {
        Properties props = buildGeneratorPropertiesBase(serviceRegistry);
        props.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "10");
        SequenceStyleGenerator generator = new SequenceStyleGenerator();
        generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
        generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
        assertClassAssignability(TableStructure.class, generator.getDatabaseStructure().getClass());
        assertClassAssignability(PooledOptimizer.class, generator.getOptimizer().getClass());
        assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
    // for dialects which do support pooled sequences, we default to pooled+sequence
    serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, PooledSequenceDialect.class.getName()).build();
    try {
        Properties props = buildGeneratorPropertiesBase(serviceRegistry);
        props.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "10");
        SequenceStyleGenerator generator = new SequenceStyleGenerator();
        generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
        generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
        assertClassAssignability(SequenceStructure.class, generator.getDatabaseStructure().getClass());
        assertClassAssignability(PooledOptimizer.class, generator.getOptimizer().getClass());
        assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Database(org.hibernate.boot.model.relational.Database) Properties(java.util.Properties) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 4 with Database

use of org.hibernate.boot.model.relational.Database in project hibernate-orm by hibernate.

the class SequenceStyleConfigUnitTest method testDefaultedSequenceBackedConfiguration.

/**
 * Test all params defaulted with a dialect supporting sequences
 */
@Test
public void testDefaultedSequenceBackedConfiguration() {
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, SequenceDialect.class.getName()).build();
    try {
        Properties props = buildGeneratorPropertiesBase(serviceRegistry);
        SequenceStyleGenerator generator = new SequenceStyleGenerator();
        generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
        generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
        assertClassAssignability(SequenceStructure.class, generator.getDatabaseStructure().getClass());
        assertClassAssignability(NoopOptimizer.class, generator.getOptimizer().getClass());
        assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Database(org.hibernate.boot.model.relational.Database) Properties(java.util.Properties) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 5 with Database

use of org.hibernate.boot.model.relational.Database in project hibernate-orm by hibernate.

the class SequenceStyleConfigUnitTest method testDefaultOptimizerBasedOnIncrementBackedByTable.

/**
 * Test default optimizer selection for table backed generators
 * based on the configured increment size.  Here we always prefer
 * pooled.
 */
@Test
public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, TableDialect.class.getName()).build();
    try {
        Properties props = buildGeneratorPropertiesBase(serviceRegistry);
        props.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "10");
        SequenceStyleGenerator generator = new SequenceStyleGenerator();
        generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
        generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
        assertClassAssignability(TableStructure.class, generator.getDatabaseStructure().getClass());
        assertClassAssignability(PooledOptimizer.class, generator.getOptimizer().getClass());
        assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Database(org.hibernate.boot.model.relational.Database) Properties(java.util.Properties) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

Database (org.hibernate.boot.model.relational.Database)18 Test (org.junit.Test)9 Properties (java.util.Properties)7 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)7 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)7 Identifier (org.hibernate.boot.model.naming.Identifier)6 ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategy)4 Table (org.hibernate.mapping.Table)4 HashSet (java.util.HashSet)3 ObjectNameNormalizer (org.hibernate.boot.model.naming.ObjectNameNormalizer)3 PhysicalNamingStrategy (org.hibernate.boot.model.naming.PhysicalNamingStrategy)3 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)3 Namespace (org.hibernate.boot.model.relational.Namespace)3 Sequence (org.hibernate.boot.model.relational.Sequence)3 Map (java.util.Map)2 AnnotationException (org.hibernate.AnnotationException)2 MetadataSources (org.hibernate.boot.MetadataSources)2 ImplicitBasicColumnNameSource (org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource)2 AttributePath (org.hibernate.boot.model.source.spi.AttributePath)2 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)2