KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > wocompat > EOSQLQuery


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.wocompat;
21
22 import java.util.Map JavaDoc;
23
24 import org.apache.cayenne.map.ObjEntity;
25 import org.apache.cayenne.query.SQLTemplate;
26
27 /**
28  * A descriptor of SQLTemplate loaded from EOModel. It is an informal "decorator" of
29  * Cayenne SQLTemplate to provide access to the extra information of WebObjects
30  * EOFetchSpecification.
31  *
32  * @author Travis Cripps
33  * @since 1.2
34  */

35 public class EOSQLQuery extends SQLTemplate {
36
37     protected Map JavaDoc plistMap;
38
39     public EOSQLQuery(ObjEntity root, Map JavaDoc plistMap) {
40         super(root, null);
41         this.plistMap = plistMap;
42         initFromPlist(plistMap);
43     }
44
45     protected void initFromPlist(Map JavaDoc plistMap) {
46
47         setResolvingInherited("YES".equalsIgnoreCase((String JavaDoc) plistMap.get("isDeep")));
48         setRefreshingObjects("YES".equalsIgnoreCase((String JavaDoc) plistMap
49                 .get("refreshesRefetchedObjects")));
50
51         Object JavaDoc fetchLimit = plistMap.get("fetchLimit");
52         if (fetchLimit != null) {
53             try {
54                 if (fetchLimit instanceof Number JavaDoc) {
55                     setFetchLimit(((Number JavaDoc) fetchLimit).intValue());
56                 }
57                 else {
58                     setFetchLimit(Integer.parseInt(fetchLimit.toString()));
59                 }
60             }
61             catch (NumberFormatException JavaDoc nfex) {
62                 // ignoring...
63
}
64         }
65
66         //query
67
// TODO: doesn't work with Stored Procedures.
68
Map JavaDoc hints = (Map JavaDoc) plistMap.get("hints");
69         if (hints != null && !hints.isEmpty()) {
70             String JavaDoc sqlExpression = (String JavaDoc) hints.get("EOCustomQueryExpressionHintKey");
71             if (sqlExpression != null) {
72                 setDefaultTemplate(sqlExpression);
73             }
74         }
75     }
76 }
77
Popular Tags