01: package org.hibernate.param;
02:
03: import java.sql.PreparedStatement;
04: import java.sql.SQLException;
05:
06: import org.hibernate.engine.QueryParameters;
07: import org.hibernate.engine.SessionImplementor;
08: import org.hibernate.type.Type;
09:
10: /**
11: * A specialized ParameterSpecification impl for dealing with a collection-key
12: * as part of a collection filter compilation.
13: *
14: * @author Steve Ebersole
15: */
16: public class CollectionFilterKeyParameterSpecification implements
17: ParameterSpecification {
18:
19: private final String collectionRole;
20: private final Type keyType;
21: private final int queryParameterPosition;
22:
23: /**
24: * Creates a specialized collection-filter collection-key parameter spec.
25: *
26: * @param collectionRole The collection role being filtered.
27: * @param keyType The mapped collection-key type.
28: * @param queryParameterPosition The position within {@link org.hibernate.engine.QueryParameters} where
29: * we can find the appropriate param value to bind.
30: */
31: public CollectionFilterKeyParameterSpecification(
32: String collectionRole, Type keyType,
33: int queryParameterPosition) {
34: this .collectionRole = collectionRole;
35: this .keyType = keyType;
36: this .queryParameterPosition = queryParameterPosition;
37: }
38:
39: public int bind(PreparedStatement statement, QueryParameters qp,
40: SessionImplementor session, int position)
41: throws SQLException {
42: Object value = qp.getPositionalParameterValues()[queryParameterPosition];
43: keyType.nullSafeSet(statement, value, position, session);
44: return keyType.getColumnSpan(session.getFactory());
45: }
46:
47: public Type getExpectedType() {
48: return keyType;
49: }
50:
51: public void setExpectedType(Type expectedType) {
52: // todo : throw exception?
53: }
54:
55: public String renderDisplayInfo() {
56: return "collection-filter-key=" + collectionRole;
57: }
58: }
|