KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > ce > auction > persistence > CENamingStrategy


1 package org.hibernate.ce.auction.persistence;
2
3 import org.hibernate.cfg.NamingStrategy;
4 import org.hibernate.util.StringHelper;
5
6 /**
7  * Prefix database table and column names with a CaveatEmptor handle.
8  * <p>
9  * This is the implementation of a Hibernate <tt>NamingStrategy</tt>.
10  * Hibernate calls this class whenever it creates the database schema.
11  * All table names are prefixed with "CE_" while keeping the
12  * default Hibernate of uppercase property names. To enable this strategy,
13  * set it as the default for the <tt>SessionFactory</tt> , eg. in
14  * <tt>HibernateUtil</tt>:
15  * <p>
16  * <pre>
17  * configuration = new Configuration();
18  * configuration.setNamingStrategy(new CENamingStrategy());
19  * sessionFactory = configuration.configure().buildSessionFactory();
20  *
21  * </pre>
22  * In general, <tt>NamingStrategy</tt> is a powerful concept that gives
23  * you freedom to name your database tables and columns using whatever
24  * pattern you like.
25  *
26  * @see HibernateUtil
27  * @author Christian Bauer <christian@hibernate.org>
28  */

29 public class CENamingStrategy implements NamingStrategy {
30
31     public String JavaDoc classToTableName(String JavaDoc className) {
32         return StringHelper.unqualify(className);
33     }
34
35     public String JavaDoc propertyToColumnName(String JavaDoc propertyName) {
36         return propertyName;
37     }
38
39     public String JavaDoc tableName(String JavaDoc tableName) {
40         return "CE_" + tableName;
41     }
42
43     public String JavaDoc columnName(String JavaDoc columnName) {
44         return columnName;
45     }
46
47     public String JavaDoc propertyToTableName(String JavaDoc className, String JavaDoc propertyName) {
48         return "CE_"
49                 + classToTableName(className)
50                 + '_'
51                 + propertyToColumnName(propertyName);
52     }
53
54 }
55
Popular Tags