View Javadoc

1   package org.mod4j.runtime.hibernate;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   import org.hibernate.cfg.ImprovedNamingStrategy;
6   import org.hibernate.cfg.NamingStrategy;
7   
8   /**
9    * @author Eric Jan Malotaux
10   */
11  public class Mod4jNamingStrategy extends ImprovedNamingStrategy {
12      private static Log logger = LogFactory.getLog(Mod4jNamingStrategy.class);
13  
14      /**
15       * A convenient singleton instance
16       */
17      public static final NamingStrategy INSTANCE = new Mod4jNamingStrategy();
18  
19      /**
20       * {@inheritDoc}
21       */
22      @Override
23      public String classToTableName(String className) {
24          String result = super.classToTableName(className) + "_table";
25          if (logger.isDebugEnabled()) {
26              logger.debug("className=" + className);
27              logger.debug("result=" + result);
28          }
29          return result;
30      }
31  
32      /**
33       * {@inheritDoc}
34       */
35      @Override
36      public String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity,
37              String associatedEntityTable, String propertyName) {
38          String collectionTableName = super.collectionTableName(ownerEntity, ownerEntityTable, associatedEntity,
39                  associatedEntityTable, propertyName);
40          if (logger.isDebugEnabled()) {
41              logger.debug("ownerEntity=" + ownerEntity);
42              logger.debug("ownerEntityTable=" + ownerEntityTable);
43              logger.debug("associatedEntity=" + associatedEntity);
44              logger.debug("associatedEntityTable=" + associatedEntityTable);
45              logger.debug("propertyName=" + propertyName);
46              logger.debug("result=" + collectionTableName);
47          }
48          return collectionTableName;
49      }
50  
51      /**
52       * {@inheritDoc}
53       */
54      @Override
55      public String columnName(String columnName) {
56          String result = super.columnName(columnName);
57          if (logger.isDebugEnabled()) {
58              logger.debug("columnName=" + columnName);
59              logger.debug("result=" + result);
60          }
61          return result;
62      }
63  
64      /**
65       * {@inheritDoc}
66       */
67      @Override
68      public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName,
69              String referencedColumnName) {
70          String result = super.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName,
71                  referencedColumnName);
72          if (logger.isDebugEnabled()) {
73              logger.debug("propertyName=" + propertyName);
74              logger.debug("propertyEntityName=" + propertyEntityName);
75              logger.debug("propertyTableName=" + propertyTableName);
76              logger.debug("referencedColumnName=" + referencedColumnName);
77              logger.debug("result=" + result);
78          }
79          return result;
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      public String joinKeyColumnName(String joinedColumn, String joinedTable) {
87          String result = super.joinKeyColumnName(joinedColumn, joinedTable);
88          if (logger.isDebugEnabled()) {
89              logger.debug("joinedColumn=" + joinedColumn);
90              logger.debug("joinedTable=" + joinedTable);
91              logger.debug("result=" + result);
92          }
93          return result;
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) {
101         String result = super.logicalCollectionColumnName(columnName, propertyName, referencedColumn);
102         if (logger.isDebugEnabled()) {
103             logger.debug("columnName=" + columnName);
104             logger.debug("propertyName=" + propertyName);
105             logger.debug("referencedColumn=" + referencedColumn);
106             logger.debug("result=" + result);
107         }
108         return result;
109     }
110 
111     /**
112      * {@inheritDoc}
113      */
114     @Override
115     public String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable,
116             String propertyName) {
117         String result = super.logicalCollectionTableName(tableName, ownerEntityTable, associatedEntityTable,
118                 propertyName);
119         if (logger.isDebugEnabled()) {
120             logger.debug("tableName=" + tableName);
121             logger.debug("ownerEntityTable=" + ownerEntityTable);
122             logger.debug("associatedEntityTable=" + associatedEntityTable);
123             logger.debug("propertyName=" + propertyName);
124             logger.debug("result=" + result);
125         }
126         return result;
127     }
128 
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public String logicalColumnName(String columnName, String propertyName) {
134         String result = super.logicalColumnName(columnName, propertyName);
135         if (logger.isDebugEnabled()) {
136             logger.debug("columnName=" + columnName);
137             logger.debug("propertyName=" + propertyName);
138             logger.debug("result=" + result);
139         }
140         return result;
141     }
142 
143     /**
144      * {@inheritDoc}
145      */
146     @Override
147     public String propertyToColumnName(String propertyName) {
148         String result = super.propertyToColumnName(propertyName);
149         if (logger.isDebugEnabled()) {
150             logger.debug("propertyName=" + propertyName);
151             logger.debug("result=" + result);
152         }
153         return result;
154     }
155 
156     /**
157      * {@inheritDoc}
158      */
159     @Override
160     public String tableName(String tableName) {
161         String result = super.tableName(tableName);
162         if (logger.isDebugEnabled()) {
163             logger.debug("tableName=" + tableName);
164             logger.debug("result=" + result);
165         }
166         return result;
167     }
168 }