001: package oes;
002:
003: import org.exolab.castor.jdo.Database;
004: import org.exolab.castor.jdo.Persistent;
005: import org.exolab.castor.jdo.PersistenceException;
006: import org.exolab.castor.mapping.AccessMode;
007:
008: public class Product implements Persistent {
009:
010: private Database _db;
011:
012: private String _sku;
013:
014: private String _shortName;
015:
016: private String _description;
017:
018: private int _categoryId;
019:
020: private Category _category;
021:
022: private int _priceId;
023:
024: private Price _price;
025:
026: public String getSku() {
027: return _sku;
028: }
029:
030: public void setSku(String sku) {
031: if (sku.length() != 14)
032: throw new IllegalArgumentException(
033: "Argument 'sku' must be 14 characters");
034: _sku = sku;
035: }
036:
037: public String getShortName() {
038: return _shortName;
039: }
040:
041: public void setShortName(String shortName) {
042: shortName = shortName.trim();
043: if (shortName.length() == 0)
044: throw new IllegalArgumentException(
045: "Argument 'shortName' is an empty string");
046: _shortName = shortName;
047: }
048:
049: public String getDescription() {
050: return _description;
051: }
052:
053: public void setDescription(String description) {
054: description = description.trim();
055: if (description.length() == 0)
056: throw new IllegalArgumentException(
057: "Argument 'description' is an empty string");
058: _description = description;
059: }
060:
061: public int getCategoryId() {
062: if (_category != null)
063: return _category.getCategoryId();
064: return _categoryId;
065: }
066:
067: public void setCategoryId(int id) {
068: _categoryId = id;
069: _category = null;
070: }
071:
072: public Category getCategory() throws PersistenceException {
073: if (_category != null)
074: return _category;
075: _category = (Category) _db.load(Category.class, new Integer(
076: _categoryId));
077: return _category;
078: }
079:
080: public void setCategory(Category category) {
081: _category = category;
082: _categoryId = category.getCategoryId();
083: }
084:
085: public int getPriceId() {
086: if (_price != null)
087: return _price.getPriceId();
088: return _priceId;
089: }
090:
091: public void setPriceId(int id) {
092: _priceId = id;
093: _price = null;
094: }
095:
096: public Price getPrice() throws PersistenceException {
097: if (_price != null)
098: return _price;
099: _price = (Price) _db.load(Price.class, new Integer(_priceId));
100: return _price;
101: }
102:
103: public void setPrice(Price price) {
104: _price = price;
105: _priceId = price.getPriceId();
106: }
107:
108: public void jdoPersistent(Database db) {
109: _db = db;
110: }
111:
112: public void jdoTransient() {
113: _db = null;
114: _price = null;
115: _category = null;
116: }
117:
118: public Class jdoLoad(AccessMode accessMode) {
119: return null;
120: }
121:
122: public void jdoBeforeCreate(Database db) {
123: }
124:
125: public void jdoAfterCreate() {
126: }
127:
128: public void jdoStore(boolean modified) {
129: }
130:
131: public void jdoBeforeRemove() {
132: }
133:
134: public void jdoAfterRemove() {
135: }
136:
137: public void jdoUpdate() {
138: }
139:
140: }
|