001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cmp2.lob;
023:
024: import javax.ejb.SessionBean;
025: import javax.ejb.SessionContext;
026: import javax.ejb.CreateException;
027: import javax.ejb.EJBException;
028: import javax.naming.InitialContext;
029: import javax.rmi.PortableRemoteObject;
030: import java.util.Set;
031: import java.util.Map;
032: import java.util.List;
033:
034: /**
035: *
036: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
037: */
038: public class FacadeSessionBean implements SessionBean {
039: private LOBHome lobHome;
040:
041: // Business methods
042:
043: public void createLOB(Integer id) throws Exception {
044: getLOBHome().create(id);
045: }
046:
047: public void removeLOB(Integer id) throws Exception {
048: getLOBHome().remove(id);
049: }
050:
051: public void addMapEntry(Integer id, Object key, Object value)
052: throws Exception {
053: getLOBHome().findByPrimaryKey(id).getMapField().put(key, value);
054: }
055:
056: public Map getMapField(Integer id) throws Exception {
057: return getLOBHome().findByPrimaryKey(id).getMapField();
058: }
059:
060: public void addSetElement(Integer id, Object value)
061: throws Exception {
062: getLOBHome().findByPrimaryKey(id).getSetField().add(value);
063: }
064:
065: public Set getSetField(Integer id) throws Exception {
066: return getLOBHome().findByPrimaryKey(id).getSetField();
067: }
068:
069: public void addListElement(Integer id, Object value)
070: throws Exception {
071: getLOBHome().findByPrimaryKey(id).getListField().add(value);
072: }
073:
074: public List getListField(Integer id) throws Exception {
075: return getLOBHome().findByPrimaryKey(id).getListField();
076: }
077:
078: public void setBinaryData(Integer id, byte[] value)
079: throws Exception {
080: getLOBHome().findByPrimaryKey(id).setBinaryData(value);
081: }
082:
083: public void setBinaryDataElement(Integer id, int index, byte value)
084: throws Exception {
085: getLOBHome().findByPrimaryKey(id).getBinaryData()[index] = value;
086: }
087:
088: public byte getBinaryDataElement(Integer id, int index)
089: throws Exception {
090: return getLOBHome().findByPrimaryKey(id).getBinaryData()[index];
091: }
092:
093: public void setValueHolderValue(Integer id, String value)
094: throws Exception {
095: getLOBHome().findByPrimaryKey(id).getValueHolder().setValue(
096: value);
097: }
098:
099: public String getValueHolderValue(Integer id) throws Exception {
100: return getLOBHome().findByPrimaryKey(id).getValueHolder()
101: .getValue();
102: }
103:
104: public void setCleanGetValueHolderValue(Integer id, String value)
105: throws Exception {
106: getLOBHome().findByPrimaryKey(id).setCleanGetValueHolder(
107: new ValueHolder(value));
108: }
109:
110: public void modifyCleanGetValueHolderValue(Integer id, String value)
111: throws Exception {
112: getLOBHome().findByPrimaryKey(id).getCleanGetValueHolder()
113: .setValue(value);
114: }
115:
116: public String getCleanGetValueHolderValue(Integer id)
117: throws Exception {
118: return getLOBHome().findByPrimaryKey(id)
119: .getCleanGetValueHolder().getValue();
120: }
121:
122: public String getStateFactoryValueHolderValue(Integer id)
123: throws Exception {
124: return getLOBHome().findByPrimaryKey(id)
125: .getStateFactoryValueHolder().getValue();
126: }
127:
128: public void modifyStateFactoryValueHolderValue(Integer id,
129: String value) throws Exception {
130: getLOBHome().findByPrimaryKey(id).getStateFactoryValueHolder()
131: .setValue(value);
132: }
133:
134: public void setStateFactoryValueHolderValue(Integer id, String value)
135: throws Exception {
136: ValueHolder holder = getLOBHome().findByPrimaryKey(id)
137: .getStateFactoryValueHolder();
138: holder.setValue(value);
139: holder.setDirty(true);
140: }
141:
142: // SessionBean implementation
143:
144: /**
145: * @exception CreateException Description of Exception
146: * @ejb.create-method
147: */
148: public void ejbCreate() throws CreateException {
149: }
150:
151: public void ejbActivate() {
152: }
153:
154: public void ejbPassivate() {
155: }
156:
157: public void ejbRemove() {
158: }
159:
160: public void setSessionContext(SessionContext ctx) {
161: }
162:
163: // Private
164:
165: private LOBHome getLOBHome() {
166: if (lobHome == null) {
167: try {
168: InitialContext initialContext = new InitialContext();
169: Object home = initialContext
170: .lookup(LOBHome.LOB_HOME_CONTEXT);
171: lobHome = (LOBHome) PortableRemoteObject.narrow(home,
172: LOBHome.class);
173: } catch (Exception e) {
174: throw new EJBException("Could not lookup "
175: + LOBHome.LOB_HOME_CONTEXT);
176: }
177: }
178: return lobHome;
179: }
180: }
|