01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. 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: */package org.apache.openejb.client;
17:
18: import java.lang.reflect.Method;
19: import java.rmi.RemoteException;
20:
21: public class EntityEJBObjectHandler extends EJBObjectHandler {
22:
23: public EntityEJBObjectHandler() {
24: }
25:
26: public EntityEJBObjectHandler(EJBMetaDataImpl ejb,
27: ServerMetaData server, ClientMetaData client) {
28: super (ejb, server, client);
29: }
30:
31: public EntityEJBObjectHandler(EJBMetaDataImpl ejb,
32: ServerMetaData server, ClientMetaData client,
33: Object primaryKey) {
34: super (ejb, server, client, primaryKey);
35: registryId = ejb.deploymentID + ":" + primaryKey;
36: registerHandler(registryId, this );
37: }
38:
39: public Object getRegistryId() {
40: return registryId;
41: }
42:
43: protected Object getPrimaryKey(Method method, Object[] args,
44: Object proxy) throws Throwable {
45: return primaryKey;
46: }
47:
48: protected Object isIdentical(Method method, Object[] args,
49: Object proxy) throws Throwable {
50: if (args[0] == null)
51: return Boolean.FALSE;
52:
53: EJBObjectProxy ejbObject = (EJBObjectProxy) args[0];
54: EJBObjectHandler that = ejbObject.getEJBObjectHandler();
55:
56: return new Boolean(this .registryId.equals(that.registryId));
57:
58: }
59:
60: protected Object equals(Method method, Object[] args, Object proxy)
61: throws Throwable {
62: return isIdentical(method, args, proxy);
63: }
64:
65: protected Object remove(Method method, Object[] args, Object proxy)
66: throws Throwable {
67:
68: EJBRequest req = new EJBRequest(
69: RequestMethodConstants.EJB_OBJECT_REMOVE, ejb, method,
70: args, primaryKey);
71:
72: EJBResponse res = request(req);
73:
74: switch (res.getResponseCode()) {
75: case ResponseCodes.EJB_ERROR:
76: throw new SystemError((ThrowableArtifact) res.getResult());
77: case ResponseCodes.EJB_SYS_EXCEPTION:
78: throw new SystemException((ThrowableArtifact) res
79: .getResult());
80: case ResponseCodes.EJB_APP_EXCEPTION:
81: throw new ApplicationException((ThrowableArtifact) res
82: .getResult());
83: case ResponseCodes.EJB_OK:
84: invalidateAllHandlers(getRegistryId());
85: return null;
86: default:
87: throw new RemoteException(
88: "Received invalid response code from server: "
89: + res.getResponseCode());
90: }
91: }
92:
93: protected void invalidateReference() {
94: // entity bean object references should not be invalidated since they
95: // will automatically hook up to a new instance of the bean using the
96: // primary key (we will load a new instance from the db)
97: }
98: }
|