use of org.hibernate.boot.model.relational.Namespace in project hibernate-orm by hibernate.
the class IdentityGeneratorExtendsTest method testIdentifierGeneratorExtendsIdentityGenerator.
@Test
public void testIdentifierGeneratorExtendsIdentityGenerator() {
final MetadataSources sources = new MetadataSources(serviceRegistry());
sources.addAnnotatedClass(EntityBean.class);
final MetadataBuilder builder = sources.getMetadataBuilder();
final Metadata metadata = builder.build();
for (final Namespace ns : metadata.getDatabase().getNamespaces()) {
for (final org.hibernate.mapping.Table table : ns.getTables()) {
final KeyValue value = table.getIdentifierValue();
assertNotNull("IdentifierValue was null", value);
assertTrue(value.isIdentityColumn(metadata.getIdentifierGeneratorFactory(), getDialect()));
}
}
Session s = openSession();
s.beginTransaction();
s.save(new EntityBean());
s.getTransaction().commit();
s.close();
}
use of org.hibernate.boot.model.relational.Namespace in project hibernate-orm by hibernate.
the class SequenceExportTest method testMultipleUsesOfExplicitSequenceName.
@Test
@TestForIssue(jiraKey = "HHH-9936")
public void testMultipleUsesOfExplicitSequenceName() {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Entity3.class).addAnnotatedClass(Entity4.class).buildMetadata();
metadata.validate();
int namespaceCount = 0;
int sequenceCount = 0;
for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
namespaceCount++;
for (Sequence sequence : namespace.getSequences()) {
sequenceCount++;
}
}
assertEquals(1, namespaceCount);
assertEquals(1, sequenceCount);
}
use of org.hibernate.boot.model.relational.Namespace in project hibernate-orm by hibernate.
the class ConstraintTest method testConstraintNameLength.
@Test
@TestForIssue(jiraKey = "HHH-1904")
public void testConstraintNameLength() {
int foundCount = 0;
for (Namespace namespace : metadata().getDatabase().getNamespaces()) {
for (org.hibernate.mapping.Table table : namespace.getTables()) {
Iterator fkItr = table.getForeignKeyIterator();
while (fkItr.hasNext()) {
ForeignKey fk = (ForeignKey) fkItr.next();
assertTrue(fk.getName().length() <= MAX_NAME_LENGTH);
// ensure the randomly generated constraint name doesn't
// happen if explicitly given
Column column = fk.getColumn(0);
if (column.getName().equals("explicit_native")) {
foundCount++;
assertEquals(fk.getName(), EXPLICIT_FK_NAME_NATIVE);
} else if (column.getName().equals("explicit_jpa")) {
foundCount++;
assertEquals(fk.getName(), EXPLICIT_FK_NAME_JPA);
}
}
Iterator ukItr = table.getUniqueKeyIterator();
while (ukItr.hasNext()) {
UniqueKey uk = (UniqueKey) ukItr.next();
assertTrue(uk.getName().length() <= MAX_NAME_LENGTH);
// ensure the randomly generated constraint name doesn't
// happen if explicitly given
Column column = uk.getColumn(0);
if (column.getName().equals("explicit")) {
foundCount++;
assertEquals(uk.getName(), EXPLICIT_UK_NAME);
}
}
}
}
assertEquals("Could not find the necessary columns.", 3, foundCount);
}
use of org.hibernate.boot.model.relational.Namespace in project hibernate-orm by hibernate.
the class InFlightMetadataCollectorImpl method addTable.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Table handling
@Override
public Table addTable(String schemaName, String catalogName, String name, String subselectFragment, boolean isAbstract) {
final Namespace namespace = getDatabase().locateNamespace(getDatabase().toIdentifier(catalogName), getDatabase().toIdentifier(schemaName));
// annotation binding depends on the "table name" for @Subselect bindings
// being set into the generated table (mainly to avoid later NPE), but for now we need to keep that :(
final Identifier logicalName;
if (name != null) {
logicalName = getDatabase().toIdentifier(name);
} else {
logicalName = null;
}
if (subselectFragment != null) {
return new Table(namespace, logicalName, subselectFragment, isAbstract);
} else {
Table table = namespace.locateTable(logicalName);
if (table != null) {
if (!isAbstract) {
table.setAbstract(false);
}
return table;
}
return namespace.createTable(logicalName, isAbstract);
}
}
use of org.hibernate.boot.model.relational.Namespace in project hibernate-orm by hibernate.
the class MultipleHiLoPerTableGenerator method registerExportables.
@Override
public void registerExportables(Database database) {
final Namespace namespace = database.locateNamespace(qualifiedTableName.getCatalogName(), qualifiedTableName.getSchemaName());
Table table = namespace.locateTable(qualifiedTableName.getObjectName());
if (table == null) {
table = namespace.createTable(qualifiedTableName.getObjectName(), false);
// todo : note sure the best solution here. do we add the columns if missing? other?
table.setPrimaryKey(new PrimaryKey(table));
final Column pkColumn = new ExportableColumn(database, table, segmentColumnName, StringType.INSTANCE, database.getDialect().getTypeName(Types.VARCHAR, keySize, 0, 0));
pkColumn.setNullable(false);
table.addColumn(pkColumn);
table.getPrimaryKey().addColumn(pkColumn);
final Column valueColumn = new ExportableColumn(database, table, valueColumnName, LongType.INSTANCE);
table.addColumn(valueColumn);
}
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
// allow physical naming strategies a chance to kick in
tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(table.getQualifiedTableName(), jdbcEnvironment.getDialect());
query = "select " + valueColumnName + " from " + jdbcEnvironment.getDialect().appendLockHint(LockMode.PESSIMISTIC_WRITE, tableName) + " where " + segmentColumnName + " = '" + segmentName + "'" + jdbcEnvironment.getDialect().getForUpdateString();
update = "update " + tableName + " set " + valueColumnName + " = ? where " + valueColumnName + " = ? and " + segmentColumnName + " = '" + segmentName + "'";
insert = "insert into " + tableName + "(" + segmentColumnName + ", " + valueColumnName + ") " + "values('" + segmentName + "', ?)";
}
Aggregations