Content deleted Content added
→Sample code: format code |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1:
'''Composite entity''' is a [[Java Platform, Enterprise Edition|Java EE]] [[Software design pattern]] and it is used to model, represent, and manage a set of interrelated persistent objects rather than representing them as individual fine-grained entity beans, and also a composite entity bean represents a graph of objects.<ref name=":o_cjp">{{Cite web|url = http://www.oracle.com/technetwork/java/compositeentity-141992.html|title = Core J2EE Patterns - Composite Entity|access-date
==Structure==
Line 24:
* materializing all the data in a coarse-grained entity whenever it is accessed, is unacceptably expensive
* In [[Java (programming language)|Java]], implementation of the ejbStore() method needs to be smart enough to avoid issuing all the updates required to persist the entire state of the object, unless the data has changed in all the persistent objects.
Composite entity pattern can only be implemented using BMP or by adding more hand-coded persistence logic to container managed persistence (CMP) [[JavaBeans|beans]]. These both approaches reduce the maintainability.<ref name=":eojdad">{{Cite book|title = Expert One-on-One J2EE Design and Development|last = Johnson|first = R. |publisher = Wiley Publishing, Inc|year = 2003|___location = Indianapolis
==Sample code==
Sample code for a Professional Service Automation application (PSA) in which the resource object is implemented via composite entity pattern, may look like as follows (entity implements coarse-grained object):
<
package corepatterns.apps.psa.ejb;
Line 69:
setResourceData(resource);
getResourceDAO().create(resource);
} catch (Exception ex) {
throw new EJBException("Reason:" + ...);
}
Line 82:
result =
resourceDAO.selectByPrimaryKey(primaryKey);
} catch (Exception ex) {
throw new EJBException("Reason:" + ...);
}
Line 115:
ResourceDAO(employeeId);
resourceDAO.delete();
} catch (ResourceException ex) {
throw new EJBException("Reason:"+...);
} catch (BlockOutTimeException ex) {
throw new EJBException("Reason:"+...);
} catch (Exception exception) {
...
}
Line 149:
// Load other dependent objects, if necessary
...
} catch (Exception ex) {
throw new EJBException("Reason:" + ...);
}
Line 161:
// Store dependent objects as needed
...
} catch (SkillSetException ex) {
throw new EJBException("Reason:" + ...);
} catch (BlockOutTimeException ex) {
throw new EJBException("Reason:" + ...);
}
Line 223:
}
}
} catch (Exception exception) {
throw new EJBException(...);
}
Line 271:
}
</
==See also==
|