001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.core.cmp.jpa;
018:
019: import org.apache.openejb.core.cmp.cmp2.SetValuedCmr;
020: import org.apache.openejb.core.cmp.cmp2.Cmp2Entity;
021: import org.apache.openejb.core.CoreDeploymentInfo;
022: import org.apache.openejb.core.DeploymentContext;
023: import org.apache.openejb.BeanType;
024: import org.apache.openejb.SystemException;
025:
026: import javax.ejb.EntityBean;
027: import javax.ejb.EntityContext;
028: import java.util.HashSet;
029: import java.util.Set;
030:
031: public class BookBean implements EntityBean, Cmp2Entity {
032: public static Object deploymentInfo;
033: static {
034: try {
035: deploymentInfo = new CoreDeploymentInfo(
036: new DeploymentContext("book", Book.class
037: .getClassLoader(), null), BookBean.class,
038: null, null, BookHome.class, Book.class, null, null,
039: null, String.class, BeanType.CMP_ENTITY);
040: ((CoreDeploymentInfo) deploymentInfo).createMethodMap();
041: } catch (SystemException e) {
042: throw new RuntimeException(e);
043: }
044: }
045:
046: private transient boolean deleted;
047:
048: private String title;
049: private Set<AuthorBean> authors = new HashSet<AuthorBean>();
050: private transient SetValuedCmr authorsCmr = new SetValuedCmr(this ,
051: "authors", AuthorBean.class, "books");
052:
053: public BookBean() {
054: }
055:
056: public BookBean(String title) {
057: this .title = title;
058: }
059:
060: public String getTitle() {
061: return title;
062: }
063:
064: public void setTitle(String title) {
065: this .title = title;
066: }
067:
068: public Set getAuthors() {
069: return authorsCmr.get(authors);
070: }
071:
072: public void setAuthors(Set authors) {
073: authorsCmr.set(this .authors, authors);
074: }
075:
076: public Object OpenEJB_getPrimaryKey() {
077: return title;
078: }
079:
080: public void OpenEJB_deleted() {
081: if (deleted)
082: return;
083: deleted = true;
084:
085: authorsCmr.deleted(authors);
086: }
087:
088: public Object OpenEJB_addCmr(String name, Object bean) {
089: if (deleted)
090: return null;
091:
092: if ("authors".equals(name)) {
093: authors.add((AuthorBean) bean);
094: return null;
095: }
096:
097: throw new IllegalArgumentException("Unknown cmr field " + name
098: + " on entity bean of type " + getClass().getName());
099: }
100:
101: public void OpenEJB_removeCmr(String name, Object value) {
102: if (deleted)
103: return;
104:
105: if ("authors".equals(name)) {
106: authors.remove(value);
107: return;
108: }
109:
110: throw new IllegalArgumentException("Unknown cmr field " + name
111: + " on entity bean of type " + getClass().getName());
112: }
113:
114: public void ejbActivate() {
115: }
116:
117: public void ejbLoad() {
118: }
119:
120: public void ejbPassivate() {
121: }
122:
123: public void ejbRemove() {
124: }
125:
126: public void ejbStore() {
127: }
128:
129: public void setEntityContext(EntityContext entityContext) {
130: }
131:
132: public void unsetEntityContext() {
133: }
134: }
|