01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.core.cmp.cmp2;
18:
19: import org.apache.openejb.Container;
20: import org.apache.openejb.DeploymentInfo;
21: import org.apache.openejb.core.cmp.CmpContainer;
22:
23: import javax.ejb.FinderException;
24:
25: /**
26: * DO NOT REFACTOR THIS CLASS. This class is referenced directly by generated code.
27: */
28: public class EjbSelect {
29: public static Object execute(Object di, String methodSignature,
30: String returnType, Object... args) throws FinderException {
31: DeploymentInfo deploymentInfo = (DeploymentInfo) di;
32: Container container = deploymentInfo.getContainer();
33: if (!(container instanceof CmpContainer)) {
34: throw new FinderException(
35: "Deployment is not connected to a CmpContainer "
36: + deploymentInfo.getDeploymentID());
37: }
38: CmpContainer cmpContainer = (CmpContainer) container;
39:
40: // if the return type is void, assume we have an update query
41: if ("void".equals(returnType)) {
42: int result = cmpContainer.update(deploymentInfo,
43: methodSignature, args);
44: return result;
45: }
46:
47: Object result = cmpContainer.select(deploymentInfo,
48: methodSignature, returnType, args);
49: if (result instanceof Number) {
50: Number number = (Number) result;
51: if ("char".equals(returnType)
52: || Character.class.getName().equals(returnType)) {
53: result = new Character((char) number.intValue());
54: } else if ("byte".equals(returnType)
55: || Byte.class.getName().equals(returnType)) {
56: result = number.byteValue();
57: } else if ("short".equals(returnType)
58: || Short.class.getName().equals(returnType)) {
59: result = number.shortValue();
60: } else if ("int".equals(returnType)
61: || Integer.class.getName().equals(returnType)) {
62: result = number.intValue();
63: } else if ("long".equals(returnType)
64: || Long.class.getName().equals(returnType)) {
65: result = number.longValue();
66: } else if ("float".equals(returnType)
67: || Float.class.getName().equals(returnType)) {
68: result = number.floatValue();
69: } else if ("double".equals(returnType)
70: || Double.class.getName().equals(returnType)) {
71: result = number.doubleValue();
72: }
73: }
74:
75: return result;
76: }
77: }
|