KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > loader > GeneratedCollectionAliases


1 // $Id: GeneratedCollectionAliases.java,v 1.2 2005/07/04 11:17:33 maxcsaucdk Exp $
2
package org.hibernate.loader;
3
4 import java.util.Map JavaDoc;
5
6 import org.hibernate.persister.collection.CollectionPersister;
7 import org.hibernate.util.CollectionHelper;
8 import org.hibernate.util.StringHelper;
9
10 /**
11  * Implementation of GeneratedCollectionAliases.
12  *
13  * @author Steve Ebersole
14  */

15 public class GeneratedCollectionAliases implements CollectionAliases {
16     private final String JavaDoc suffix;
17     private final String JavaDoc[] keyAliases;
18     private final String JavaDoc[] indexAliases;
19     private final String JavaDoc[] elementAliases;
20     private final String JavaDoc identifierAlias;
21     private Map JavaDoc userProvidedAliases;
22     
23     public GeneratedCollectionAliases(Map JavaDoc userProvidedAliases, CollectionPersister persister, String JavaDoc suffix) {
24         this.suffix = suffix;
25         this.userProvidedAliases = userProvidedAliases;
26
27         this.keyAliases = getUserProvidedAliases(
28                 "key",
29                 persister.getKeyColumnAliases( suffix )
30             );
31
32         this.indexAliases = getUserProvidedAliases(
33                 "index",
34                 persister.getIndexColumnAliases( suffix )
35                 );
36         
37         this.elementAliases = getUserProvidedAliases( "element",
38                 persister.getElementColumnAliases( suffix )
39                 );
40                 
41         this.identifierAlias = getUserProvidedAlias( "id",
42                 persister.getIdentifierColumnAlias( suffix )
43                 );
44     }
45
46     public GeneratedCollectionAliases(CollectionPersister persister, String JavaDoc string) {
47         this(CollectionHelper.EMPTY_MAP, persister, string);
48     }
49
50     /**
51      * Returns the suffixed result-set column-aliases for columns making up the key for this collection (i.e., its FK to
52      * its owner).
53      *
54      * @return The key result-set column aliases.
55      */

56     public String JavaDoc[] getSuffixedKeyAliases() {
57         return keyAliases;
58     }
59
60     /**
61      * Returns the suffixed result-set column-aliases for the collumns making up the collection's index (map or list).
62      *
63      * @return The index result-set column aliases.
64      */

65     public String JavaDoc[] getSuffixedIndexAliases() {
66         return indexAliases;
67     }
68
69     /**
70      * Returns the suffixed result-set column-aliases for the columns making up the collection's elements.
71      *
72      * @return The element result-set column aliases.
73      */

74     public String JavaDoc[] getSuffixedElementAliases() {
75         return elementAliases;
76     }
77
78     /**
79      * Returns the suffixed result-set column-aliases for the column defining the collection's identifier (if any).
80      *
81      * @return The identifier result-set column aliases.
82      */

83     public String JavaDoc getSuffixedIdentifierAlias() {
84         return identifierAlias;
85     }
86
87     /**
88      * Returns the suffix used to unique the column aliases for this particular alias set.
89      *
90      * @return The uniqued column alias suffix.
91      */

92     public String JavaDoc getSuffix() {
93         return suffix;
94     }
95
96     public String JavaDoc toString() {
97         return super.toString() + " [suffix=" + suffix +
98                 ", suffixedKeyAliases=[" + join( keyAliases ) +
99                 "], suffixedIndexAliases=[" + join( indexAliases ) +
100                 "], suffixedElementAliases=[" + join( elementAliases ) +
101                 "], suffixedIdentifierAlias=[" + identifierAlias + "]]";
102     }
103
104     private String JavaDoc join(String JavaDoc[] aliases) {
105         if ( aliases == null) return null;
106
107         return StringHelper.join( ", ", aliases );
108     }
109     
110     private String JavaDoc[] getUserProvidedAliases(String JavaDoc propertyPath, String JavaDoc[] defaultAliases) {
111         String JavaDoc[] result = (String JavaDoc[]) userProvidedAliases.get(propertyPath);
112         if (result==null) {
113             return defaultAliases;
114         }
115         else {
116             return result;
117         }
118     }
119
120     private String JavaDoc getUserProvidedAlias(String JavaDoc propertyPath, String JavaDoc defaultAlias) {
121         String JavaDoc[] columns = (String JavaDoc[]) userProvidedAliases.get(propertyPath);
122         if (columns==null) {
123             return defaultAlias;
124         }
125         else {
126             return columns[0];
127         }
128     }
129
130 }
131
Popular Tags