001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.ejb.entity;
030:
031: import com.caucho.ejb.AbstractContext;
032: import com.caucho.ejb.AbstractEJBHome;
033: import com.caucho.ejb.AbstractServer;
034: import com.caucho.ejb.protocol.HomeSkeletonWrapper;
035: import com.caucho.log.Log;
036:
037: import javax.ejb.EJBHome;
038: import javax.ejb.EJBMetaData;
039: import javax.ejb.FinderException;
040: import javax.ejb.Handle;
041: import javax.ejb.HomeHandle;
042: import javax.ejb.RemoveException;
043: import java.io.ObjectStreamException;
044: import java.io.Serializable;
045: import java.util.logging.Logger;
046:
047: /**
048: * Abstract base class for an EntityHome.
049: */
050: abstract public class EntityHome extends AbstractEJBHome implements
051: EJBHome, Serializable {
052: protected static final Logger log = Log.open(EntityHome.class);
053:
054: protected final EntityServer _server;
055:
056: protected EntityHome(EntityServer server) {
057: _server = server;
058: }
059:
060: /**
061: * Returns the owning server.
062: */
063: public EntityServer getServer() {
064: return _server;
065: }
066:
067: /**
068: * Returns the EJB's meta data.
069: */
070: public EJBMetaData getEJBMetaData() {
071: return getServer().getEJBMetaData();
072: }
073:
074: /**
075: * Returns the home handle for the home bean.
076: */
077: public HomeHandle getHomeHandle() {
078: return getServer().getHomeHandle();
079: }
080:
081: /**
082: * Returns null, since primary key isn't available to the home.
083: */
084: public Object getPrimaryKey() {
085: return null;
086: }
087:
088: /**
089: * Remove the object specified by the handle.
090: */
091: public void remove(Handle handle) throws RemoveException {
092: getServer().remove(handle);
093: }
094:
095: /**
096: * Remove the object specified by the primary key.
097: */
098: public void remove(Object primaryKey) throws RemoveException {
099: try {
100: AbstractContext cxt = getServer().getContext(primaryKey);
101:
102: cxt.getEJBLocalObject().remove();
103: } catch (FinderException e) {
104: throw new RemoveException(String.valueOf(e));
105: }
106: }
107:
108: /**
109: * Returns the server.
110: */
111: public AbstractServer __caucho_getServer() {
112: return _server;
113: }
114:
115: /**
116: * The home id is null.
117: */
118: public String __caucho_getId() {
119: return null;
120: }
121:
122: /**
123: * Serialize the HomeSkeletonWrapper in place of this object.
124: *
125: * @return the matching skeleton wrapper.
126: */
127: public Object writeReplace() throws ObjectStreamException {
128: return new HomeSkeletonWrapper(getHomeHandle());
129: }
130: }
|