use of org.hibernate.boot.model.naming.ObjectNameNormalizer 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());
}
use of org.hibernate.boot.model.naming.ObjectNameNormalizer in project hibernate-orm by hibernate.
the class SequenceHiLoGeneratorNoIncrementTest method setUp.
@Before
public void setUp() throws Exception {
serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
generator = new SequenceStyleGenerator();
// Build the properties used to configure the id generator
Properties properties = new Properties();
properties.setProperty(SequenceStyleGenerator.SEQUENCE_PARAM, TEST_SEQUENCE);
properties.setProperty(SequenceStyleGenerator.OPT_PARAM, "legacy-hilo");
// JPA allocationSize of 1
properties.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "0");
properties.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, new ObjectNameNormalizer() {
@Override
protected MetadataBuildingContext getBuildingContext() {
return new MetadataBuildingContextTestingImpl(serviceRegistry);
}
});
generator.configure(StandardBasicTypes.LONG, properties, serviceRegistry);
final Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
generator.registerExportables(metadata.getDatabase());
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
sequenceValueExtractor = new SequenceValueExtractor(sessionFactory.getDialect(), TEST_SEQUENCE);
}
use of org.hibernate.boot.model.naming.ObjectNameNormalizer in project hibernate-orm by hibernate.
the class SequenceGenerator method configure.
@Override
@SuppressWarnings("StatementWithEmptyBody")
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSequenceGenerator(getClass().getName());
identifierType = type;
final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get(IDENTIFIER_NORMALIZER);
logicalQualifiedSequenceName = QualifiedNameParser.INSTANCE.parse(ConfigurationHelper.getString(SEQUENCE, params, "hibernate_sequence"), normalizer.normalizeIdentifierQuoting(params.getProperty(CATALOG)), normalizer.normalizeIdentifierQuoting(params.getProperty(SCHEMA)));
if (params.containsKey(PARAMETERS)) {
LOG.warn("Use of 'parameters' config setting is no longer supported; " + "to specify initial-value or increment use the " + "org.hibernate.id.enhanced.SequenceStyleGenerator generator instead.");
}
}
use of org.hibernate.boot.model.naming.ObjectNameNormalizer in project hibernate-orm by hibernate.
the class Ejb3Column method redefineColumnName.
public void redefineColumnName(String columnName, String propertyName, boolean applyNamingStrategy) {
final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
final Database database = context.getMetadataCollector().getDatabase();
final ImplicitNamingStrategy implicitNamingStrategy = context.getBuildingOptions().getImplicitNamingStrategy();
final PhysicalNamingStrategy physicalNamingStrategy = context.getBuildingOptions().getPhysicalNamingStrategy();
if (applyNamingStrategy) {
if (StringHelper.isEmpty(columnName)) {
if (propertyName != null) {
final AttributePath attributePath = AttributePath.parse(propertyName);
Identifier implicitName = normalizer.normalizeIdentifierQuoting(implicitNamingStrategy.determineBasicColumnName(new ImplicitBasicColumnNameSource() {
@Override
public AttributePath getAttributePath() {
return attributePath;
}
@Override
public boolean isCollectionElement() {
// @Column refers to the element column
return !propertyHolder.isComponent() && !propertyHolder.isEntity();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
}));
// HHH-6005 magic
if (implicitName.getText().contains("_collection&&element_")) {
implicitName = Identifier.toIdentifier(implicitName.getText().replace("_collection&&element_", "_"), implicitName.isQuoted());
}
final Identifier physicalName = physicalNamingStrategy.toPhysicalColumnName(implicitName, database.getJdbcEnvironment());
mappingColumn.setName(physicalName.render(database.getDialect()));
}
// Do nothing otherwise
} else {
final Identifier explicitName = database.toIdentifier(columnName);
final Identifier physicalName = physicalNamingStrategy.toPhysicalColumnName(explicitName, database.getJdbcEnvironment());
mappingColumn.setName(physicalName.render(database.getDialect()));
}
} else {
if (StringHelper.isNotEmpty(columnName)) {
mappingColumn.setName(normalizer.toDatabaseIdentifierText(columnName));
}
}
}
use of org.hibernate.boot.model.naming.ObjectNameNormalizer in project hibernate-orm by hibernate.
the class Ejb3JoinColumn method buildJoinColumn.
/**
* Build JoinColumn for a JOINED hierarchy
*/
public static Ejb3JoinColumn buildJoinColumn(PrimaryKeyJoinColumn pkJoinAnn, JoinColumn joinAnn, Value identifier, Map<String, Join> joins, PropertyHolder propertyHolder, MetadataBuildingContext context) {
final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
Column col = (Column) identifier.getColumnIterator().next();
String defaultName = context.getMetadataCollector().getLogicalColumnName(identifier.getTable(), col.getQuotedName());
if (pkJoinAnn != null || joinAnn != null) {
String colName;
String columnDefinition;
String referencedColumnName;
if (pkJoinAnn != null) {
colName = pkJoinAnn.name();
columnDefinition = pkJoinAnn.columnDefinition();
referencedColumnName = pkJoinAnn.referencedColumnName();
} else {
colName = joinAnn.name();
columnDefinition = joinAnn.columnDefinition();
referencedColumnName = joinAnn.referencedColumnName();
}
final String sqlType;
if (columnDefinition.equals("")) {
sqlType = null;
} else {
sqlType = normalizer.toDatabaseIdentifierText(columnDefinition);
}
final String name;
if ("".equals(colName)) {
name = normalizer.normalizeIdentifierQuotingAsString(defaultName);
} else {
name = context.getObjectNameNormalizer().normalizeIdentifierQuotingAsString(colName);
}
return new Ejb3JoinColumn(sqlType, name, false, false, true, true, referencedColumnName, null, joins, propertyHolder, null, null, false, context);
} else {
defaultName = context.getObjectNameNormalizer().normalizeIdentifierQuotingAsString(defaultName);
return new Ejb3JoinColumn(null, defaultName, false, false, true, true, null, null, joins, propertyHolder, null, null, true, context);
}
}
Aggregations