Dirk Haase wrote:
> Hi Jim,
>
> it works fine for me, too. It's just that I was confused that ejbStore
> was called even though the Bean was not stored. This is the sample code:
>
> public void ejbStore() {
>
> System.out.println("storing...");
> }
>
> public boolean isModified() {
>
> return false;
> }
>
> and the line in the properties file:
>
> isModifiedMethodName isModified
>
> of course, this is only sample code. I changed the value of some
> persistent fields and it did not update the database because isModified
> always returned false. But by the output I could tell that ejbStore()
> was called.
>
> But apparenty, like Eric Richardson wrote, this is how it is supposed to
> be.
Hi,
This may help.
Here is the explanation Phillipe gave.
Eric :-)
Hi Eric,
If you have a look in the archive of jonas-users mailing list you can
find
that I have already answered to this question. Here is the answer I have
made
some time ago:
in fact the data are nor loaded at instantiation time but at the call
of the first business method inside a transaction.
If you are in Container Managed Persistence the container read
the managed field just before to call the Bean in ejbLoad.
Synchronization objects are associated to the instances of the beans
these objects are notified of the beginning of the commit process
by the beforeCompletion() operation. this method call the bean in
ejbStore and then update the state of the entity in the database.
The problem is that if we do transaction with methods that doesn't
change the state the bean the container will still perform database
updates.
If you are outside a transaction the container must write the contents
of the bean after every invocation
as the container has no way of knowing that the bean's contents haven't
been modified by the invocation.
In order to improve performance we have implemented in JOnAS (but it is
not documented((I don't know why...)) the isModified extension of
Weblogic.
Before performing an update the container will call a method of the bean
(whose name is indicated in the isModifiedMethodName of the
EnvironmentProperties). this method is responsible to tell if the state
of the bean has been changed.
This mechanism is illustrated in attached files.
Philippe
Philippe Coq Groupe Bulll/BullSoft/OpenMaster Phone: (33) 04 76 29 78
49
Bull S.A - 1 rue de Provence - 38432 Echirolles Cedex France
[EMAIL PROTECTED] http://www-frec.bull.com
Download our EJBServer at http://www.bullsoft.com/ejb
//Title: Introduction to Enterprise JavaBeans on the AS/400 System
//Version:
//Copyright: Copyright (c) 1999
//Author: ITSO
//Company: IBM
//Description:
package com.ibm.itso.roch.cpwejb.server;
import java.rmi.*;
import javax.ejb.*;
import java.math.*;
import com.ibm.itso.roch.cpwejb.interfaces.*;
/**
* Represents an item.
*
* @author ITSO
*/
public class ItemBean implements EntityBean {
// public instance data which is persisted
public String ivItemID;
public String ivItemName;
public float ivItemPrice;
public String ivItemInfo;
// private instance data which is not persisted
private EntityContext entityContext;
private transient boolean isDirty;
/**
* Indicates whether the state of the item bean has been modified
*
* @return a boolean indicator. If true, the item bean has been
modified. If
* false, the item bean has not been modified.
*/
public boolean isModified() {
return isDirty;
}
/**
* Sets a flag to indicate whether the state of the item bean has been
modified
*
* @param flag a boolean indicator. If true, the item bean has been
modified. If
* false, the item bean has not been modified.
*/
public void setModified(boolean flag) {
isDirty = flag;
}
/**
* Creates an item bean
*
* @throws RemoteException if an RMI exception occurs
*
* @throws CreateException if the item cannot be created
*
* @param id an int which represents the item id
*
* @param name a String which represents the item name
*
* @param price a float which represents the item's price
*
* @param data a String which contains additional information about the
item
*/
public void ejbCreate(String id, String name, float price, String data)
throws RemoteException, CreateException {
ivItemID = id;
ivItemName = name;
ivItemPrice = price;
ivItemInfo = data;
return;
}
/**
* Does nothing in this implementation
*/
public void ejbPostCreate(String id, String name, float price, String
data) throws RemoteException, CreateException {
// Nothing to do in this implementation
}
/**
* Does nothing in this implementation
*/
public void ejbActivate() throws RemoteException {
// Nothing to do in this implementation
setModified(true); // Line added by BULL
}
/**
* Loads the item's state from persistent storage
*
* @throws RemoteException if an RMI exception occurs
*/
public void ejbLoad() throws RemoteException {
setModified(false);
}
/**
* Does nothing in this implementation
*/
public void ejbPassivate() throws RemoteException {
// Nothing to do in this implementation
}
/**
* Does nothing in this implementation
*/
public void ejbRemove() throws RemoteException, RemoveException {
// Nothing to do in this implementation
}
/**
* Stores the item's state in persistent storage
*
* @throws RemoteException if an RMI exception occurs
*/
public void ejbStore() throws RemoteException {
setModified(false);
}
/**
* Sets the context for the item bean
*
* @throws RemoteException if an RMI exception occurs
*
* @param context an EntityContext which represents the item bean's
context
*/
public void setEntityContext(EntityContext context) throws
RemoteException {
entityContext = context;
setModified(true); // Line added by BULL
}
/**
* Unsets the context for the item bean
*
* @throws RemoteException if an RMI exception occurs
*/
public void unsetEntityContext() throws RemoteException {
entityContext = null;
}
// public set and get methods
/**
* Gets the item id.
*
* @throws RemoteException if an RMI exception occurs
*
* @return a String which represents the item id
*/
public String getItemID() throws RemoteException {
return ivItemID;
}
/**
* Sets the item name
*
* @throws RemoteException if an RMI exception occurs
*
* @param name a String which represents the item name
*/
public void setItemName(String name) throws RemoteException {
ivItemName = name;
setModified(true);
}
/**
* Gets the item name
*
* @throws RemoteException if an RMI exception occurs
*
* @return a String which represents the item name
*/
public String getItemName() throws RemoteException {
return ivItemName;
}
/**
* Sets the item's price
*
* @throws RemoteException if an RMI exception occurs
*
* @param price a float which represents the price
*/
public void setItemPrice(float price) throws RemoteException {
ivItemPrice = price;
setModified(true);
}
/**
* Gets the item's price
*
* @throws RemoteException if an RMI exception occurs
*
* @return a float which represents the price
*/
public float getItemPrice() throws RemoteException {
return ivItemPrice;
}
/**
* Sets the item description
*
* @throws RemoteException if an RMI exception occurs
*
* @param info a String which contains additional information about the
item
*/
public void setItemInfo(String info) throws RemoteException {
ivItemInfo = info;
setModified(true);
}
/**
* Gets the item description
*
* @throws RemoteException if an RMI exception occurs
*
* @param a String which contains additional information about the item
*/
public String getItemInfo() throws RemoteException {
return ivItemInfo;
}
}
EntityDescriptor {
BeanHomeName =
"com.ibm.itso.roch.cpwejb.ItemHome";
EnterpriseBeanClassName =
com.ibm.itso.roch.cpwejb.server.ItemBean ;
HomeInterfaceClassName =
com.ibm.itso.roch.cpwejb.interfaces.ItemHome;
RemoteInterfaceClassName =
com.ibm.itso.roch.cpwejb.interfaces.Item;
PrimaryKeyClassName =
com.ibm.itso.roch.cpwejb.interfaces.ItemID;
Reentrant = false;
ControlDescriptors = {
{
IsolationLevel=TRANSACTION_SERIALIZABLE;
RunAsMode= CLIENT_IDENTITY;
TransactionAttribute = TX_REQUIRED;
};
};
EnvironmentProperties = "EProduct.properties";
ContainerManagedFields = {
ivItemID;
ivItemName;
ivItemPrice;
ivItemInfo;
};
}
datasource.name jdbc_1
isModifiedMethodName isModified
db.TableName EProduct
db.Field.ivItemID ProdId
db.Field.ivItemName Name
db.Field.ivItemPrice Price
db.Field.ivItemInfo Descrip
db.Finder.findAllItems
db.Finder.findByName where ? = Name
db.Finder.findByPrice where ? = Price
db.Finder.findCheaperItems where Price < ?
db.Finder.findMoreExpensiveItems where Price > ?
>
>
> dirk
>
> --
> Dirk Haase mailto: [EMAIL PROTECTED]
> ----
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body of the message "unsubscribe jonas-users".
> For general help, send email to [EMAIL PROTECTED] and
> include in the body of the message "help".
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".