Class LinkGenerator

java.lang.Object
ch.tocco.nice2.model.entity.api.relation.LinkGenerator

public final class LinkGenerator extends Object
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_column2
 
The 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 Details

    • generateLink

      public static String generateLink(RelationModel model)
      Creates the link element for the given RelationModel using the information supplied with getName() for the given model and its reverse model. For 1:n relations, the foreign key column is returned, for n:m relations the link triple tablename:fk1:fk2 is returned. Please see class documentation for more detail.