Class LinkGenerator
java.lang.Object
ch.tocco.nice2.model.entity.api.relation.LinkGenerator
Generates the value for the
<link/>
tag of a relation.
For 1:n
relations, the foreign key column name is generated according
to the following scheme
fk_LC(NOREL(<relation_name>))
where LC
converts everything to lowercase and NOREL
strips any leading
rel
prefix from the relation name (turning relUser
into user
).
For n:m
relations, the link is a triple of the form
link_table_name:fk_column1:fk_column2The
link_table_name
is created according to this scheme:
"nice_" LC(NOREL(<relation_name>)) "_to_" LC(NOREL(<reverse_relation_name>))
FKs ordering: owning:reverse
The two foreign key columns are created the same way as the foreign key columns
for 1:n
relations.
If a column- or table name exceeds a length of 63 chars (which is the maximum length for postgresql objects), it is reduced to 63 chars. To retain readability the reduction is done like this:
1. Split the name by underscore into a list of segments 2. remove the last character from segments until the name is of appropriate length. If a segments is of length 1 don't modify it.If the length cannot be reduced (because there are too many segments), an
IllegalStateException
is thrown.-
Method Summary
Modifier and TypeMethodDescriptionstatic String
generateLink
(RelationModel model) Creates the link element for the givenRelationModel
using the information supplied withgetName()
for the given model and its reverse model.
-
Method Details
-
generateLink
Creates the link element for the givenRelationModel
using the information supplied withgetName()
for the given model and its reverse model. For1:n
relations, the foreign key column is returned, forn:m
relations the link tripletablename:fk1:fk2
is returned. Please see class documentation for more detail.
-