01: package org.apache.ojb.broker.accesslayer.sql;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.metadata.ClassDescriptor;
19: import org.apache.ojb.broker.metadata.FieldDescriptor;
20: import org.apache.ojb.broker.platforms.Platform;
21: import org.apache.ojb.broker.query.Criteria;
22: import org.apache.ojb.broker.query.Query;
23: import org.apache.ojb.broker.query.QueryByCriteria;
24: import org.apache.ojb.broker.util.logging.Logger;
25:
26: /**
27: * Model a SELECT Statement by Primary Key
28: *
29: * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
30: * @version $Id: SqlSelectByPkStatement.java,v 1.8.2.4 2005/12/22 18:25:51 brj Exp $
31: */
32:
33: public class SqlSelectByPkStatement extends SqlSelectStatement {
34: /**
35: * Constructor for SqlSelectByPkStatement.
36: *
37: * @param cld
38: * @param logger
39: */
40: public SqlSelectByPkStatement(Platform pf, ClassDescriptor cld,
41: Logger logger) {
42: super (pf, cld, buildQuery(cld), logger);
43: }
44:
45: /**
46: * Build a Pk-Query base on the ClassDescriptor.
47: *
48: * @param cld
49: * @return a select by PK query
50: */
51: private static Query buildQuery(ClassDescriptor cld) {
52: FieldDescriptor[] pkFields = cld.getPkFields();
53: Criteria crit = new Criteria();
54:
55: for (int i = 0; i < pkFields.length; i++) {
56: crit.addEqualTo(pkFields[i].getAttributeName(), null);
57: }
58: return new QueryByCriteria(cld.getClassOfObject(), crit);
59: }
60: }
|