customertype.java

来自「此程序都是企业级 的数据库开发程序 全面揭示了JAVA对数据库的操作」· Java 代码 · 共 118 行

JAVA
118
字号
import java.util.*;

import org.jlf.log.*;
import org.jlf.dataMap.*;


/**
 * This class holds the different types of Customers in
 * the system.  One instance of this class corresponds to one
 * row in the CUSTOMER_TYPE table.
 */
public class CustomerType extends CachedObject {

  // --------------------------------------------------------------
  // Section 1: DataMappedObject descriptors
  // --------------------------------------------------------------

  // Constants for attributes
  public static final String ID_ATTRIBUTE = "CUSTOMER_TYPE_ID";
  public static final String DESCRIPTION_ATTRIBUTE = "DESCRIPTION";

  /**
   * 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 recording-specific attributes
    descriptor = new DataAttributeDescriptor(ID_ATTRIBUTE, 
                                             LongAttribute.class, true);
    descriptor.setIsKeyField(true);
    descriptors.put(ID_ATTRIBUTE, descriptor);

    descriptor = new DataAttributeDescriptor(DESCRIPTION_ATTRIBUTE, 
                                             StringAttribute.class, false);
    descriptor.setMaximumLength(50);
    descriptors.put(DESCRIPTION_ATTRIBUTE, descriptor);

    return descriptors;
  } 

  /**
   * Default constructor must be public for the data mapping
   * framework!  However, when creating a new object, look to use
   * a paramterized constructor.
   */
  public CustomerType() {}

  // --------------------------------------------------------------
  // Section 2: Java Bean methods
  // --------------------------------------------------------------

  /**
   * Retrieves the database id of the object.
   */
  public long getCustomerTypeId() {
    return getLongAttribute(ID_ATTRIBUTE);
  } 

  /**
   * Retrieves the description of the type.
   */
  public String getDescription() {
    return getStringAttribute(DESCRIPTION_ATTRIBUTE);
  } 

  // --------------------------------------------------------------
  // Section 3: Convenience accessors for types
  // --------------------------------------------------------------
  public static final long GENERIC_CUSTOMER_ID = 1;

  /**
   * Type of customer that has no volume discount.
   */
  public static final CustomerType GENERIC_CUSTOMER = 
    CustomerType.findById(GENERIC_CUSTOMER_ID);

  public static final long FREQUENT_BUYER_ID = 2;

  /**
   * Type of customer that has purchased enough
   * recordings to receive a volume discount.
   */
  public static final CustomerType FREQUENT_BUYER = 
    CustomerType.findById(FREQUENT_BUYER_ID);

  public static final long CORPORATE_CUSTOMER_ID = 3;

  /**
   * Type of customer that is a corporation with a volume discount.
   */
  public static final CustomerType CORPORATE_CUSTOMER = 
    CustomerType.findById(CORPORATE_CUSTOMER_ID);

  public static final long NON_PROFIT_CUSTOMER_ID = 4;

  /**
   * Type of customer that is a non-profit corporation
   * and has a volume discount.
   */
  public static final CustomerType NON_PROFIT_CUSTOMER = 
    CustomerType.findById(NON_PROFIT_CUSTOMER_ID);

  /**
   * Tries to find a CustomerType by its primary key, its id.
   * Returns the CustomerType if found in the database, null if not.
   */
  public static CustomerType findById(long id) {
    CustomerType customerType = new CustomerType();
    customerType.setAttributeValue(ID_ATTRIBUTE, new Long(id));
    return (CustomerType) customerType.findByPrimaryKey();
  } 

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?