KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > NameGenerator


1 // $Id: NameGenerator.java,v 1.5 2004/12/06 14:17:22 pgmjsd Exp $
2
package org.hibernate.hql;
3
4 import org.hibernate.MappingException;
5 import org.hibernate.engine.SessionFactoryImplementor;
6 import org.hibernate.type.Type;
7
8 /**
9  * Provides utility methods for generating HQL / SQL names. Shared by both the 'classic' and 'new' query translators.
10  *
11  * @author josh Mar 18, 2004 7:17:25 AM
12  */

13 public final class NameGenerator {
14     /**
15      * Private empty constructor (checkstyle says utility classes should not have default constructors).
16      */

17     private NameGenerator() {
18     }
19
20     public static String JavaDoc[][] generateColumnNames(Type[] types, SessionFactoryImplementor f) throws MappingException {
21         String JavaDoc[][] columnNames = new String JavaDoc[types.length][];
22         for ( int i = 0; i < types.length; i++ ) {
23             int span = types[i].getColumnSpan( f );
24             columnNames[i] = new String JavaDoc[span];
25             for ( int j = 0; j < span; j++ ) {
26                 columnNames[i][j] = NameGenerator.scalarName( i, j );
27             }
28         }
29         return columnNames;
30     }
31
32     public static String JavaDoc scalarName(int x, int y) {
33         return new StringBuffer JavaDoc()
34                 .append( "col_" )
35                 .append( x )
36                 .append( '_' )
37                 .append( y )
38                 .append( '_' )
39                 .toString();
40     }
41 }
42
Popular Tags