David Yuan

Greenhorn
+ Follow
since Mar 01, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Yuan

my answers:
Which of the following are true about SSL?
a. SSL facilitates secure communication
b. SSL is a high level protocol and sits on top of HTTP
c. SSL is a low level protocol and sits below HTTP
d. SSL works only with HTTP
ANSWER: a,c
------------------------------------------------------
Select the correct sentences from below
a. In the mediator pattern the individual Objects participating in the collaboration maintain direct references to each other
b. Facade pattern is used to provide a simple interface to a subsystem comprising of a large number of objects.
c. Memento pattern preserves Encapsulation boundaries whil exposing an object's internal state
d. State pattern is used for operations that have large number of conditional statements based on the Object's state
ANSWER: b,c & d
---------------------------------------------------------------------------Which of the following are true about the Observer pattern ...
a. The subject is the publisher of the message and the Observer is the subscriber of the message notification
b. Observers can be dynamically added.
c. The Observer pattern supports broadcast communications
d. It promotes loose coupling between senders of messages and receivers of messages during communication
e. None of the above
ANWSER: a, b,c & d. B is correct since we can add subscriber to the subject on the fly. Applications of the Observer pattern include the JMS and Loosely Coupled Events (LCE) in COM+. In JMS you can dynamically add message listener to the topic. In LCE you can add subscriber dynamically too.
---------------------------------------------------------------------------When is unsetEntityContext() invoked on an Entity bean?
a. When the entity bean is to be garbage collected
b. After an entity bean is garbage collected
c. after the finalize() method has been invoked on the EntityBean
d. None of the above
ANWSER: a. True the EJB spec doens't say it is GCed after the method is called, but in the specs 2.1 Page 185, the life cycle diagram says that after unsetEntityContext is called, the bean doesn't exist. If this doesn't mean it is garbage collected, what else can it mean?
-David
Hi All,
I had a some questions regarding BMT.
1. How is the container managing the lifetime of the UserTransaction in the Context object? When is it created and when is it destroyed?
2. Does the UserTransaction propagate automatically when a BMT bean calls another BMT bean? And does it propagate when a BMT bean calls a CMT, and vice versa?
3. How can one specify the Transaction Attibute in the ejb-jar-xml for a BMT bean? Do we need to specify "Require" or something?
-David
I found some code snippet from the section of "17.3.3 Enterprise Beans Using Bean-Managed Transaction Demarcation" of EJB spec 2.1.
Basically it demonstrate how the BMT get the UserTransaction with a call to ejbContext.getUserTransaction(), and get the connection factory from JNDI. I didn't see any code to enlist the connection in the UserTransaction. There I assume it is enlisted automatically. Right? (Sorry if this is a newbie question since I am from a COM+/DTC background. )
-David
Hi All,
I read in some Notes that for code brevity's sake, one can create a connection in ebjCreate (for SB) or setEntityContext (for EB), and close the connection in ejbRemove(for SB) or unsetEntityContext (for EB).
I never did that in my programming, so I am curirous that if we do this, how can we manage the transaction? If we use CMT, will the connection automatically enlist in the Tx in each busines method? And if we use BMT, how can we enlist the connection at the beginning of each business method and unenlist it before exiting?
A code snippet would be appreciated!
-David.
The paragraph is copied from A. Ramu Meda's Bullet Notes:
"With bean-managed persistence, when the EJB container moves an instance from the pooled state to the ready state, it does not automatically set the primary key. Therefore, the ejbCreate and ejbActivate methods must set the primary key. "
I don't quite understand what it is saying here. I checked the sample code for BMP bean from Ed Roman's bok MEJB 2rd Ed. The ejbCreate returns a primary key, but ejbActivate doesn't nothing related to the primary key.
public AccountPK ejbCreate(String accountID, String ownerName)
throws CreateException {
PreparedStatement pstmt = null;
Connection conn = null;
try {
System.out.println("ejbCreate() called.");
this.accountID = accountID;
this.ownerName = ownerName;
this.balance = 0;
/*
* Acquire DB connection
*/
conn = getConnection();
/*
* Insert the account into the database
*/
pstmt = conn.prepareStatement(
"insert into accounts (id, ownerName, balance)"
+ " values (?, ?, ?)");
pstmt.setString(1, accountID);
pstmt.setString(2, ownerName);
pstmt.setDouble(3, balance);
pstmt.executeUpdate();
/*
* Generate the Primary Key and return it
*/
return new AccountPK(accountID);
}
catch (Exception e) {
throw new CreateException(e.toString());
}
finally {
/*
* Release DB Connection for other beans
*/
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) {}
try { if (conn != null) conn.close(); }
catch (Exception e) {}
}
}
public void ejbActivate() {
System.out.println("ejbActivate() called.");
}
Can somebody explain what's the quoted paragraph is saying in more detail? Thanks!
-David.
Ajith,
Thanks! The .pdf is great!
-David.
Oops, I found out the answer. The EJB specs does say to throw an EJBException will doom the Tx.
In section "18.2.2 System Exceptions", it says:
The Bean Provider can rely on the container to perform the following tasks when catching a non-application exception:
� The transaction in which the bean method participated will be rolled back.
� No other method will be invoked on an instance that threw a non-application exception.
-David
Hi All,
I am seeing a mock test question that asks if to throw a EJBException from a CMT bean will roll back the current transaction if any.
I searched in EJB specs, all I found that is to throw a Application exception will not doom the transaction. I don't see it mentions anywhere if to throw an EJBException will doom the Tx.
So I am at a loss, can somebody share some insight on this?
-David
I had a mock test, and a Qs asks that Applet can connect to the website from which it is downloaded with socket. I know this is true, but I do remember from some previous reading that this can be forbidden by configuration. Is my memory wrong?
-David.
Ming Hu,
Yes, that's exactly what I am thinking of...
-David.
The reason that I can think of so far for ejbCreate being left out of the SessionBean is there is no way to define a universal ejbCreate in the interface. The home interface's create and the remote interface's ejbCreate can have different parameters, which can't be predicted by the EJB spec authors.
Therefore they simply left it out of the interface of SessionBean, and mark it as a "Must" in the specs. Am I right?
-David.
Hi Viktor,
Thank you for your reply. I understand SessionBean doesn't define ejbCreate, and neither EJBHome nor EJBLocalHome defines "create" method. What I don't know is the purpose for this design.
To me, it doesn't appear to be a careless mistake of the EJB designers. Therefore I am just wondering about the reason behind.
Regards,
David
Hi All,
Sorry if this is a FAQ. But I am curious why SessionBean interface
doesn't have the ejbCreate defined?
If ejbCreate is optional, we can create a Session Bean that can never
be created. Can somebody explain it?
Below is the definition of the interface:
public interface javax.ejb.SessionBean
extends javax.ejb.EnterpriseBean
{
public void setSessionContext(SessionContext ctx);
public void ejbPassivate();
public void ejbActivate();
public void ejbRemove();
}
Thank you for any insights in advance.
-David