KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > container > EntityBean


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EntityBean.java,v 1.4 2004/12/01 13:35:34 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.container;
27
28 import org.objectweb.jonas_ejb.container.EntityCounters;
29 import org.objectweb.jonas_ejb.container.JEntityFactory;
30 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
31
32 /**
33  * This class implements the EntityBean type specified in JSR77
34  * @author Adriana Danes
35  *
36  */

37 public class EntityBean extends EJB {
38
39     // lock policy
40
private static final int LOCK_CONTAINER_READ_UNCOMMITTED = EntityDesc.LOCK_CONTAINER_READ_UNCOMMITTED;
41     private static final int LOCK_CONTAINER_SERIALIZED = EntityDesc.LOCK_CONTAINER_SERIALIZED;
42     private static final int LOCK_CONTAINER_READ_COMMITTED = EntityDesc.LOCK_CONTAINER_READ_COMMITTED;
43     private static final int LOCK_DATABASE = EntityDesc.LOCK_DATABASE;
44     private static final int LOCK_READ_ONLY = EntityDesc.LOCK_READ_ONLY;
45
46     private String JavaDoc persistency;
47
48     public EntityBean(String JavaDoc objectName, JEntityFactory factoryToManage, String JavaDoc persistency) {
49         super(objectName, factoryToManage);
50         this.persistency = persistency;
51     }
52
53     /**
54      * get persistency type
55      */

56     public String JavaDoc getPersistency() {
57         return persistency;
58     }
59
60     /**
61      * get passivation time out
62      * @return passivation timeout in seconds
63      */

64     public int getPassivationTimeOut() {
65         return ejbToManage.getContainer().getSwapTime();
66     }
67
68     /**
69      * set passivation time out
70      * @param timeOut passivation timeout in seconds
71      */

72     public void setPassivationTimeOut(int timeOut) {
73         ejbToManage.getContainer().setSwapTime(timeOut);
74     }
75
76     /**
77      * get inactivity time out
78      * @return inactivity timeout in seconds
79      */

80     public int getInactivityTimeOut() {
81         return ((JEntityFactory) ejbToManage).getInactivityTimeout();
82     }
83
84     /**
85      * @return true if bean is shared
86      */

87     public boolean getShared() {
88         return ((JEntityFactory) ejbToManage).isShared();
89     }
90
91     /**
92      * @return min-pool-size value
93      */

94     public int getMinPoolSize() {
95         return ((JEntityFactory) ejbToManage).getMinPoolSize();
96     }
97
98     /**
99      * @return max-cache-size value
100      */

101     public int getMaxCacheSize() {
102         return ((JEntityFactory) ejbToManage).getMaxCacheSize();
103     }
104
105     /**
106      * @return pool-size value
107      */

108     public int getPoolSize() {
109         return ((JEntityFactory) ejbToManage).getPoolSize();
110     }
111
112     /**
113      * @return EJB Container lock policy
114      */

115     public String JavaDoc getLockPolicy() {
116         int lockPolicy = ((JEntityFactory) ejbToManage).lockPolicy();
117         String JavaDoc sLockPolicy = null;
118         switch (lockPolicy) {
119             case LOCK_CONTAINER_READ_UNCOMMITTED:
120                 sLockPolicy = "container-read-uncommitted";
121                 break;
122             case LOCK_CONTAINER_SERIALIZED:
123                 sLockPolicy = "container-serialized";
124                 break;
125             case LOCK_CONTAINER_READ_COMMITTED:
126                 sLockPolicy = "container-read-committed";
127                 break;
128             case LOCK_DATABASE:
129                 sLockPolicy = "database";
130                 break;
131             case LOCK_READ_ONLY:
132                 sLockPolicy = "read-only";
133                 break;
134         }
135         return sLockPolicy;
136     }
137
138     public boolean getPrefetch() {
139         return ((JEntityFactory) ejbToManage).isPrefetch();
140     }
141     /**
142      * @return Cache Size value
143      */

144     public int getCacheSize() {
145         return ((JEntityFactory) ejbToManage).getCacheSize();
146     }
147
148     /**
149      * Instance Counters (inTx, outTx, idle, passive, removed)
150      * @return table of int values for Entity counters
151      */

152     public Integer JavaDoc[] getEntityCounters() {
153         EntityCounters ec = ((JEntityFactory) ejbToManage).getEntityCounters();
154         Integer JavaDoc[] result = new Integer JavaDoc[5];
155         result[0] = new Integer JavaDoc(ec.inTx);
156         result[1] = new Integer JavaDoc(ec.outTx);
157         result[2] = new Integer JavaDoc(ec.idle);
158         result[3] = new Integer JavaDoc(ec.passive);
159         result[4] = new Integer JavaDoc(ec.removed);
160         return result;
161     }
162
163     /**
164      * Synchronize bean state for all its instances outside transactions
165      */

166     public void synchronize() {
167         ((JEntityFactory) ejbToManage).sync();
168     }
169
170     /**
171      * Reduce number of instances in memory
172      */

173     public void reduceCache() {
174         ((JEntityFactory) ejbToManage).reduceCache();
175     }
176 }
177
Popular Tags