public interface FieldNameConverter
Superinterface to all field name converters; designed to impose conventions upon the auto-conversion of method names to database fields. The idea behind this is to allow user-specified field name conventions and standards rather than always enforcing ActiveObjects's idea of "good naming".
Every EntityManager
contains a single field name converter which
the entire library uses when performing operations. Any third-party code which
interacts with database fields can also make use of this class. However, it's
significantly harder to do so because Java doesn't support method literals.
Most new implementations of field name converters should extend
AbstractFieldNameConverter
rather than implementing this interface
directly. This allows third-party converters to take advantage of boiler-plate
conversion code which would otherwise have to be duplicated in every converter.
Modifier and Type | Method and Description |
---|---|
String |
getName(Method method)
Generates a field name to correspond with the specified method.
|
String |
getPolyTypeName(Method method)
Generates a secondary field name which corresponds with the polymorphic
type flag for the field corresponding to the specified method.
|
String getName(Method method)
method
- The method for which a corresponding field name must be
generated.String getPolyTypeName(Method method)
Generates a secondary field name which corresponds with the polymorphic
type flag for the field corresponding to the specified method. If the
method in question does not represent a polymorphic field, this method
may return any value, or null
. For most use-cases, the
return value of this method will be identical to that of the
getName(Method)
method with a conventional suffix (usually "Type"
or "_type") to indicate that it is a polymorphic flag. Polymorphic
fields are the only scenario in which two fields will correspond to a
single method.
An example of a table with a polymorphic flagging field could be taken as follows (MySQL DDL):
CREATE TABLE comments ( id INTEGER NOT NULL AUTO_INCREMENT, title VARCHAR(45), text TEXT, commentableID INTEGER, commentableType VARCHAR(255), PRIMARY KEY(id) );
Notice the absence of foreign key constraint on the commentableID
field. This is because this table has a one-to-many mapping with potentially
numerous tables which can be described as "commentable". Thus,
commentableID
and commentableType
describe a
polymorphic one-to-many relationship within the database.
method
- The method for which a corresponding field name must be
generated.Copyright © 2007–2019 Atlassian. All rights reserved.