Container Managed Persistence
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Joydip_Kanjilal
Posted On:   Thursday, May 17, 2001 03:04 AM

I am trying for a Container Managed Persistence with WebLogic Server 3.1.5 and JDBC-ODBC Bridge and the JTS driver. When I am using the DDCreator utility it is failing to create the serialized instance of the deployment descriptor. I have created a pool in the name of ejbPool in the WebLogic.properties file. The code is taken from the book of EJB by Tom Valesky. The .java files are compiling perfectly. I am giving below all the files. Pl. send me the solution. My e-mail addresses are :-- joydip_kanjilal@usa.net joydip_kanjilal@123india.com The Deployment Descriptor:--- (EntityDescriptor ; For entity EJBeans, this file must start with "(EntityDescriptor"    More>>

I am trying for a Container Managed Persistence with WebLogic Server 3.1.5 and JDBC-ODBC Bridge and the JTS driver.
When I am using the DDCreator utility it is failing to create the serialized instance of the deployment descriptor.
I have created a pool in the name of ejbPool in the WebLogic.properties file.
The code is taken from the book of EJB by Tom Valesky. The .java files are compiling perfectly.

I am giving below all the files. Pl. send me the solution. My e-mail addresses are :--
joydip_kanjilal@usa.net
joydip_kanjilal@123india.com


The Deployment Descriptor:---


(EntityDescriptor
; For entity EJBeans, this file must start with "(EntityDescriptor"
; For session EJBeans, this file must start with "(Session Descriptor"

beanHomeName OrderHome
; JNDI name of EJBean

enterpriseBeanClassName order.OrderBean
; The EJBean class

homeInterfaceClassName order.OrderHome
; The home interface implemented by a class generated by
; the EJB compiler (ejbc).
; See "homeClassName" below to plug in your own home class.

remoteInterfaceClassName order.Order
; This interface is implemented by an "EJBObject", a wrapper
; class that is generated by the EJB compiler (ejbc). This wrapper
; interposes between a caller and the EJBean, and deals with
; concurrency, transactions and security. See "ejbObjectClassName"
; below to plug in your own EJBObject class.

isReentrant false
; Either "true" or "false".
; If true, the same transaction is allowed to revisit a a EJBean.
; If the EJBean does not support transactions or if a transaction
; is not active, a lock is taken out on behalf of the EJBObject.
; Session EJBeans cannot be reentrant; this property must be "false".

(accessControlEntries
; DEFAULT [admin guest paul]
; Specifies security access control for the EJBean as a whole (under
; the DEFAULT entry), and/or provide method-specific access control
; entries.
;
; [For additional information on WebLogic security, please see
; the Tengah Developer Guide "Using Tengah ACLs (Access Control Lists)"
; available at http://www.weblogic.com/classdocs/API_acl.html.]
;
; Names in the entries represent user names or role names. Roles
; map to groups, and it is up to the associated realm to judge
; which string is a user name and which is a role.
; The realm can be specified by setting the "realmClass" property below.
; Methods with the same name but with different signatures can be
; distinguished by supplying the complete method signature.
;
; Example:
; DEFAULT [admin guest paul]
; deposit [everyone]
; "withdraw(double)" [paul john]
; "withdraw(int)" [amadeus admin]
;
; Note:
; The method name is that of the corresponding home or remote interface,
; not of the EJBean itself. (After all, you are controlling access from
; outside.) Method names that are not single words must be enclosed in
; double quotes(").
); end accessControlEntries

(controlDescriptors
; This section decides the run-time properties when a method is called.
; The DEFAULT sub-section applies to all methods, but can be overridden
; on a per-method basis, similar to the "accessControlEntries" above.
(DEFAULT
isolationLevel TRANSACTION_SERIALIZABLE
; Sets the JDBC transaction isolation level
;
; TRANSACTION_READ_UNCOMMITTED
; Dirty reads, non-repeatable reads and phantom reads can occur.
;
; TRANSACTION_READ_COMMITTED
; Dirty reads prevented; non-repeatable and phantom reads possible.
;
; TRANSACTION_REPEATABLE_READ
; Dirty and non-repeatable reads prevented; phantom reads possible.
;
; TRANSACTION_SERIALIZABLE
; The strictest isolation level; all of the above problems avoided.

transactionAttribute TX_REQUIRES_NEW
; TX_BEAN_MANAGED EJBean starts and ends transaction.
; TX_MANDATORY Caller must start transaction.
; TX_REQUIRED EJBean requires a transaction, Tengah will
; start one if caller hasn't already done so.
; TX_NOT_SUPPORTED Tengah suspends caller's transaction
; before calling EJBean.
; TX_REQUIRES_NEW Tengah starts a new transaction for every call.
; TX_SUPPORTS Tengah simply passes the caller's transaction along.

runAsMode CLIENT_IDENTITY
; This option sets the effective user identity; options are:
; CLIENT_IDENTITY The caller's identity is passed to the EJBean.
; SPECIFIED_IDENTITY See "runAsIdentity" below.
; SYSTEM_IDENTITY "system" in the weblogic realm.

; runAsIdentity paul
; If "runAsMode" is set to SPECIFIED_IDENTITY, assume the identity
; given by "runAsIdentity" before passing the call to the EJBean.
); end DEFAULT
); end controlDescriptors

(environmentProperties
; realmName "my.realm"
orderBean.databaseURL "jdbc:weblogic:jts:ejbPool"
orderBean.JDBCDriverName "weblogic.jdbc.jts.Driver"

; The entity responsible for authenticating users with
; their passwords or other credentials.
; Defaults to the "weblogic" realm.

; homeClassName
; For a home interface called "Foo", the EJB compiler generates
; an implementation called "FooHomeImpl". You can inherit from
; it and override or provide new methods in a custom class, by
; specifying that class's name for this property.

; ejbObjectClassName
; For a remote interface called "Foo", the EJB compiler generates
; an implementation called "FooEOImpl". You can inherit from
; it and override or provide new methods in a custom class, by
; specifying that class's name for this property.

maxBeansInFreePool 20
; Tengah EJB maintains a free pool of beans for every bean class.
; This property decides the size of the pool.

maxBeansInCache 100
; Maximum number of objects of this class that are allowed in memory.
; Objects are kept in an LRU chain, and the ones dropped from the
; end of the chain are passivated.

idleTimeoutSeconds 10
; The LRU chain (see "maxBeansInCache" above) is scrubbed of
; inactive objects after at least this many seconds

; isModifiedMethodName isModified
; Applicable only to entity EJBeans.
; The name of the EJBean method called when the EJBean is stored.
; If a method is not specified, Tengah always assumes that the EJBean
; has been modified and always saves it. Providing a method and setting
; it as appropriate will improve performance.

(finderDescriptors
; Container managed beans only
; This property applies to all persistent storage types,
; and can be overridden by an equivalent property in
; a specific persistent storage type.
;
; The finder properties are pairs of finder method signatures
; and expressions. The methods are used to find EJBeans and
; always return an enumeration of EJBeans.
; The expression notation is not fixed, and
; will change in the future.
; Currently, finderDescriptors only work for persistentStoreType "jdbc"
;
; Current expression prefix notation:
; operator operand1 [operand2]
;
; where:
; operator can be one of:
; "(", ")", "=", " <", ">", " <=", ">=",
; "!" [not], "&" [and], "|" [or], "like"
;
; operand can be one of:
; another expression, an EJBean attribute or,
; when preceeded by "$", a finder method parameter
;
; Example expression; tests if balance is > amount:
;
; "> balance $amount"
;
; Compound expressions can be used;
; note use of single quotes (') to distinguish strings :
;
; "(& (> balance $amount) (! (= accountType 'checking')))"
;
"findByCustID(int custidnum)" "(= custid $custidnum)"
; "findLargeAccounts(double amount)" "> balance $amount"
; This is converted to a "findLargeAccounts" method
; in the generated persistent storage class, which
; returns an enumeration of beans of this class
; that satisfy this expression.
); end finderDescriptors

(persistentStoreProperties
; This section specifies the persistent store properties for
; entity EJBeans with container-managed persistence and
; stateful session EJBeans.
; For entity EJBeans with EJBean-managed persistence and
; stateless session EJBeans, this section is not required.

persistentStoreType jdbc
; Either "file", "jdbc" or a custom type.
; The type is used to identify the specific section below
; that provides additional information for setting up
; the appropriate persistent storage.

; persistentStoreClassName
; For specifying a custom persistent store that can store the EJBean.
; When you specify either "file" or "jdbc" as the "persistentStoreType",
; the EJB compiler automatically generates classes for making
; the EJBean persistent. If you want to use a different persistent storage,
; you can specify that class name here. This class must implement the
; weblogic.ejb.pstore.PersistentStore interface.
; Note: As this feature is still in development, there currently isn't
; a published API for using a custom persistentStoreClassName.
; A future release will include documentation and
; a published API for the interface.

(jdbc
; If the "persistentStoreType" is "jdbc", the following
; object-relational mapping information is applied.

tableName orders
; Ensure that table "ejbAccounts" is already created
; in the database using an appropriate SQL statement such as:
; "create table ejbAccounts (id varchar(15), bal float)"
; Otherwise, a run-time exception will be thrown.

dbIsShared true
; Either "true" or "false".
; If this is true, caching is turned off, because
; Tengah knows it doesn't "own" the table.

poolName ejbPool
; Either you specify a pool, or specify the JDBC driver URL and
; driver name. The pool is preferable for performance reasons;
; it must be setup in the weblogic.properties file.

; driverURL
; driverName weblogic.jdbc.jts.Driver

(attributeMap
; Maps the EJBean attributes to database column names
; EJBean attribute Database column name
; -----------------------------------------
custid CUST_ID
itemcode ITEMCODE
quantity QUANTITY
); end attributeMap
); end jdbc

(file
persistentDirectoryRoot c:mystore
; If specified, all instances of an EJBean
; (example: "examples.ejb.AccountBean")
; are stored under the "persistentDirectoryRoot"
; (example: "c:mystoreexamples_ejb_AccountBean .db")
; with the name of the EJBean converted to a directory name.
; Defaults to a directory "mystore" in the directory
; where Tengah was started.

); end file

); end persistentStoreProperties
); end environmentProperties

; Entity EJBean-specific properties:
; For entity EJBeans you must specify the primary key class and
; (if applicable) the container-managed attributes.

primaryKeyClassName order.OrderPK
; Note that for container-managed persistence (according to
; the EJB 1.0 spec) you must have a custom class for the
; primary key -- "java.lang.String" won't do.
; For EJBean-managed persistence, it can be any class.

containerManagedFields [custid itemcode quantity]
; For container-managed persistence only.
; The list of public non-transient attributes of the EJBean
; that are to be made persistent.
; To include all EJBean attributes without having to
; enumerate them by name, use:
; containerManagedFields *

; end entity EJBean-specific properties

; Session EJBean-specific properties:
; For session EJBeans you must specify the state management type
; and the session time out in seconds.

; stateManagementType STATELESS_SESSION
; Either STATELESS_SESSION or STATEFUL_SESSION.
; The type of session EJBean.

; sessionTimeout 10; seconds

; end session EJBean-specific properties

); end EntityDescriptor or SessionDescriptor



The Remote Interface:---


package order;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;

public interface Order extends EJBObject
{
//note: no setCustID or setItemCode-- these are part of the primary key
public void setQuantity(int quantity) throws RemoteException;
public int getCustID() throws RemoteException;
public String getItemCode() throws RemoteException;
public int getQuantity() throws RemoteException;
}



The Home Interface:---

package order;
import javax.ejb.EJBHome;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;

public interface OrderHome extends EJBHome
{

public Order create(int custid, String itemcode, int quantity) throws RemoteException, CreateException;
public Order findByPrimaryKey(OrderPK pk) throws RemoteException, FinderException;
public java.util.Enumeration findByCustID(int custid) throws RemoteException, FinderException;
}


The Bean Class:---




package order;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;

public class OrderBean implements EntityBean
{

transient private EntityContext ctx;
public int custid;
public String itemcode;
public int quantity;

public void setEntityContext(EntityContext ctx)
{
this.ctx = ctx;
}
public void unsetEntityContext()
{
this.ctx = null;
}


public void ejbCreate(int custid, String itemcode, int quantity) throws CreateException
{

this.custid = custid;
this.itemcode = itemcode;
this.quantity = quantity;


}


public void ejbPostCreate(int custid, String itemcode, int quantity) throws CreateException
{
}


public void ejbActivate()
{


}

public void ejbPassivate()
{


}

public void ejbRemove()
{


}

public void ejbLoad()
{

}

public void ejbStore()
{

}


public void setQuantity(int quantity)
{
this.quantity = quantity;
}
public int getCustID()
{
return this.custid;
}
public String getItemCode()
{
return this.itemcode;

}
public int getQuantity()
{
return this.quantity;

}

}



The Client:---


package order;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.rmi.RemoteException;
import javax.ejb.RemoveException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import java.util.Enumeration;

public class OrderClient
{
public static void main(String[] argv)
{

System.out.println("client is running");
try
{
InitialContext ic = new InitialContext();
System.out.println("looked up initial context");
OrderHome oh = (OrderHome) ic.lookup("order.OrderHome");
System.out.println("looked up home interface");
Order o1 = oh.create(1, "1", 1);
Order o2 = oh.create(1, "2", 2);
System.out.println("created remote interface");
Enumeration e = oh.findByCustID(1);
Order o;
while (e.hasMoreElements())
{
System.out.println("found another");
o = (Order) e.nextElement();
System.out.println("custID: " + o.getCustID());
System.out.println("itemcode: " + o.getItemCode());
System.out.println("quantity: " + o.getQuantity());
System.out.println("removing...");
o.remove();
System.out.println("removed");
}

System.out.println("done with OrderClient");

}
catch (FinderException e)
{
System.out.println("FinderException caught");
e.printStackTrace();

}
catch (NamingException e)
{
System.out.println("NamingException caught");
e.printStackTrace();
}
catch (RemoveException e)
{
System.out.println("RemoveException caught");
e.printStackTrace();
}
catch (CreateException e)
{
System.out.println("CreateException caught");
e.printStackTrace();
}

catch (RemoteException e)
{
System.out.println("RemoteException caught");
e.printStackTrace();
}
}
}


The Manifest File:---

Name: order/Order.ser
Enterprise-Bean: True




Please let me know the rectified files at ur earliest. I am not getting how and where to specify the ejbPool and the driver information in the Deployment Descriptor File. Pl. let me know the detailed steps.

   <<Less
About | Sitemap | Contact