📄 customertrackedrecording.java
字号:
import java.util.*;
import org.jlf.log.*;
import org.jlf.dataMap.*;
/**
* This class is used to track Customer purchases
* and interests in Recordings. It maps to the
* CUSTOMER_TRACKED_RECORDINGS table in the database and has
* relationships to Customer, Recording, and CustomerTrackingType
* objects.
*/
public class CustomerTrackedRecording extends DataMappedObject {
// --------------------------------------------------------------
// Section 1: DataMappedObject descriptors
// --------------------------------------------------------------
// Constants for attributes
public static final String CUSTOMER_ID_ATTRIBUTE = "CUSTOMER_ID";
public static final String RECORDING_ID_ATTRIBUTE = "RECORDING_ID";
public static final String CUSTOMER_TRACKING_TYPE_ID_ATTRIBUTE =
"TRACKING_TYPE_ID";
public static final String DATE_TRACKED_ATTRIBUTE = "DATE_TRACKED";
// Used for optimistic locking
public static final String VERSION_ATTRIBUTE = "VERSION";
// Relationships
public static final String CUSTOMER_RELATIONSHIP = "customer";
public static final String RECORDING_RELATIONSHIP = "recording";
public static final String CUSTOMER_TRACKING_TYPE_RELATIONSHIP =
"customerTrackingType";
/**
* Sets up a table of attribute descriptors for the
* object.
*/
protected Hashtable basicGetAttributeDescriptors() {
// Always call the superclass!
Hashtable descriptors = super.basicGetAttributeDescriptors();
DataAttributeDescriptor descriptor;
// Then add class-specific attributes, starting with primary key
descriptor = new DataAttributeDescriptor(CUSTOMER_ID_ATTRIBUTE,
LongAttribute.class, true);
descriptor.setIsKeyField(true);
descriptors.put(CUSTOMER_ID_ATTRIBUTE, descriptor);
descriptor = new DataAttributeDescriptor(RECORDING_ID_ATTRIBUTE,
LongAttribute.class, true);
descriptor.setIsKeyField(true);
descriptors.put(RECORDING_ID_ATTRIBUTE, descriptor);
descriptor =
new DataAttributeDescriptor(CUSTOMER_TRACKING_TYPE_ID_ATTRIBUTE,
LongAttribute.class, true);
descriptor.setIsKeyField(true);
descriptors.put(CUSTOMER_TRACKING_TYPE_ID_ATTRIBUTE, descriptor);
// Add non-key attributes
descriptor = new DataAttributeDescriptor(DATE_TRACKED_ATTRIBUTE,
DateAttribute.class, false);
descriptors.put(DATE_TRACKED_ATTRIBUTE, descriptor);
descriptor = new DataAttributeDescriptor(VERSION_ATTRIBUTE,
LongAttribute.class, false);
descriptors.put(VERSION_ATTRIBUTE, descriptor);
return descriptors;
}
/**
* Sets up the relationships from this object to its
* customer, recording, and tracking type.
*/
protected Hashtable basicGetRelationshipDescriptors() {
// Always call the superclass!
Hashtable descriptors = super.basicGetRelationshipDescriptors();
// Add new relationships for this class
descriptors.put(CUSTOMER_RELATIONSHIP,
new RelationshipDescriptor(CUSTOMER_RELATIONSHIP,
Customer.class));
descriptors.put(RECORDING_RELATIONSHIP,
new RelationshipDescriptor(RECORDING_RELATIONSHIP,
Recording.class));
descriptors
.put(CUSTOMER_TRACKING_TYPE_RELATIONSHIP,
new RelationshipDescriptor(CUSTOMER_TRACKING_TYPE_RELATIONSHIP,
CustomerTrackingType.class));
return descriptors;
}
/**
* Override to perform lazy-read relationships.
*/
public Vector findByRelationship(Relationship relationship,
DataMapper dataMapper) {
DataMappedObject dmo = relationship.getPrimaryObject();
// If primary object is a Customer, find all objects
// by Customer.
if (dmo instanceof Customer) {
// Look into the primary object for a customer.
// Set the customer and execute find by customer criteria.
Customer customer = (Customer) dmo;
setCustomer(customer);
return findManyBySearchCriteria("findByCustomer", dataMapper);
} else {
// Not a customer, must be a recording. Give it a try
// and execute find by recording criteria.
Recording recording = (Recording) dmo;
setRecording(recording);
return findManyBySearchCriteria("findByRecording", dataMapper);
}
}
/**
* Default constructor must be public for the data mapping
* framework! However, when creating a new object, look to use
* a paramterized constructor.
*/
public CustomerTrackedRecording() {}
// --------------------------------------------------------------
// Section 2: Java Bean methods
// --------------------------------------------------------------
/**
* Main constructor for the class. Sets customer,
* recording, and tracking type as input, and sets
* the date tracked to the current date/time.
*/
public CustomerTrackedRecording(Customer customer, Recording recording,
CustomerTrackingType trackingType) {
setCustomer(customer);
setRecording(recording);
setCustomerTrackingType(trackingType);
setDateTracked(new Date());
// Set initial object version to 1, increment every time the
// object is saved
setVersion(1);
}
/**
* Retrieves the Recording.
*/
public Recording getRecording() {
return (Recording) getRelatedObject(RECORDING_RELATIONSHIP);
}
/**
* Sets the Recording.
*/
public void setRecording(Recording recording) {
if (getRelatedObject(RECORDING_RELATIONSHIP) != null) {
throw new DataMapError("Cannot reset a Recording once set!", null,
Log.ERROR_LEVEL);
}
addRelatedObject(RECORDING_RELATIONSHIP, recording);
}
/**
* Retrieves the Customer.
*/
public Customer getCustomer() {
return (Customer) getRelatedObject(CUSTOMER_RELATIONSHIP);
}
/**
* Sets the Customer.
*/
public void setCustomer(Customer customer) {
if (getRelatedObject(CUSTOMER_RELATIONSHIP) != null) {
throw new DataMapError("Cannot reset a Customer once set!", null,
Log.ERROR_LEVEL);
}
addRelatedObject(CUSTOMER_RELATIONSHIP, customer);
}
/**
* Retrieves the CustomerTrackingType.
*/
public CustomerTrackingType getCustomerTrackingType() {
return (CustomerTrackingType) getRelatedObject(CUSTOMER_TRACKING_TYPE_RELATIONSHIP);
}
/**
* Sets the CustomerTrackingType.
*/
public void setCustomerTrackingType(CustomerTrackingType customerTrackingType) {
if (getRelatedObject(CUSTOMER_TRACKING_TYPE_RELATIONSHIP) != null) {
throw new DataMapError("Cannot reset a CustomerTrackingType once set!",
null, Log.ERROR_LEVEL);
}
addRelatedObject(CUSTOMER_TRACKING_TYPE_RELATIONSHIP,
customerTrackingType);
}
/**
* Retrieves the date this relationship was tracked.
*/
public Date getDateTracked() {
return (Date) getAttributeValue(DATE_TRACKED_ATTRIBUTE);
}
/**
* Sets the date this relationship was tracked.
*/
public void setDateTracked(Date dateTracked) {
setAttributeValue(DATE_TRACKED_ATTRIBUTE, dateTracked);
}
/**
* Retrieves the version of the Recording object.
*/
public long getVersion() {
return getLongAttribute(VERSION_ATTRIBUTE);
}
/**
* Sets the version of the Recording object.
*/
private void setVersion(long version) {
setLongAttribute(VERSION_ATTRIBUTE, version);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -