KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > persister > collection > ElementPropertyMapping


1 //$Id: ElementPropertyMapping.java,v 1.2 2005/03/23 15:41:47 steveebersole Exp $
2
package org.hibernate.persister.collection;
3
4 import org.hibernate.MappingException;
5
6 import org.hibernate.QueryException;
7
8 import org.hibernate.persister.entity.PropertyMapping;
9
10 import org.hibernate.type.Type;
11
12 import org.hibernate.util.StringHelper;
13
14 /**
15  * @author Gavin King
16  */

17 public class ElementPropertyMapping implements PropertyMapping {
18
19     private final String JavaDoc[] elementColumns;
20     private final Type type;
21
22     public ElementPropertyMapping(String JavaDoc[] elementColumns, Type type)
23     throws MappingException {
24         this.elementColumns = elementColumns;
25         this.type = type;
26     }
27
28     public Type toType(String JavaDoc propertyName) throws QueryException {
29         if ( propertyName==null || "id".equals(propertyName) ) {
30             return type;
31         }
32         else {
33             throw new QueryException("cannot dereference scalar collection element: " + propertyName);
34         }
35     }
36
37     public String JavaDoc[] toColumns(String JavaDoc alias, String JavaDoc propertyName) throws QueryException {
38         if (propertyName==null || "id".equals(propertyName) ) {
39             return StringHelper.qualify(alias, elementColumns);
40         }
41         else {
42             throw new QueryException("cannot dereference scalar collection element: " + propertyName);
43         }
44     }
45
46     /**
47      * Given a property path, return the corresponding column name(s).
48      */

49     public String JavaDoc[] toColumns(String JavaDoc propertyName) throws QueryException, UnsupportedOperationException JavaDoc {
50         throw new UnsupportedOperationException JavaDoc( "References to collections must be define a SQL alias" );
51     }
52
53     public Type getType() {
54         return type;
55     }
56
57 }
Popular Tags