001: package oes;
002:
003: import java.util.Collection;
004: import java.util.ArrayList;
005: import org.exolab.castor.jdo.Database;
006: import org.exolab.castor.jdo.Persistent;
007: import org.exolab.castor.jdo.PersistenceException;
008: import org.exolab.castor.jdo.Query;
009: import org.exolab.castor.jdo.QueryResults;
010: import org.exolab.castor.mapping.AccessMode;
011:
012: public class Category implements Persistent {
013:
014: private Database _db;
015:
016: private int _categoryId;
017:
018: private String _shortName;
019:
020: private String _description;
021:
022: private Collection _products;
023:
024: public int getCategoryId() {
025: return _categoryId;
026: }
027:
028: public void setCategoryId(int id) {
029: _categoryId = id;
030: }
031:
032: public String getShortName() {
033: return _shortName;
034: }
035:
036: public void setShortName(String shortName) {
037: shortName = shortName.trim();
038: if (shortName.length() == 0)
039: throw new IllegalArgumentException(
040: "Argument 'shortName' is an empty string");
041: _shortName = shortName;
042: }
043:
044: public String getDescription() {
045: return _description;
046: }
047:
048: public void setDescription(String description) {
049: description = description.trim();
050: if (description.length() == 0)
051: throw new IllegalArgumentException(
052: "Argument 'description' is an empty string");
053: _description = description;
054: }
055:
056: public Collection getProducts() throws PersistenceException {
057: Query qry;
058: QueryResults res;
059:
060: if (_products == null) {
061: _products = new ArrayList();
062: qry = _db
063: .getOQLQuery("SELECT p FROM Product p WHERE p.category=$1");
064: qry.bind(_categoryId);
065: res = qry.execute();
066: while (res.hasMore())
067: _products.add(res.next());
068: }
069: return _products;
070: }
071:
072: public void jdoPersistent(Database db) {
073: _db = db;
074: }
075:
076: public void jdoTransient() {
077: _db = null;
078: _products = null;
079: }
080:
081: public Class jdoLoad(AccessMode accessMode) {
082: return null;
083: }
084:
085: public void jdoBeforeCreate(Database db) {
086: }
087:
088: public void jdoAfterCreate() {
089: }
090:
091: public void jdoStore(boolean modified) {
092: }
093:
094: public void jdoBeforeRemove() {
095: }
096:
097: public void jdoAfterRemove() {
098: }
099:
100: public void jdoUpdate() {
101: }
102: }
|