Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean.

This page discusses - Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean.

Ads

Tutorials   
Chapter 5. Client View of an Entity Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements related to transactions and the identifica Given a list of responsibilities, identify whose which are the Container's with respect to transactions, including the handling of getRollbackOnly, setRollbackOnly, getUserTransacti EJB Transactional Attributes Chapter 11. Transactions Given a list of scenarios, identify which will result in an ejbRemove method not being called on a bean instance. Given a list of responsibilities related to session beans, identify those which are the responsibility of the session bean provider and those which are the responsibility of the EJB contai Given a list of methods for a stateful or stateless session bean class, define which of the following operations can be performed from each of those methods: SessionContext interface metho Chapter 4. Session Bean Life Cycle Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces. Identify the interface and method for each of the following: retrieve the session bean's remote home interface, retrieve the session bean's local component interface, determine if the sessio Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both. Chapter 14. Security Management Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag. Given a list of responsibilities, identify which belong to the deployer, bean provider, application assembler, container provider, system administrator, or any combination. From a list of responsibilities, identify which belong to the application assembler, bean provider, deployer, container provider, or system administrator. Part I. Exam Objectives Preface Identify the interfaces and methods a JMS message-driven bean must implement. Identify the use and behavior of the MessageDrivenContext interface methods. SCBCD Study Guide Given a list of responsibilities related to exceptions, identify those which are the bean provider's, and those which are the responsibility of the container provider. Be prepared to recog Given a particular method condition, identify the following: whether an exception will be thrown, the type of exception thrown, the container's action, and the client's view. Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans. Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation. Identify correct and incorrect statements or examples about an entity bean's primary key and object identity. Identify the use, syntax, and behavior of, the following entity bean home method types, for Container-Managed Persistence (CMP); finder methods, create methods, remove methods, and home me Chapter 8. Entity Beans Chapter 13. Enterprise Bean Environment Chapter 2. Client View of a Session Bean Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information. Given a list, identify which are requirements for an EJB-jar file. Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject). Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions. Identify correct and incorrect statements or examples about the purpose and use of EJB QL. Chapter 9. EJB-QL Identify correct and incorrect statements or examples about EJB programming restrictions. Chapter 1. EJB Overview Identify EJB 2.0 container requirements. Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject). Chapter 12. Exceptions Identify the use and the behavior of the ejbPassivate method in a session bean, including the responsibilities of both the container and the bean provider. Identify correct and incorrect statements about the purpose and use of the deployment descriptor elements for environment entries, EJB references, and resource manager connection factory r Chapter 10. Message-Driven Bean Component Contract Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's security context. From a list, identify the responsibility of the container for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbCreate, ejbPostCreate, ejbActi Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean. Chapter 7. CMP Entity Bean Life Cycle From a list, identify the purpose, behavior, and responsibilities of the bean provider for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbC Identify correctly-implemented deployment descriptor elements for a CMP bean (including container-managed relationships).
Ads

Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean.

An entity bean may have relationships with other entity beans with container-managed persistence (CMP).

Relationships may be one-to-one, one-to-many, or many-to-many relationships.

Container-managed relationships can exist ONLY among entity beans within the same LOCAL relationship scope, as defined by the relationships element in the deployment descriptor. Container-managed relationships (CMR) are defined in terms of the LOCAL interfaces of the related beans.

Relationships may be either bidirectional or unidirectional. If a relationship is bidirectional, it can be navigated in both directions, whereas a unidirectional relationship can be navigated in one direction only.

A unidirectional relationship is implemented with a cmr-field on the entity bean instance from which navigation can take place, and no related cmr-field on the entity bean instance that is the target of the relationship. Unidirectional relationships are typically used when the Bean Provider wishes to restrict the visibility of a relationship.

					 
<relationships>
	<ejb-relation>
		<ejb-relation-name>
			Customer-Address
		</ejb-relation-name>
		<ejb-relationship-role>
			<ejb-relationship-role-name>
				Customer-has-a-Address
			</ejb-relationship-role-name>
			<multiplicity>One</multiplicity>
			<relationship-role-source>
				<ejb-name>CustomerEJB</ejb-name>
			</relationship-role-source>
			<cmr-field>
				<cmr-field-name>homeAddress</cmr-field-name>
			</cmr-field>
		</ejb-relationship-role>
		<ejb-relationship-role>
			<ejb-relationship-role-name>
				Address-belongs-to-Customer
			</ejb-relationship-role-name>
			<multiplicity>One</multiplicity>
			<relationship-role-source>
				<ejb-name>AddressEJB</ejb-name>
			</relationship-role-source>
		</ejb-relationship-role>
	</ejb-relation>
</relationships>
					
					

An entity bean that DOES NOT have a LOCAL interface can have ONLY unidirectional relationships from itself to other entity beans. The lack of a local interface prevents other entity beans from having a relationship to it.

The bean developer navigates or manipulates relationships by using the get and set accessor methods for the container-managed relationship (CMR) fields and the java.util.Collection API for collection-valued container-managed relationship fields.

					
<relationships>
	...
	<ejb-relation>
		<ejb-relation-name>
			Customer-Phones
		</ejb-relation-name>
		<ejb-relationship-role>
			<ejb-relationship-role-name>
				Customer-has-many-Phone-numbers
			</ejb-relationship-role-name>
			<multiplicity>One</multiplicity>	
			<relationship-role-source>
				<ejb-name>CustomerEJB</ejb-name>
			</relationship-role-source>
			<cmr-field>
				<cmr-field-name>phoneNumbers</cmr-field-name>
				<cmr-field-type>java.util.Collection</cmr-field-type>
			</cmr-field>
		</ejb-relationship-role>
		<ejb-relationship-role>
			<ejb-relationship-role-name>
				Phone-belongs-to-Customer
			</ejb-relationship-role-name>
			<multiplicity>Many</multiplicity>
			<relationship-role-source>
				<ejb-name>PhoneEJB</ejb-name>
			</relationship-role-source>
		</ejb-relationship-role>
	</ejb-relation>
	...
</relationships>					
									
					
					
public abstract class CustomerBean implements javax.ejb.EntityBean {
	...
	public void addPhoneNumber(String number, byte type) 
			throws NamingException, CreateException   {
		InitialContext jndiEnc = new InitialContext();
		PhoneHomeLocal phoneHome = (PhoneHomeLocal)	
				(jndiEnc.lookup("PhoneHomeLocal"));
		PhoneLocal phone = phoneHome.create(number,type);
		Collection phoneNumbers = this.getPhoneNumbers();
		phoneNumbers.add(phone);
	}

	public void removePhoneNumber(byte typeToRemove) {
		Collection phoneNumbers = this.getPhoneNumbers();
		Iterator iterator = phoneNumbers.iterator();
		while(iterator.hasNext()){
			PhoneLocal phone = (PhoneLocal)iterator.next();
			if (phone.getType() == typeToRemove) {
				phoneNumbers.remove(phone);
				break;
			}
		}
	}

	public abstract java.util.Collection getPhoneNumbers( );
	public abstract void setPhoneNumbers(java.util.Collection phones);

}
					

The bean provider MUST consider the type and cardinality of relationships when the entity bean classes are programmed. The get method for a cmr-field MUST return either the local interface of the entity bean or a collection (either java.util.Collection or java.util.Set) of the same. The set method for the relationship MUST take as an argument the entity bean’s local interface or a collection of the same.

public abstract class CustomerBean implements javax.ejb.EntityBean {
	...
	// persistent relationships
	public abstract AddressLocal getHomeAddress();
	public abstract void setHomeAddress(AddressLocal address);

	public abstract AddressLocal getBillingAddress();
	public abstract void setBillingAddress(AddressLocal address);

	public abstract CreditCardLocal getCreditCard();
	public abstract void setCreditCard(CreditCardLocal card);

	public abstract java.util.Collection getPhoneNumbers( );
	public abstract void setPhoneNumbers(java.util.Collection phones);
	...						
}
					

The Bean Provider can specify the removal of an entity object in two ways:

  • By the use of a remove method on the entity bean’s COMPONENT interface or HOME interface.

  • By the use of a cascade-delete specification in the deployment descriptor (ONLY when other member of relationship has multiplicity ONE).

When the remove() method is invoked on an entity object, the container MUST invoke the entity Bean Provider’s ejbRemove() method. After the bean provider’s ejbRemove() method returns (and prior to returning to the client), the Container MUST remove the entity object from all relationships in which it participates, and THEN remove its persistent representation.

  • Once an entity has been removed from a relationship, the accessor methods for any relationships to the entity will reflect this removal. An accessor method for a one-to-one or many-to-one relationship to the entity will return null; and an accessor method for a many-to-many relationship to the entity will return a collection from which the entity object has been removed.

  • The Container MUST detect any subsequent attempt to invoke an accessor method on the removed entity object and throw the java.rmi.NoSuchObjectException if the client is a REMOTE client or the javax.ejb.NoSuchObjectLocalException if the client is a LOCAL client. The Container MUST detect an attempt to assign a removed entity object as the value of a cmr-field of another object (whether as an argument to a set accessor method or as an argument to a method of the java.util.Collection API) and throw the java.lang.IllegalArgumentException.

After removing the entity object from all relationships and removing its persistent representation, the Container MUST then cascade the removal to all entity beans with which the entity had been previously in container-managed relationships for which the cascade-delete option was specified. The remove method, alone, causes only the entity on which it is invoked to be removed. It DOES NOT cause the deletion to be cascaded to other entity objects. In order for the deletion of one entity object to be automatically cascaded to another, the cascade-delete mechanism should be used.

The cascade-delete deployment descriptor element is used within a particular relationship to specify that the lifetime of one or more entity objects is dependent upon the lifetime of another entity object.

					
<ejb-relation>
	<ejb-relation-name>Customer-HomeAddress</ejb-relation-name>
	<ejb-relationship-role>
		<ejb-relationship-role-name>
			Customer-has-a-Address
		</ejb-relationship-role-name>
		<multiplicity>One</multiplicity>
		<relationship-role-source>
			<ejb-name>CustomerEJB</ejb-name>
		</relationship-role-source>
		<cmr-field>
			<cmr-field-name>homeAddress</cmr-field-name>
		</cmr-field>
	</ejb-relationship-role>
	<ejb-relationship-role>
		<ejb-relationship-role-name>
			Address-belongs-to-Customer
		</ejb-relationship-role-name>
		<multiplicity>One</multiplicity>
		<cascade-delete/>
		<relationship-role-source>
			<ejb-name>AddressEJB</ejb-name>
		</relationship-role-source>
	</ejb-relationship-role>
</ejb-relation>
					
					

The cascade-delete deployment descriptor element is contained within the ejb-relationship-role element. The cascade-delete element can ONLY be specified for an ejb-relationship-role element contained in an ejb-relation element if the other ejb-relationship-role element in the same ejb-relation element specifies a multiplicity of ONE. The cascade-delete option CANNOT be specified for a many-to-many relationship. The deletion of one entity object can only be cascaded to cause the deletion of other entity objects if the first entity object is in a one-to-one or one-to-many relationship with those other entity objects.

Visit http://java.boot.by  for the updates.

Advertisements

Share on Google+Share on Google+

Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean.

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 
Comments:0

Ads

 

Ads