Hi folks,

I'm trying to port the global naming strategy we use to Grails 8 with no
luck at the moment.

We name domain classes with a `T` prefix to indicate it is a class affected
by the @Transactional context. It is useful info to be aware of when coding.

Since today we prefixed the table names with a corresponding `t_` prefix
but I'd like to have plain names for tables/columns in the DB for Dueuno
4/Grails 8.

This is what I'm trying but it looks like the method is not executed. The
configuration is inside `plugin.groovy`:

hibernate.physicalNamingStrategy = dueuno.database.TNamingStrategy


This is the implementation:

@CompileStatic
class TNamingStrategy implements PhysicalNamingStrategy {

    @Override
    Identifier toPhysicalTableName(Identifier logicalName,
JdbcEnvironment jdbcEnvironment) {
        String className = logicalName.text
        String tableName = className.startsWith('T')
                ? className.drop(1)
                : className
        return Identifier.toIdentifier(tableName.toLowerCase())

    }

    @Override
    Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment
environment) {
        Identifier.toIdentifier(name.text.toLowerCase())
    }

    @Override
    Identifier toPhysicalCatalogName(Identifier name, JdbcEnvironment
environment) {
        return name
    }

    @Override
    Identifier toPhysicalSchemaName(Identifier name, JdbcEnvironment
environment) {
        return name
    }

    @Override
    Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment
environment) {
        return name
    }

}


What is the correct way of implementing a custom naming strategy?
What am I missing?

Cheers,
Gianluca


Gianluca Sartori
--
https://dueuno.com

Reply via email to