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.Cmp2Entity;
020: import org.apache.openejb.core.cmp.cmp2.SetValuedCmr;
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.Set;
029: import java.util.HashSet;
030:
031: public class AuthorBean implements EntityBean, Cmp2Entity {
032: public static Object deploymentInfo;
033: static {
034: try {
035: deploymentInfo = new CoreDeploymentInfo(
036: new DeploymentContext("author", Author.class
037: .getClassLoader(), null), AuthorBean.class,
038: null, null, AuthorHome.class, Author.class, null,
039: null, 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 name;
049: private Set<BookBean> books = new HashSet<BookBean>();
050: private transient SetValuedCmr booksCmr = new SetValuedCmr(this ,
051: "books", BookBean.class, "authors");
052:
053: public AuthorBean() {
054: }
055:
056: public AuthorBean(String name) {
057: this .name = name;
058: }
059:
060: public String getName() {
061: return name;
062: }
063:
064: public void setName(String name) {
065: this .name = name;
066: }
067:
068: public Set getBooks() {
069: return booksCmr.get(books);
070: }
071:
072: public void setBooks(Set books) {
073: booksCmr.set(this .books, books);
074: }
075:
076: public Object OpenEJB_getPrimaryKey() {
077: return name;
078: }
079:
080: public void OpenEJB_deleted() {
081: if (deleted)
082: return;
083: deleted = true;
084:
085: booksCmr.deleted(books);
086: }
087:
088: public Object OpenEJB_addCmr(String name, Object bean) {
089: if (deleted)
090: return null;
091:
092: if ("books".equals(name)) {
093: books.add((BookBean) 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 ("books".equals(name)) {
106: books.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: }
|