Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean.

This page discusses - Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP 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 the rules and semantics for relationship assignment and relationship updating in a CMP bean.

The assignment operations for container-managed relationships have a special semantics that is determined by the referential integrity semantics for the relationship multiplicity.

In the case of a one-to-one relationship, when the Bean Provider uses a set accessor method to assign an object from a cmr-field in one instance to a cmr-field of the SAME relationship type (i.e., as defined by the ejb-relation and ejb-relationship-role deployment descriptor elements) in another instance, the object is effectively MOVED and the value of the source cmr-field is set to null in the same transaction context. If the argument to the set accessor method is NOT of the same type as the cmr-field, the container MUST throw the java.lang.IllegalArgumentException.

In the case of a one-to-many or many-to-many relationship, either the java.util.Collection API or a set accessor method may be used to manipulate the contents of a collection-valued cmr-field. These two approaches are discussed below.

The methods of the java.util.Collection API for the container-managed collections used for collection-valued cmr-fields have the usual semantics, with the following exception: the add and addAll methods applied to container-managed collections in one-to-many relationships have a special semantics that is determined by the referential integrity of one-to-many relationships.

If the argument to the add method is already an element of a collection-valued relationship field of the same relationship type as the target collection (as defined by the ejb-relation and ejb-relationship-role deployment descriptor elements), it is removed from this first relationship and added, in the same transaction context, to the target relationship (i.e., it is effectively moved from one collection of the relationship type to the other). For example, if there is a one-to-many relationship between field "person" and "telephones", adding a "telephone" to a new field "person" will have the effect of removing it from its current field "person".

public abstract class PersonBean implements javax.ejb.EntityBean {
	...
	public void addPhoneNumber(PhoneLocal phone) {
		Collection phoneNumbers = this.getPhoneNumbers();
		phoneNumbers.add(phone);
	}
	...
}	
					

The addAll method, when applied to a target collection in a one-to-many relationship, has similar semantics, applied to the members of its collection argument individually.

public abstract class PersonBean implements javax.ejb.EntityBean {
	...
	public void addPhoneNumbers(Collection numbers) {
		Collection phoneNumbers = this.getPhoneNumbers();
		phoneNumbers.addAll(numbers);
	}

	// relationship fields
	public abstract Set getPhoneNumbers( );
	public abstract void setPhoneNumbers(Set numbers);
	...
}	
					

Bean Provider MUST NOT modify the container-managed COLLECTION while the iteration is in progress in any way that causes elements to be added or removed, other than by the java.util.Iterator.remove() method. If elements are added or removed from the underlying container-managed collection used by an iterator other than by the java.util.Iterator.remove() method, the container should throw the java.lang.IllegalStateException on the next operation on the iterator.

Collection nySalesreps = nyOffice.getSalesreps();
Collection sfSalesreps = sfOffice.getSalesreps();
Iterator i = nySalesreps.iterator();
Salesrep salesrep;

// a WRONG way to transfer the salesrep
while (i.hasNext()) {
	salesrep = (Salesrep)i.next();
	sfSalesreps.add(salesrep); // removes salesrep from nyOffice
}

// this is a CORRECT and safe way to transfer the salesrep
while (i.hasNext()) {
	salesrep = (Salesrep)i.next();
	i.remove();
	sfSalesreps.add(salesrep);
}
					

The semantics of a set accessor method, when applied to a collection-valued cmr-field, is also determined by the referential integrity semantics associated with the multiplicity of the relationship. The identity of the collection object referenced by a cmr-field does not change when a set accessor method is executed.

In the case of a one-to-many relationship, if a collection of entity objects is assigned from a cmr-field of in one instance to a cmr-field of the same relationship type in another instance, the objects in the collection are effectively MOVED. The CONTENTS of the collection of the target instance are REPLACED with the contents of the collection of the source instance, but the identity of the collection object containing the instances in the relationship does not change. The source cmr-field references the same collection object as before (i.e., the identity of the collection object is preserved), but the collection is empty.

The Bean Provider can thus use the set(...) method to MOVE objects between the collections referenced by cmr-fields of the same relationship type in different instances. The set accessor method, when applied to a cmr-field in a one-to-many relationship thus has the semantics of the java.util.Collection methods clear, followed by addAll, applied to the TARGET collection; and clear, applied to the SOURCE collection. It is the responsibility of the container to transfer the contents of the collection instances in the same transaction context.

public void changeTelephoneNumber() {
	Address a = getShippingAddress();
	Address b = getBillingAddress();
	Collection c = b.getTelephoneNumbers();
	a.setTelephoneNumbers(b.getTelephoneNumbers());
	if (c.isEmpty()) {	// MUST be true
		...
	}
}					
					

In the case of a many-to-many relationship, if the value of a cmr-field is assigned to a cmr-field of the same relationship type in another instance, the objects in the collection of the first instance are assigned as the contents of the cmr-field of the second instance. The identities of the collection objects referenced by the cmr-fields do not change. The contents of the collections are shared, but not the collections themselves. The set accessor method, when applied to a cmr-field in a many-to-many relationship thus has the semantics of the java.util.Collection methods clear, followed by addAll, applied to the TARGET collection.

public void shareCustomers(SalesRep rep) {
	setCustomers(rep.getCustomers());
	// the customers are shared among the salesreps
}
					
  1. One-to-one bidirectional relationships

    EntityBean_B entityBean_B1 = entityBean_A1.getEntityBean_B();
    EntityBean_B entityBean_B2 = entityBean_A2.getEntityBean_B();
    							
    entityBean_A1.setEntityBean_B(entityBean_A2.getEntityBean_B());
    
    if entityBean_A1.getEntityBean_B().isIdentical(entityBean_B2) { ... } // true
    
    if (entityBean_A2.getEntityBean_B() == null) { ... } // true
    if (entityBean_B1.getEntityBean_A() == null) { ... } // true
    							
  2. One-to-one unidirectional relationships

    EntityBean_B entityBean_B1 = entityBean_A1.getEntityBean_B();
    EntityBean_B entityBean_B2 = entityBean_A2.getEntityBean_B();
    							
    entityBean_A1.setEntityBean_B(entityBean_A2.getEntityBean_B());
    
    if (entityBean_A2.getEntityBean_B() == null) { ... } // true
    							
  3. One-to-many bidirectional relationships

    Collection entityBeans_B1 = entityBean_A1.getEntityBean_B();
    Collection entityBeans_B2 = entityBean_A2.getEntityBean_B();
    							
    entityBean_A1.setEntityBean_B(entityBean_A2.getEntityBean_B());
    
    if (entityBean_A2.getEntityBean_B().isEmpty()) { ... } // true
    if (entityBeans_B2.isEmpty()) { ... } // true
    if (entityBean_B11.getEntityBean_A() == null) { ... } // true
    if (entityBean_A1.isIdentical(entityBean_B21.getEntityBean_A())) { 
    	... // true
    } 
    							
    entityBean_B21.setEntityBean_A(entityBean_B11.getEntityBean_A());
    
    if (entityBean_A1.isIdentical(entityBean_B21.getEntityBean_A())) { 
    	... // true
    } 
    if (entityBeans_B1.contains(entityBean_B21)) { ... } // true
    							
    entityBean_A1.getEntityBean_B().add(entityBean_B21);
    
    if (entityBean_A1.isIdentical(entityBean_B21.getEntityBean_A())) {
    	... // true
    }
    if (entityBeans_B1.contains(entityBean_B21)) { ... } // true
    							
    entityBean_A1.getEntityBean_B().remove(entityBean_B12);
    
    if (entityBean_B12.getEntityBean_A() == null) { ... } // true
    							
  4. One-to-many unidirectional relationships

    Collection entityBeans_B1 = entityBean_A1.getEntityBean_B();
    Collection entityBeans_B2 = entityBean_A2.getEntityBean_B();
    							
    entityBean_A1.setEntityBean_B(entityBean_A2.getEntityBean_B());
    
    if (entityBean_A2.getEntityBean_B().isEmpty()) { ... } // true
    if (entityBeans_B2.isEmpty()) { ... } // true
    if (entityBean_A1.getEntityBean_B().contains(entityBean_B21)) { 
    	... // true
    } 
    if (entityBeans_B1.contains(entityBean_B21)) { ... } // true
    							
    entityBean_A1.getEntityBean_B().add(entityBean_B21);
    
    if (entityBeans_B1 == entityBean_A1.getEntityBean_B()) {
    	... // true
    }
    if (entityBeans_B1.contains(entityBean_B21)) { ... } // true
    							
    entityBean_A1.getEntityBean_B().remove(entityBean_B12);
    
    if !(entityBean_A1.getEntityBean_B().contains(entityBean_B12)) {
    	... // true
    } 
    							
  5. Many-to-one unidirectional relationships

    if entityBean_A1.isIdentical(entityBean_B11.getEntityBean_A()) { ... } // true
    if entityBean_A1.isIdentical(entityBean_B12.getEntityBean_A()) { ... } // true
    
    if entityBean_A2.isIdentical(entityBean_B21.getEntityBean_A()) { ... } // true
    if entityBean_A2.isIdentical(entityBean_B22.getEntityBean_A()) { ... } // true
    							
    entityBean_B12.setEntityBean_A(entityBean_B22.getEntityBean_A());
    
    if entityBean_A1.isIdentical(entityBean_B11.getEntityBean_A()) { ... } // true
    
    if entityBean_A2.isIdentical(entityBean_B12.getEntityBean_A()) { ... } // true
    if entityBean_A2.isIdentical(entityBean_B21.getEntityBean_A()) { ... } // true
    if entityBean_A2.isIdentical(entityBean_B22.getEntityBean_A()) { ... } // true
    							
  6. Many-to-many bidirectional relationships

    if entityBean_A11.getEntityBean_B().contains(entityBean_B11) { ... } // true
    if entityBean_A11.getEntityBean_B().contains(entityBean_B12) { ... } // true
    
    if entityBean_A12.getEntityBean_B().contains(entityBean_B11) { ... } // true
    if entityBean_A12.getEntityBean_B().contains(entityBean_B12) { ... } // true
    if entityBean_A12.getEntityBean_B().contains(entityBean_B21) { ... } // true
    							
    entityBean_A11.setEntityBean_B(entityBean_A22.getEntityBean_B());
    							
    if entityBean_A11.getEntityBean_B().contains(entityBean_B21) { ... } // true
    if entityBean_A11.getEntityBean_B().contains(entityBean_B22) { ... } // true
    
    if entityBean_A22.getEntityBean_B().contains(entityBean_B21) { ... } // true
    if entityBean_A22.getEntityBean_B().contains(entityBean_B22) { ... } // true
    							
    entityBean_A11.getEntityBean_B().add(entityBean_B21);
    							
    if entityBean_A11.getEntityBean_B().contains(entityBean_B11) { ... } // true
    if entityBean_A11.getEntityBean_B().contains(entityBean_B12) { ... } // true
    if entityBean_A11.getEntityBean_B().contains(entityBean_B21) { ... } // true
    							
    entityBean_A12.getEntityBean_B().remove(entityBean_B12);
    							
    if entityBean_A12.getEntityBean_B().contains(entityBean_B11) { ... } // true
    if entityBean_A12.getEntityBean_B().contains(entityBean_B21) { ... } // true
    
    if entityBean_B12.getEntityBean_A().contains(entityBean_A11) { ... } // true
    if entityBean_B12.getEntityBean_A().contains(entityBean_A21) { ... } // true
    							
  7. Many-to-many unidirectional relationships

    if entityBean_A11.getEntityBean_B().contains(entityBean_B11) { ... } // true
    if entityBean_A11.getEntityBean_B().contains(entityBean_B12) { ... } // true
    
    if entityBean_A12.getEntityBean_B().contains(entityBean_B11) { ... } // true
    if entityBean_A12.getEntityBean_B().contains(entityBean_B12) { ... } // true
    if entityBean_A12.getEntityBean_B().contains(entityBean_B21) { ... } // true
    							
    entityBean_A11.setEntityBean_B(entityBean_A22.getEntityBean_B());
    							
    if entityBean_A11.getEntityBean_B().contains(entityBean_B21) { ... } // true
    if entityBean_A11.getEntityBean_B().contains(entityBean_B22) { ... } // true
    
    if entityBean_A22.getEntityBean_B().contains(entityBean_B21) { ... } // true
    if entityBean_A22.getEntityBean_B().contains(entityBean_B22) { ... } // true
    							
    entityBean_A11.getEntityBean_B().add(entityBean_B21);
    							
    if entityBean_A11.getEntityBean_B().contains(entityBean_B11) { ... } // true
    if entityBean_A11.getEntityBean_B().contains(entityBean_B12) { ... } // true
    if entityBean_A11.getEntityBean_B().contains(entityBean_B21) { ... } // true
    							
    entityBean_A12.getEntityBean_B().remove(entityBean_B12);
    							
    if entityBean_A12.getEntityBean_B().contains(entityBean_B11) { ... } // true
    if entityBean_A12.getEntityBean_B().contains(entityBean_B21) { ... } // true
    							

Advertisements

Share on Google+Share on Google+

Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP 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