hibernate3 学习笔记(一)

        因为工作的关系,最近需要在项目中使用 hibernate 实现持久层,从来没有用过 hibernate, 刚开始确实有些不好掌握。从网上查了不小的资料,确定选用hibernate 的版本为 3.3.1 GA。

        hibernate 的包分为两部分,第一部分为运行所需的JAR包,还有一部分是生成代码所需的工具包。使用hibernate时,会根据数据库的结构,自动生成持久化的代码,这部分代码的生成,需要相关工具的支持。这就是为什么需要工具的原因。对于工具,有多种选择,可以根据不同情况,进行选择。一般情况下,可以使用 Hibernate Synchronizer,我们选用 HibernateSynchronizer-3.1.9,接下来,就是在 eclipse 中安装 hibernate 插件。      

 

       先做一个简单的例子:新找一个 java project, 并添加所需的 jar 包:

        classes12.jar  (Oracle 连接包)

        hibernate3.jar 

        dom4j-1.6.1.jar  (开源XML解析包)

        slf4j-log4j12-1.5.2.jar   (日志)

        slf4j-api-1.5.2.jar          (日志)

        log4j-1.2.15.jar    日志记录包

        jta-1.1.jar   (JTA规范)

        antlr-2.7.6.jar   (语法分析生成器)

        commons-collections-3.1.jar   (json依赖包)

        javassist-3.4.GA.jar    (类文件操作器)

        hibernate-testing.jar

 

       另外,还要加上JUNIT 包。

       做完以上的工作后,开发环境基本上就完成了。

 

接下来,首先添加一个 hibernate 的配置文件:hibernate.cfg.xml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE hibernate-configuration
  3.     PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
  4.     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  5.     
  6. <hibernate-configuration>
  7.     <session-factory name="cdma">
  8.         <!-- local connection properties -->
  9.         <property name="hibernate.connection.url">
  10.             jdbc:oracle:thin:@10.52.16.138:1521:oragxlu
  11.         </property>
  12.         <property name="hibernate.connection.driver_class">
  13.             oracle.jdbc.driver.OracleDriver
  14.         </property>
  15.         <property name="hibernate.connection.username">cdmagis</property>
  16.         <property name="hibernate.connection.password">cdmagis</property>
  17.         <!-- property name="hibernate.connection.pool_size"></property -->
  18.         <!-- dialect for Oracle (any version) -->
  19.         <property name="dialect">
  20.             org.hibernate.dialect.OracleDialect
  21.         </property>
  22.         <property name="hibernate.show_sql">false</property>
  23.         <property name="hibernate.transaction.factory_class">
  24.             org.hibernate.transaction.JDBCTransactionFactory
  25.         </property>
  26.         <mapping resource="CdmaBts.hbm.xml" />
  27.     </session-factory>
  28. </hibernate-configuration>

      在这个文件中,定义了数据库的连接信息。另外,还可以定义连接池。

      再添加一个 mapping 文件。

 

  1. <?xml version="1.0"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3.     "-//Hibernate/Hibernate Mapping DTD//EN"
  4.     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
  5. <hibernate-mapping package="test.src">
  6.     <class
  7.         name="test.src.CdmaBts"
  8.         table="CDMA_BTS"
  9.     >
  10.         <meta attribute="sync-DAO">true</meta>
  11.         <id
  12.             name="Id"
  13.             type="integer"
  14.             column="ID"
  15.         >
  16.             <generator class="sequence"/>
  17.         </id>
  18.         <property
  19.             name="Code"
  20.             column="CODE"
  21.             type="string"
  22.             not-null="false"
  23.             length="40"
  24.         />
  25.         <property
  26.             name="Name"
  27.             column="NAME"
  28.             type="string"
  29.             not-null="false"
  30.             length="40"
  31.         />
  32.         <property
  33.             name="Areaid"
  34.             column="AREAID"
  35.             type="integer"
  36.             not-null="false"
  37.             length="18"
  38.         />
  39.         <property
  40.             name="Barnid"
  41.             column="BARNID"
  42.             type="integer"
  43.             not-null="false"
  44.             length="18"
  45.         />
  46.         <property
  47.             name="Type"
  48.             column="TYPE"
  49.             type="integer"
  50.             not-null="false"
  51.             length="18"
  52.         />
  53.         <property
  54.             name="Factory"
  55.             column="FACTORY"
  56.             type="string"
  57.             not-null="false"
  58.             length="100"
  59.         />
  60.         <property
  61.             name="Spec"
  62.             column="SPEC"
  63.             type="integer"
  64.             not-null="false"
  65.             length="18"
  66.         />
  67.         <property
  68.             name="Usebegintime"
  69.             column="USEBEGINTIME"
  70.             type="date"
  71.             not-null="false"
  72.             length="7"
  73.         />
  74.         <property
  75.             name="Staff"
  76.             column="STAFF"
  77.             type="integer"
  78.             not-null="false"
  79.             length="12"
  80.         />
  81.         <property
  82.             name="Recordtime"
  83.             column="RECORDTIME"
  84.             type="date"
  85.             not-null="false"
  86.             length="7"
  87.         />
  88.         <property
  89.             name="Property"
  90.             column="PROPERTY"
  91.             type="integer"
  92.             not-null="false"
  93.             length="12"
  94.         />
  95.         <property
  96.             name="FixedCode"
  97.             column="FIXED_CODE"
  98.             type="string"
  99.             not-null="false"
  100.             length="40"
  101.         />
  102.         <property
  103.             name="State"
  104.             column="STATE"
  105.             type="integer"
  106.             not-null="false"
  107.             length="12"
  108.         />
  109.         <property
  110.             name="MaintenanceMode"
  111.             column="MAINTENANCE_MODE"
  112.             type="integer"
  113.             not-null="false"
  114.             length="12"
  115.         />
  116.         <property
  117.             name="Note"
  118.             column="NOTE"
  119.             type="string"
  120.             not-null="false"
  121.             length="300"
  122.         />
  123.         <property
  124.             name="Zczt"
  125.             column="ZCZT"
  126.             type="integer"
  127.             not-null="false"
  128.             length="12"
  129.         />
  130.         <property
  131.             name="Local"
  132.             column="LOCAL"
  133.             type="string"
  134.             not-null="false"
  135.             length="100"
  136.         />
  137.         <property
  138.             name="Whburden"
  139.             column="WHBURDEN"
  140.             type="integer"
  141.             not-null="false"
  142.             length="12"
  143.         />
  144.         <property
  145.             name="Stationid"
  146.             column="STATIONID"
  147.             type="integer"
  148.             not-null="false"
  149.             length="18"
  150.         />
  151.         <property
  152.             name="Covertype"
  153.             column="COVERTYPE"
  154.             type="integer"
  155.             not-null="false"
  156.             length="12"
  157.         />
  158.         <property
  159.             name="Chaincount"
  160.             column="CHAINCOUNT"
  161.             type="integer"
  162.             not-null="false"
  163.             length="12"
  164.         />
  165.         <property
  166.             name="Shootcount"
  167.             column="SHOOTCOUNT"
  168.             type="integer"
  169.             not-null="false"
  170.             length="12"
  171.         />
  172.         <property
  173.             name="Mscid"
  174.             column="MSCID"
  175.             type="integer"
  176.             not-null="false"
  177.             length="18"
  178.         />
  179.         <property
  180.             name="Bscid"
  181.             column="BSCID"
  182.             type="integer"
  183.             not-null="false"
  184.             length="18"
  185.         />
  186.         <property
  187.             name="Towerid"
  188.             column="TOWERID"
  189.             type="integer"
  190.             not-null="false"
  191.             length="18"
  192.         />
  193.         <property
  194.             name="Ifsurvey"
  195.             column="IFSURVEY"
  196.             type="integer"
  197.             not-null="false"
  198.             length="1"
  199.         />
  200.         <property
  201.             name="Networdcode"
  202.             column="NETWORDCODE"
  203.             type="string"
  204.             not-null="false"
  205.             length="40"
  206.         />
  207.         <property
  208.             name="Rated"
  209.             column="RATED"
  210.             type="integer"
  211.             not-null="false"
  212.             length="12"
  213.         />
  214.         <property
  215.             name="Maxshoot"
  216.             column="MAXSHOOT"
  217.             type="integer"
  218.             not-null="false"
  219.             length="12"
  220.         />
  221.         <property
  222.             name="Maintenance"
  223.             column="MAINTENANCE"
  224.             type="string"
  225.             not-null="false"
  226.             length="40"
  227.         />
  228.         <property
  229.             name="Aegisagreement"
  230.             column="AEGISAGREEMENT"
  231.             type="string"
  232.             not-null="false"
  233.             length="40"
  234.         />
  235.     </class>    
  236. </hibernate-mapping>

     这个文件,定义了DB表的信息,对应的创建表的SQL如下:

  1. create table CDMA_BTS
  2. (
  3.   ID               NUMBER(18) not null,
  4.   CODE             VARCHAR2(40),
  5.   NAME             VARCHAR2(40),
  6.   AREAID           NUMBER(18),
  7.   BARNID           NUMBER(18),
  8.   TYPE             NUMBER(18),
  9.   FACTORY          VARCHAR2(100),
  10.   SPEC             NUMBER(18),
  11.   USEBEGINTIME     DATE,
  12.   STAFF            NUMBER(12),
  13.   RECORDTIME       DATE,
  14.   PROPERTY         NUMBER(12),
  15.   FIXED_CODE       VARCHAR2(40),
  16.   STATE            NUMBER(12),
  17.   MAINTENANCE_MODE NUMBER(12),
  18.   NOTE             VARCHAR2(300),
  19.   ZCZT             NUMBER(12),
  20.   LOCAL            VARCHAR2(100),
  21.   WHBURDEN         NUMBER(12),
  22.   STATIONID        NUMBER(18),
  23.   COVERTYPE        NUMBER(12),
  24.   CHAINCOUNT       NUMBER(12),
  25.   SHOOTCOUNT       NUMBER(12),
  26.   MSCID            NUMBER(18),
  27.   BSCID            NUMBER(18),
  28.   TOWERID          NUMBER(18),
  29.   IFSURVEY         NUMBER(1),
  30.   NETWORDCODE      VARCHAR2(40),
  31.   RATED            NUMBER(12),
  32.   MAXSHOOT         NUMBER(12),
  33.   MAINTENANCE      VARCHAR2(40),
  34.   AEGISAGREEMENT   VARCHAR2(40)
  35. );

        然后再同步文件,会生成如下的文件:

  1. package test.src;
  2. import test.src.base.BaseCdmaBts;
  3. public class CdmaBts extends BaseCdmaBts {
  4.     private static final long serialVersionUID = 1L;
  5. /*[CONSTRUCTOR MARKER BEGIN]*/
  6.     public CdmaBts () {
  7.         super();
  8.     }
  9.     /**
  10.      * Constructor for primary key
  11.      */
  12.     public CdmaBts (java.lang.Integer id) {
  13.         super(id);
  14.     }
  15. /*[CONSTRUCTOR MARKER END]*/
  16. }

_BaseRootDAO.java:

  1. package test.src.base;
  2. import java.io.Serializable;
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Map;
  7. import org.hibernate.Criteria;
  8. import org.hibernate.HibernateException;
  9. import org.hibernate.Query;
  10. import org.hibernate.Session;
  11. import org.hibernate.Transaction;
  12. import org.hibernate.SessionFactory;
  13. import org.hibernate.cfg.Configuration;
  14. import org.hibernate.criterion.Expression;
  15. import org.hibernate.criterion.Order;
  16. public abstract class _BaseRootDAO {
  17.     public _BaseRootDAO () {}
  18.     
  19.     public _BaseRootDAO (Session session) {
  20.         setSession(session);
  21.     }
  22.     protected static Map<String, SessionFactory> sessionFactoryMap;
  23.     protected SessionFactory sessionFactory;
  24.     protected Session session;
  25.     protected final static ThreadLocal<Session> currentSession = new ThreadLocal<Session>();
  26.     
  27.     /**
  28.      * Return a new Session object that must be closed when the work has been completed.
  29.      * @return the active Session
  30.      */
  31.     public Session getSession() {
  32.         return getSession(
  33.             getConfigurationFileName());
  34.     }
  35.     /**
  36.      * Return a new Session object that must be closed when the work has been completed.
  37.      * @param configFile the config file must match the meta attribute "config-file" in the hibernate mapping file
  38.      * @return the active Session
  39.      */
  40.     protected Session getSession(String configFile) {
  41.         if (null != session && session.isOpen()) return session;
  42.         else if (null != sessionFactory) {
  43.             Session s = currentSession.get();
  44.             if (null == s || !s.isOpen()) {
  45.                 s = sessionFactory.openSession();
  46.                 currentSession.set(s);
  47.             }
  48.             return s;
  49.         }
  50.         else {
  51.             Session s = currentSession.get();
  52.             if (null == s || !s.isOpen()) {
  53.                 s = getSessionFactory(configFile).openSession();
  54.                 currentSession.set(s);
  55.             }
  56.             return s;
  57.         }
  58.     }
  59.     public void setSession (Session session) {
  60.         this.session = session;
  61.     }
  62.     /**
  63.      * Configure the session factory by reading hibernate config file
  64.      */
  65.     public static void initialize () {
  66.         test.src.dao._RootDAO.initialize(
  67.             (String) null);
  68.     }
  69.     
  70.     /**
  71.      * Configure the session factory by reading hibernate config file
  72.      * @param configFileName the name of the configuration file
  73.      */
  74.     public static void initialize (String configFileName) {
  75.         test.src.dao._RootDAO.initialize(
  76.             configFileName,
  77.             test.src.dao._RootDAO.getNewConfiguration(
  78.                 null));
  79.     }
  80.     public static void initialize (String configFileName, Configuration configuration) {
  81.         if (null != sessionFactoryMap && null != sessionFactoryMap.get(configFileName)) return;
  82.         else {
  83.             if (null == configFileName) {
  84.                 configuration.configure();
  85.                 test.src.dao._RootDAO.setSessionFactory(
  86.                     null,
  87.                     configuration.buildSessionFactory());
  88.             }
  89.             else {
  90.                 configuration.configure(
  91.                     configFileName);
  92.                 test.src.dao._RootDAO.setSessionFactory(
  93.                     configFileName,
  94.                     configuration.buildSessionFactory());
  95.             }
  96.         }
  97.     }
  98.     /**
  99.      * Set the session factory
  100.      */
  101.     public void setSessionFactory (SessionFactory sessionFactory) {
  102.         this.sessionFactory = sessionFactory;
  103.     }
  104.     /**
  105.      * Set the session factory
  106.      */
  107.     protected static void setSessionFactory (String configFileName, SessionFactory sf) {
  108.         if (null == configFileName) configFileName = "";
  109.         if (null == sessionFactoryMap) sessionFactoryMap = new HashMap<String, SessionFactory>();
  110.         sessionFactoryMap.put(
  111.             configFileName,
  112.             sf);
  113.     }
  114.     /**
  115.      * Return the SessionFactory that is to be used by these DAOs.  Change this
  116.      * and implement your own strategy if you, for example, want to pull the SessionFactory
  117.      * from the JNDI tree.
  118.      */
  119.     public SessionFactory getSessionFactory() {
  120.         if (null != sessionFactory) return sessionFactory;
  121.         else return getSessionFactory(
  122.         getConfigurationFileName());
  123.     }
  124.     public SessionFactory getSessionFactory(String configFileName) {
  125.         if (null == configFileName) configFileName = "";
  126.         if (null == sessionFactoryMap)
  127.             initialize(configFileName);
  128.         SessionFactory sf = (SessionFactory) sessionFactoryMap.get(configFileName);
  129.         if (null == sf)
  130.             throw new RuntimeException("The session factory for '" + configFileName + "' has not been initialized (or an error occured during initialization)");
  131.         else
  132.             return sf;
  133.     }
  134.     /**
  135.      * Close all sessions for the current thread
  136.      */
  137.     public static void closeCurrentSession () {
  138.         Session s = currentSession.get();
  139.         if (null != s) {
  140.             if (s.isOpen()) s.close();
  141.             currentSession.set(null);
  142.         }
  143.     }
  144.     /**
  145.      * Close the session
  146.      */
  147.     public void closeSession (Session session) {
  148.         if (null != session) session.close();
  149.     }
  150.     /**
  151.      * Begin the transaction related to the session
  152.      */
  153.     public Transaction beginTransaction(Session s) {
  154.         return s.beginTransaction();
  155.     }
  156.     /**
  157.      * Commit the given transaction
  158.      */
  159.     public void commitTransaction(Transaction t) {
  160.         t.commit();
  161.     }
  162.     /**
  163.      * Return a new Configuration to use.  This is not a mistake and is meant
  164.      * to be overridden in the RootDAO if you want to do something different.
  165.      * The file name is passed in so you have that to access.  The config file
  166.      * is read in the initialize method.
  167.      */
  168.      public static Configuration getNewConfiguration (String configFileName) {
  169.         return new Configuration();
  170.      }
  171.     
  172.     /**
  173.      * Return the name of the configuration file to be used with this DAO or null if default
  174.      */
  175.     public String getConfigurationFileName () {
  176.         return null;
  177.     }
  178.     /**
  179.      * Return the specific Object class that will be used for class-specific
  180.      * implementation of this DAO.
  181.      * @return the reference Class
  182.      */
  183.     protected abstract Class getReferenceClass();
  184.     /**
  185.      * Used by the base DAO classes but here for your modification
  186.      * Get object matching the given key and return it.
  187.      */
  188.     protected Object get(Class refClass, Serializable key) {
  189.         Session s = null;
  190.         try {
  191.             s = getSession();
  192.             return get(refClass, key, s);
  193.         } finally {
  194.             closeSession(s);
  195.         }
  196.     }
  197.     /**
  198.      * Used by the base DAO classes but here for your modification
  199.      * Get object matching the given key and return it.
  200.      */
  201.     protected Object get(Class refClass, Serializable key, Session s) {
  202.         return s.get(refClass, key);
  203.     }
  204.     /**
  205.      * Used by the base DAO classes but here for your modification
  206.      * Load object matching the given key and return it.
  207.      */
  208.     protected Object load(Class refClass, Serializable key) {
  209.         Session s = null;
  210.         try {
  211.             s = getSession();
  212.             return load(refClass, key, s);
  213.         } finally {
  214.             closeSession(s);
  215.         }
  216.     }
  217.     /**
  218.      * Used by the base DAO classes but here for your modification
  219.      * Load object matching the given key and return it.
  220.      */
  221.     protected Object load(Class refClass, Serializable key, Session s) {
  222.         return s.load(refClass, key);
  223.     }
  224.     /**
  225.      * Return all objects related to the implementation of this DAO with no filter.
  226.      */
  227.     public java.util.List findAll () {
  228.         Session s = null;
  229.         try {
  230.             s = getSession();
  231.             return findAll(s);
  232.         }
  233.         finally {
  234.             closeSession(s);
  235.         }
  236.     }
  237.     /**
  238.      * Return all objects related to the implementation of this DAO with no filter.
  239.      * Use the session given.
  240.      * @param s the Session
  241.      */
  242.     public java.util.List findAll (Session s) {
  243.         return findAll(s, getDefaultOrder());
  244.     }
  245.     /**
  246.      * Return all objects related to the implementation of this DAO with no filter.
  247.      */
  248.     public java.util.List findAll (Order defaultOrder) {
  249.         Session s = null;
  250.         try {
  251.             s = getSession();
  252.             return findAll(s, defaultOrder);
  253.         }
  254.         finally {
  255.             closeSession(s);
  256.         }
  257.     }
  258.     /**
  259.      * Return all objects related to the implementation of this DAO with no filter.
  260.      * Use the session given.
  261.      * @param s the Session
  262.      */
  263.     public java.util.List findAll (Session s, Order defaultOrder) {
  264.         Criteria crit = s.createCriteria(getReferenceClass());
  265.         if (null != defaultOrder) crit.addOrder(defaultOrder);
  266.         return crit.list();
  267.     }
  268.     /**
  269.      * Return all objects related to the implementation of this DAO with a filter.
  270.      * Use the session given.
  271.      * @param propName the name of the property to use for filtering
  272.      * @param filter the value of the filter
  273.      */
  274.     protected Criteria findFiltered (String propName, Object filter) {
  275.         return findFiltered(propName, filter, getDefaultOrder());
  276.     }
  277.     /**
  278.      * Return all objects related to the implementation of this DAO with a filter.
  279.      * Use the session given.
  280.      * @param propName the name of the property to use for filtering
  281.      * @param filter the value of the filter
  282.      * @param orderProperty the name of the property used for ordering
  283.      */
  284.     protected Criteria findFiltered (String propName, Object filter, Order order) {
  285.         Session s = null;
  286.         try {
  287.             s = getSession();
  288.             return findFiltered(s, propName, filter, order);
  289.         }
  290.         finally {
  291.             closeSession(s);
  292.         }
  293.     }
  294.     
  295.     /**
  296.      * Return all objects related to the implementation of this DAO with a filter.
  297.      * Use the session given.
  298.      * @param s the Session
  299.      * @param propName the name of the property to use for filtering
  300.      * @param filter the value of the filter
  301.      * @param orderProperty the name of the property used for ordering
  302.      */
  303.     protected Criteria findFiltered (Session s, String propName, Object filter, Order order) {
  304.         Criteria crit = s.createCriteria(getReferenceClass());
  305.         crit.add(Expression.eq(propName, filter));
  306.         if (null != order) crit.addOrder(order);
  307.         return crit;
  308.     }
  309.     
  310.     /**
  311.      * Obtain an instance of Query for a named query string defined in the mapping file.
  312.      * @param name the name of a query defined externally 
  313.      * @return Query
  314.      */
  315.     protected Query getNamedQuery(String name) {
  316.         Session s = null;
  317.         try {
  318.             s = getSession();
  319.             return getNamedQuery(name, s);
  320.         } finally {
  321.             closeSession(s);
  322.         }
  323.     }
  324.     /**
  325.      * Obtain an instance of Query for a named query string defined in the mapping file.
  326.      * Use the session given.
  327.      * @param name the name of a query defined externally 
  328.      * @param s the Session
  329.      * @return Query
  330.      */
  331.     protected Query getNamedQuery(String name, Session s) {
  332.         Query q = s.getNamedQuery(name);
  333.         return q;
  334.     }
  335.     /**
  336.      * Obtain an instance of Query for a named query string defined in the mapping file.
  337.      * @param name the name of a query defined externally 
  338.      * @param param the first parameter to set
  339.      * @return Query
  340.      */
  341.     protected Query getNamedQuery(String name, Serializable param) {
  342.         Session s = null;
  343.         try {
  344.             s = getSession();
  345.             return getNamedQuery(name, param, s);
  346.         } finally {
  347.             closeSession(s);
  348.         }
  349.     }
  350.     /**
  351.      * Obtain an instance of Query for a named query string defined in the mapping file.
  352.      * Use the session given.
  353.      * @param name the name of a query defined externally 
  354.      * @param param the first parameter to set
  355.      * @param s the Session
  356.      * @return Query
  357.      */
  358.     protected Query getNamedQuery(String name, Serializable param, Session s) {
  359.         Query q = s.getNamedQuery(name);
  360.         q.setParameter(0, param);
  361.         return q;
  362.     }
  363.     /**
  364.      * Obtain an instance of Query for a named query string defined in the mapping file.
  365.      * Use the parameters given.
  366.      * @param name the name of a query defined externally 
  367.      * @param params the parameter array
  368.      * @return Query
  369.      */
  370.     protected Query getNamedQuery(String name, Serializable[] params) {
  371.         Session s = null;
  372.         try {
  373.             s = getSession();
  374.             return getNamedQuery(name, params, s);
  375.         } finally {
  376.             closeSession(s);
  377.         }
  378.     }
  379.     /**
  380.      * Obtain an instance of Query for a named query string defined in the mapping file.
  381.      * Use the parameters given and the Session given.
  382.      * @param name the name of a query defined externally 
  383.      * @param params the parameter array
  384.      * @s the Session
  385.      * @return Query
  386.      */
  387.     protected Query getNamedQuery(String name, Serializable[] params, Session s) {
  388.         Query q = s.getNamedQuery(name);
  389.         if (null != params) {
  390.             for (int i = 0; i < params.length; i++) {
  391.                 q.setParameter(i, params[i]);
  392.             }
  393.         }
  394.         return q;
  395.     }
  396.     /**
  397.      * Obtain an instance of Query for a named query string defined in the mapping file.
  398.      * Use the parameters given.
  399.      * @param name the name of a query defined externally 
  400.      * @param params the parameter Map
  401.      * @return Query
  402.      */
  403.     protected Query getNamedQuery(String name, Map params) {
  404.         Session s = null;
  405.         try {
  406.             s = getSession();
  407.             return getNamedQuery(name, params, s);
  408.         } finally {
  409.             closeSession(s);
  410.         }
  411.     }
  412.     /**
  413.      * Obtain an instance of Query for a named query string defined in the mapping file.
  414.      * Use the parameters given and the Session given.
  415.      * @param name the name of a query defined externally 
  416.      * @param params the parameter Map
  417.      * @s the Session
  418.      * @return Query
  419.      */
  420.     protected Query getNamedQuery(String name, Map params, Session s) {
  421.         Query q = s.getNamedQuery(name);
  422.         if (null != params) {
  423.             for (Iterator i=params.entrySet().iterator(); i.hasNext(); ) {
  424.                 Map.Entry entry = (Map.Entry) i.next();
  425.                 q.setParameter((String) entry.getKey(), entry.getValue());
  426.             }
  427.         }
  428.         return q;
  429.     }
  430.     /**
  431.      * Execute a query. 
  432.      * @param queryStr a query expressed in Hibernate's query language
  433.      * @return a distinct list of instances (or arrays of instances)
  434.      */
  435.     public Query getQuery(String queryStr) {
  436.         Session s = null;
  437.         try {
  438.             s = getSession();
  439.             return getQuery(queryStr, s);
  440.         } finally {
  441.             closeSession(s);
  442.         }
  443.     }
  444.     /**
  445.      * Execute a query but use the session given instead of creating a new one.
  446.      * @param queryStr a query expressed in Hibernate's query language
  447.      * @s the Session to use
  448.      */
  449.     public Query getQuery(String queryStr, Session s) {
  450.         return s.createQuery(queryStr);
  451.     }
  452.     /**
  453.      * Execute a query. 
  454.      * @param query a query expressed in Hibernate's query language
  455.      * @param queryStr the name of a query defined externally 
  456.      * @param param the first parameter to set
  457.      * @return Query
  458.      */
  459.     protected Query getQuery(String queryStr, Serializable param) {
  460.         Session s = null;
  461.         try {
  462.             s = getSession();
  463.             return getQuery(queryStr, param, s);
  464.         } finally {
  465.             closeSession(s);
  466.         }
  467.     }
  468.     /**
  469.      * Execute a query but use the session given instead of creating a new one.
  470.      * @param queryStr a query expressed in Hibernate's query language
  471.      * @param param the first parameter to set
  472.      * @s the Session to use
  473.      * @return Query
  474.      */
  475.     protected Query getQuery(String queryStr, Serializable param, Session s) {
  476.         Query q = getQuery(queryStr, s);
  477.         q.setParameter(0, param);
  478.         return q;
  479.     }
  480.     /**
  481.      * Execute a query. 
  482.      * @param queryStr a query expressed in Hibernate's query language
  483.      * @param params the parameter array
  484.      * @return Query
  485.      */
  486.     protected Query getQuery(String queryStr, Serializable[] params) {
  487.         Session s = null;
  488.         try {
  489.             s = getSession();
  490.             return getQuery(queryStr, params, s);
  491.         } finally {
  492.             closeSession(s);
  493.         }
  494.     }
  495.     /**
  496.      * Execute a query but use the session given instead of creating a new one.
  497.      * @param queryStr a query expressed in Hibernate's query language
  498.      * @param params the parameter array
  499.      * @s the Session
  500.      * @return Query
  501.      */
  502.     protected Query getQuery(String queryStr, Serializable[] params, Session s) {
  503.         Query q = getQuery(queryStr, s);
  504.         if (null != params) {
  505.             for (int i = 0; i < params.length; i++) {
  506.                 q.setParameter(i, params[i]);
  507.             }
  508.         }
  509.         return q;
  510.     }
  511.     /**
  512.      * Obtain an instance of Query for a named query string defined in the mapping file.
  513.      * Use the parameters given.
  514.      * @param queryStr a query expressed in Hibernate's query language
  515.      * @param params the parameter Map
  516.      * @return Query
  517.      */
  518.     protected Query getQuery(String queryStr, Map params) {
  519.         Session s = null;
  520.         try {
  521.             s = getSession();
  522.             return getQuery(queryStr, params, s);
  523.         } finally {
  524.             closeSession(s);
  525.         }
  526.     }
  527.     /**
  528.      * Obtain an instance of Query for a named query string defined in the mapping file.
  529.      * Use the parameters given and the Session given.
  530.      * @param queryStr a query expressed in Hibernate's query language
  531.      * @param params the parameter Map
  532.      * @s the Session
  533.      * @return Query
  534.      */
  535.     protected Query getQuery(String queryStr, Map params, Session s) {
  536.         Query q = getQuery(queryStr, s);
  537.         if (null != params) {
  538.             for (Iterator i=params.entrySet().iterator(); i.hasNext(); ) {
  539.                 Map.Entry entry = (Map.Entry) i.next();
  540.                 q.setParameter((String) entry.getKey(), entry.getValue());
  541.             }
  542.         }
  543.         return q;
  544.     }
  545.     protected Order getDefaultOrder () {
  546.         return null;
  547.     }
  548.     /**
  549.      * Used by the base DAO classes but here for your modification
  550.      * Persist the given transient instance, first assigning a generated identifier. 
  551.      * (Or using the current value of the identifier property if the assigned generator is used.) 
  552.      */
  553.     protected Serializable save(final Object obj) {
  554.         return (Serializable) run (
  555.             new TransactionRunnable () {
  556.                 public Object run (Session s) {
  557.                     return save(obj, s);
  558.                 }
  559.             });
  560.     }
  561.     /**
  562.      * Used by the base DAO classes but here for your modification
  563.      * Persist the given transient instance, first assigning a generated identifier. 
  564.      * (Or using the current value of the identifier property if the assigned generator is used.) 
  565.      */
  566.     protected Serializable save(Object obj, Session s) {
  567.         return s.save(obj);
  568.     }
  569.     /**
  570.      * Used by the base DAO classes but here for your modification
  571.      * Either save() or update() the given instance, depending upon the value of its
  572.      * identifier property.
  573.      */
  574.     protected void saveOrUpdate(final Object obj) {
  575.         run (
  576.             new TransactionRunnable () {
  577.                 public Object run (Session s) {
  578.                     saveOrUpdate(obj, s);
  579.                     return null;
  580.                 }
  581.             });
  582.     }
  583.     /**
  584.      * Used by the base DAO classes but here for your modification
  585.      * Either save() or update() the given instance, depending upon the value of its
  586.      * identifier property.
  587.      */
  588.     protected void saveOrUpdate(Object obj, Session s) {
  589.         s.saveOrUpdate(obj);
  590.     }
  591.     /**
  592.      * Used by the base DAO classes but here for your modification
  593.      * Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent
  594.      * instance with the same identifier in the current session.
  595.      * @param obj a transient instance containing updated state
  596.      */
  597.     protected void update(final Object obj) {
  598.         run (
  599.             new TransactionRunnable () {
  600.                 public Object run (Session s) {
  601.                     update(obj, s);
  602.                     return null;
  603.                 }
  604.             });
  605.     }
  606.     /**
  607.      * Used by the base DAO classes but here for your modification
  608.      * Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent
  609.      * instance with the same identifier in the current session.
  610.      * @param obj a transient instance containing updated state
  611.      * @param s the Session
  612.      */
  613.     protected void update(Object obj, Session s) {
  614.         s.update(obj);
  615.     }
  616.     /**
  617.      * Delete all objects returned by the query
  618.      */
  619.     protected int delete (final Query query) {
  620.         Integer rtn = (Integer) run (
  621.             new TransactionRunnable () {
  622.                 public Object run (Session s) {
  623.                     return new Integer(delete((Query) query, s));
  624.                 }
  625.             });
  626.         return rtn.intValue();
  627.     }
  628.     /**
  629.      * Delete all objects returned by the query
  630.      */
  631.     protected int delete (Query query, Session s) {
  632.         List list = query.list();
  633.         for (Iterator i=list.iterator(); i.hasNext(); ) {
  634.             delete(i.next(), s);
  635.         }
  636.         return list.size();
  637.     }
  638.     /**
  639.      * Used by the base DAO classes but here for your modification
  640.      * Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
  641.      * Session or a transient instance with an identifier associated with existing persistent state. 
  642.      */
  643.     protected void delete(final Object obj) {
  644.         run (
  645.             new TransactionRunnable () {
  646.                 public Object run (Session s) {
  647.                     delete(obj, s);
  648.                     return null;
  649.                 }
  650.             });
  651.     }
  652.     /**
  653.      * Used by the base DAO classes but here for your modification
  654.      * Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
  655.      * Session or a transient instance with an identifier associated with existing persistent state. 
  656.      */
  657.     protected void delete(Object obj, Session s) {
  658.         s.delete(obj);
  659.     }
  660.     /**
  661.      * Used by the base DAO classes but here for your modification
  662.      * Re-read the state of the given instance from the underlying database. It is inadvisable to use this to implement
  663.      * long-running sessions that span many business tasks. This method is, however, useful in certain special circumstances.
  664.      */
  665.     protected void refresh(Object obj, Session s) {
  666.         s.refresh(obj);
  667.     }
  668.     protected void throwException (Throwable t) {
  669.         if (t instanceof HibernateException) throw (HibernateException) t;
  670.         else if (t instanceof RuntimeException) throw (RuntimeException) t;
  671.         else throw new HibernateException(t);
  672.     }
  673.     /**
  674.      * Execute the given transaction runnable.
  675.      */
  676.     protected Object run (TransactionRunnable transactionRunnable) {
  677.         Transaction t = null;
  678.         Session s = null;
  679.         try {
  680.             s = getSession();
  681.             t = beginTransaction(s);
  682.             Object obj = transactionRunnable.run(s);
  683.             commitTransaction(t);
  684.             return obj;
  685.         }
  686.         catch (Throwable throwable) {
  687.             if (null != t) {
  688.                 try {
  689.                     t.rollback();
  690.                 }
  691.                 catch (HibernateException e) {handleError(e);}
  692.             }
  693.             if (transactionRunnable instanceof TransactionFailHandler) {
  694.                 try {
  695.                     ((TransactionFailHandler) transactionRunnable).onFail(s);
  696.                 }
  697.                 catch (Throwable e) {handleError(e);}
  698.             }
  699.             throwException(throwable);
  700.             return null;
  701.         }
  702.         finally {
  703.             closeSession(s);
  704.         }
  705.     }
  706.     /**
  707.      * Execute the given transaction runnable.
  708.      */
  709.     protected TransactionPointer runAsnyc (TransactionRunnable transactionRunnable) {
  710.         final TransactionPointer transactionPointer = new TransactionPointer(transactionRunnable);
  711.         ThreadRunner threadRunner = new ThreadRunner(transactionPointer);
  712.         threadRunner.start();
  713.         return transactionPointer;
  714.     }
  715.     /**
  716.      * This class can be used to encapsulate logic used for a single transaction.
  717.      */
  718.     public abstract class TransactionRunnable {
  719.         public abstract Object run (Session s) throws Exception;
  720.     }
  721.     /**
  722.      * This class can be used to handle any error that has occured during a transaction
  723.      */
  724.     public interface TransactionFailHandler {
  725.         public void onFail (Session s);
  726.     }
  727.     /**
  728.      * This class can be used to handle failed transactions
  729.      */
  730.     public abstract class TransactionRunnableFailHandler extends TransactionRunnable implements TransactionFailHandler {
  731.     }
  732.     public class TransactionPointer {
  733.         private TransactionRunnable transactionRunnable;
  734.         private Throwable thrownException;
  735.         private Object returnValue;
  736.         private boolean hasCompleted = false;
  737.         
  738.         public TransactionPointer (TransactionRunnable transactionRunnable) {
  739.             this.transactionRunnable = transactionRunnable;
  740.         }
  741.         public boolean hasCompleted() {
  742.             return hasCompleted;
  743.         }
  744.         public void complete() {
  745.             this.hasCompleted = true;
  746.         }
  747.         
  748.         public Object getReturnValue() {
  749.             return returnValue;
  750.         }
  751.         public void setReturnValue(Object returnValue) {
  752.             this.returnValue = returnValue;
  753.         }
  754.         public Throwable getThrownException() {
  755.             return thrownException;
  756.         }
  757.         public void setThrownException(Throwable thrownException) {
  758.             this.thrownException = thrownException;
  759.         }
  760.         public TransactionRunnable getTransactionRunnable() {
  761.             return transactionRunnable;
  762.         }
  763.         public void setTransactionRunnable(TransactionRunnable transactionRunnable) {
  764.             this.transactionRunnable = transactionRunnable;
  765.         }
  766.         /**
  767.          * Wait until the transaction completes and return the value returned from the run method of the TransactionRunnable.
  768.          * If the transaction throws an Exception, throw that Exception.
  769.          * @param timeout the timeout in milliseconds (or 0 for no timeout)
  770.          * @return the return value from the TransactionRunnable
  771.          * @throws TimeLimitExcededException if the timeout has been reached before transaction completion
  772.          * @throws Throwable the thrown Throwable
  773.          */
  774.         public Object waitUntilFinish (long timeout) throws Throwable {
  775.             long killTime = -1;
  776.             if (timeout > 0) killTime = System.currentTimeMillis() + timeout;
  777.             do {
  778.                 try {
  779.                     Thread.sleep(50);
  780.                 }
  781.                 catch (InterruptedException e) {}
  782.             }
  783.             while (!hasCompleted && ((killTime > 0 && System.currentTimeMillis() < killTime) || killTime <= 0));
  784.             if (!hasCompleted) throw new javax.naming.TimeLimitExceededException();
  785.             if (null != thrownException) throw thrownException;
  786.             else return returnValue;
  787.         }
  788.     }
  789.     private class ThreadRunner extends Thread {
  790.         private TransactionPointer transactionPointer;
  791.         
  792.         public ThreadRunner (TransactionPointer transactionPointer) {
  793.             this.transactionPointer = transactionPointer;
  794.         }
  795.         
  796.         public void run () {
  797.             Transaction t = null;
  798.             Session s = null;
  799.             try {
  800.                 s = getSession();
  801.                 t = beginTransaction(s);
  802.                 Object obj = transactionPointer.getTransactionRunnable().run(s);
  803.                 t.commit();
  804.                 transactionPointer.setReturnValue(obj);
  805.             }
  806.             catch (Throwable throwable) {
  807.                 if (null != t) {
  808.                     try {
  809.                         t.rollback();
  810.                     }
  811.                     catch (HibernateException e) {handleError(e);}
  812.                 }
  813.                 if (transactionPointer.getTransactionRunnable() instanceof TransactionFailHandler) {
  814.                     try {
  815.                         ((TransactionFailHandler) transactionPointer.getTransactionRunnable()).onFail(s);
  816.                     }
  817.                     catch (Throwable e) {handleError(e);}
  818.                 }
  819.                 transactionPointer.setThrownException(throwable);
  820.             }
  821.             finally {
  822.                 transactionPointer.complete();
  823.                 try {
  824.                     closeSession(s);
  825.                 }
  826.                 catch (HibernateException e) {
  827.                     transactionPointer.setThrownException(e);
  828.                 }
  829.             }
  830.         }
  831.     }
  832.     protected void handleError (Throwable t) {
  833.     }
  834. }

BaseCdmaBts.java

  1. package test.src.base;
  2. import java.io.Serializable;
  3. /**
  4.  * This is an object that contains data related to the CDMA_BTS table.
  5.  * Do not modify this class because it will be overwritten if the configuration file
  6.  * related to this class is modified.
  7.  *
  8.  * @hibernate.class
  9.  *  table="CDMA_BTS"
  10.  */
  11. public abstract class BaseCdmaBts  implements Serializable {
  12.     public static String REF = "CdmaBts";
  13.     public static String PROP_RATED = "Rated";
  14.     public static String PROP_TYPE = "Type";
  15.     public static String PROP_PROPERTY = "Property";
  16.     public static String PROP_LOCAL = "Local";
  17.     public static String PROP_SPEC = "Spec";
  18.     public static String PROP_USEBEGINTIME = "Usebegintime";
  19.     public static String PROP_AREAID = "Areaid";
  20.     public static String PROP_IFSURVEY = "Ifsurvey";
  21.     public static String PROP_RECORDTIME = "Recordtime";
  22.     public static String PROP_TOWERID = "Towerid";
  23.     public static String PROP_FIXED_CODE = "FixedCode";
  24.     public static String PROP_CHAINCOUNT = "Chaincount";
  25.     public static String PROP_MAINTENANCE_MODE = "MaintenanceMode";
  26.     public static String PROP_BSCID = "Bscid";
  27.     public static String PROP_NETWORDCODE = "Networdcode";
  28.     public static String PROP_STAFF = "Staff";
  29.     public static String PROP_FACTORY = "Factory";
  30.     public static String PROP_SHOOTCOUNT = "Shootcount";
  31.     public static String PROP_ZCZT = "Zczt";
  32.     public static String PROP_CODE = "Code";
  33.     public static String PROP_COVERTYPE = "Covertype";
  34.     public static String PROP_NOTE = "Note";
  35.     public static String PROP_NAME = "Name";
  36.     public static String PROP_MAXSHOOT = "Maxshoot";
  37.     public static String PROP_BARNID = "Barnid";
  38.     public static String PROP_MSCID = "Mscid";
  39.     public static String PROP_STATE = "State";
  40.     public static String PROP_AEGISAGREEMENT = "Aegisagreement";
  41.     public static String PROP_MAINTENANCE = "Maintenance";
  42.     public static String PROP_STATIONID = "Stationid";
  43.     public static String PROP_WHBURDEN = "Whburden";
  44.     public static String PROP_ID = "Id";
  45.     // constructors
  46.     public BaseCdmaBts () {
  47.         initialize();
  48.     }
  49.     /**
  50.      * Constructor for primary key
  51.      */
  52.     public BaseCdmaBts (java.lang.Integer id) {
  53.         this.setId(id);
  54.         initialize();
  55.     }
  56.     protected void initialize () {}
  57.     private int hashCode = Integer.MIN_VALUE;
  58.     // primary key
  59.     private java.lang.Integer id;
  60.     // fields
  61.     private java.lang.String code;
  62.     private java.lang.String name;
  63.     private java.lang.Integer areaid;
  64.     private java.lang.Integer barnid;
  65.     private java.lang.Integer type;
  66.     private java.lang.String factory;
  67.     private java.lang.Integer spec;
  68.     private java.util.Date usebegintime;
  69.     private java.lang.Integer staff;
  70.     private java.util.Date recordtime;
  71.     private java.lang.Integer property;
  72.     private java.lang.String fixedCode;
  73.     private java.lang.Integer state;
  74.     private java.lang.Integer maintenanceMode;
  75.     private java.lang.String note;
  76.     private java.lang.Integer zczt;
  77.     private java.lang.String local;
  78.     private java.lang.Integer whburden;
  79.     private java.lang.Integer stationid;
  80.     private java.lang.Integer covertype;
  81.     private java.lang.Integer chaincount;
  82.     private java.lang.Integer shootcount;
  83.     private java.lang.Integer mscid;
  84.     private java.lang.Integer bscid;
  85.     private java.lang.Integer towerid;
  86.     private java.lang.Integer ifsurvey;
  87.     private java.lang.String networdcode;
  88.     private java.lang.Integer rated;
  89.     private java.lang.Integer maxshoot;
  90.     private java.lang.String maintenance;
  91.     private java.lang.String aegisagreement;
  92.     /**
  93.      * Return the unique identifier of this class
  94.      * @hibernate.id
  95.      *  generator-class="sequence"
  96.      *  column="ID"
  97.      */
  98.     public java.lang.Integer getId () {
  99.         return id;
  100.     }
  101.     /**
  102.      * Set the unique identifier of this class
  103.      * @param id the new ID
  104.      */
  105.     public void setId (java.lang.Integer id) {
  106.         this.id = id;
  107.         this.hashCode = Integer.MIN_VALUE;
  108.     }
  109.     /**
  110.      * Return the value associated with the column: CODE
  111.      */
  112.     public java.lang.String getCode () {
  113.         return code;
  114.     }
  115.     /**
  116.      * Set the value related to the column: CODE
  117.      * @param code the CODE value
  118.      */
  119.     public void setCode (java.lang.String code) {
  120.         this.code = code;
  121.     }
  122.     /**
  123.      * Return the value associated with the column: NAME
  124.      */
  125.     public java.lang.String getName () {
  126.         return name;
  127.     }
  128.     /**
  129.      * Set the value related to the column: NAME
  130.      * @param name the NAME value
  131.      */
  132.     public void setName (java.lang.String name) {
  133.         this.name = name;
  134.     }
  135.     /**
  136.      * Return the value associated with the column: AREAID
  137.      */
  138.     public java.lang.Integer getAreaid () {
  139.         return areaid;
  140.     }
  141.     /**
  142.      * Set the value related to the column: AREAID
  143.      * @param areaid the AREAID value
  144.      */
  145.     public void setAreaid (java.lang.Integer areaid) {
  146.         this.areaid = areaid;
  147.     }
  148.     /**
  149.      * Return the value associated with the column: BARNID
  150.      */
  151.     public java.lang.Integer getBarnid () {
  152.         return barnid;
  153.     }
  154.     /**
  155.      * Set the value related to the column: BARNID
  156.      * @param barnid the BARNID value
  157.      */
  158.     public void setBarnid (java.lang.Integer barnid) {
  159.         this.barnid = barnid;
  160.     }
  161.     /**
  162.      * Return the value associated with the column: TYPE
  163.      */
  164.     public java.lang.Integer getType () {
  165.         return type;
  166.     }
  167.     /**
  168.      * Set the value related to the column: TYPE
  169.      * @param type the TYPE value
  170.      */
  171.     public void setType (java.lang.Integer type) {
  172.         this.type = type;
  173.     }
  174.     /**
  175.      * Return the value associated with the column: FACTORY
  176.      */
  177.     public java.lang.String getFactory () {
  178.         return factory;
  179.     }
  180.     /**
  181.      * Set the value related to the column: FACTORY
  182.      * @param factory the FACTORY value
  183.      */
  184.     public void setFactory (java.lang.String factory) {
  185.         this.factory = factory;
  186.     }
  187.     /**
  188.      * Return the value associated with the column: SPEC
  189.      */
  190.     public java.lang.Integer getSpec () {
  191.         return spec;
  192.     }
  193.     /**
  194.      * Set the value related to the column: SPEC
  195.      * @param spec the SPEC value
  196.      */
  197.     public void setSpec (java.lang.Integer spec) {
  198.         this.spec = spec;
  199.     }
  200.     /**
  201.      * Return the value associated with the column: USEBEGINTIME
  202.      */
  203.     public java.util.Date getUsebegintime () {
  204.         return usebegintime;
  205.     }
  206.     /**
  207.      * Set the value related to the column: USEBEGINTIME
  208.      * @param usebegintime the USEBEGINTIME value
  209.      */
  210.     public void setUsebegintime (java.util.Date usebegintime) {
  211.         this.usebegintime = usebegintime;
  212.     }
  213.     /**
  214.      * Return the value associated with the column: STAFF
  215.      */
  216.     public java.lang.Integer getStaff () {
  217.         return staff;
  218.     }
  219.     /**
  220.      * Set the value related to the column: STAFF
  221.      * @param staff the STAFF value
  222.      */
  223.     public void setStaff (java.lang.Integer staff) {
  224.         this.staff = staff;
  225.     }
  226.     /**
  227.      * Return the value associated with the column: RECORDTIME
  228.      */
  229.     public java.util.Date getRecordtime () {
  230.         return recordtime;
  231.     }
  232.     /**
  233.      * Set the value related to the column: RECORDTIME
  234.      * @param recordtime the RECORDTIME value
  235.      */
  236.     public void setRecordtime (java.util.Date recordtime) {
  237.         this.recordtime = recordtime;
  238.     }
  239.     /**
  240.      * Return the value associated with the column: PROPERTY
  241.      */
  242.     public java.lang.Integer getProperty () {
  243.         return property;
  244.     }
  245.     /**
  246.      * Set the value related to the column: PROPERTY
  247.      * @param property the PROPERTY value
  248.      */
  249.     public void setProperty (java.lang.Integer property) {
  250.         this.property = property;
  251.     }
  252.     /**
  253.      * Return the value associated with the column: FIXED_CODE
  254.      */
  255.     public java.lang.String getFixedCode () {
  256.         return fixedCode;
  257.     }
  258.     /**
  259.      * Set the value related to the column: FIXED_CODE
  260.      * @param fixedCode the FIXED_CODE value
  261.      */
  262.     public void setFixedCode (java.lang.String fixedCode) {
  263.         this.fixedCode = fixedCode;
  264.     }
  265.     /**
  266.      * Return the value associated with the column: STATE
  267.      */
  268.     public java.lang.Integer getState () {
  269.         return state;
  270.     }
  271.     /**
  272.      * Set the value related to the column: STATE
  273.      * @param state the STATE value
  274.      */
  275.     public void setState (java.lang.Integer state) {
  276.         this.state = state;
  277.     }
  278.     /**
  279.      * Return the value associated with the column: MAINTENANCE_MODE
  280.      */
  281.     public java.lang.Integer getMaintenanceMode () {
  282.         return maintenanceMode;
  283.     }
  284.     /**
  285.      * Set the value related to the column: MAINTENANCE_MODE
  286.      * @param maintenanceMode the MAINTENANCE_MODE value
  287.      */
  288.     public void setMaintenanceMode (java.lang.Integer maintenanceMode) {
  289.         this.maintenanceMode = maintenanceMode;
  290.     }
  291.     /**
  292.      * Return the value associated with the column: NOTE
  293.      */
  294.     public java.lang.String getNote () {
  295.         return note;
  296.     }
  297.     /**
  298.      * Set the value related to the column: NOTE
  299.      * @param note the NOTE value
  300.      */
  301.     public void setNote (java.lang.String note) {
  302.         this.note = note;
  303.     }
  304.     /**
  305.      * Return the value associated with the column: ZCZT
  306.      */
  307.     public java.lang.Integer getZczt () {
  308.         return zczt;
  309.     }
  310.     /**
  311.      * Set the value related to the column: ZCZT
  312.      * @param zczt the ZCZT value
  313.      */
  314.     public void setZczt (java.lang.Integer zczt) {
  315.         this.zczt = zczt;
  316.     }
  317.     /**
  318.      * Return the value associated with the column: LOCAL
  319.      */
  320.     public java.lang.String getLocal () {
  321.         return local;
  322.     }
  323.     /**
  324.      * Set the value related to the column: LOCAL
  325.      * @param local the LOCAL value
  326.      */
  327.     public void setLocal (java.lang.String local) {
  328.         this.local = local;
  329.     }
  330.     /**
  331.      * Return the value associated with the column: WHBURDEN
  332.      */
  333.     public java.lang.Integer getWhburden () {
  334.         return whburden;
  335.     }
  336.     /**
  337.      * Set the value related to the column: WHBURDEN
  338.      * @param whburden the WHBURDEN value
  339.      */
  340.     public void setWhburden (java.lang.Integer whburden) {
  341.         this.whburden = whburden;
  342.     }
  343.     /**
  344.      * Return the value associated with the column: STATIONID
  345.      */
  346.     public java.lang.Integer getStationid () {
  347.         return stationid;
  348.     }
  349.     /**
  350.      * Set the value related to the column: STATIONID
  351.      * @param stationid the STATIONID value
  352.      */
  353.     public void setStationid (java.lang.Integer stationid) {
  354.         this.stationid = stationid;
  355.     }
  356.     /**
  357.      * Return the value associated with the column: COVERTYPE
  358.      */
  359.     public java.lang.Integer getCovertype () {
  360.         return covertype;
  361.     }
  362.     /**
  363.      * Set the value related to the column: COVERTYPE
  364.      * @param covertype the COVERTYPE value
  365.      */
  366.     public void setCovertype (java.lang.Integer covertype) {
  367.         this.covertype = covertype;
  368.     }
  369.     /**
  370.      * Return the value associated with the column: CHAINCOUNT
  371.      */
  372.     public java.lang.Integer getChaincount () {
  373.         return chaincount;
  374.     }
  375.     /**
  376.      * Set the value related to the column: CHAINCOUNT
  377.      * @param chaincount the CHAINCOUNT value
  378.      */
  379.     public void setChaincount (java.lang.Integer chaincount) {
  380.         this.chaincount = chaincount;
  381.     }
  382.     /**
  383.      * Return the value associated with the column: SHOOTCOUNT
  384.      */
  385.     public java.lang.Integer getShootcount () {
  386.         return shootcount;
  387.     }
  388.     /**
  389.      * Set the value related to the column: SHOOTCOUNT
  390.      * @param shootcount the SHOOTCOUNT value
  391.      */
  392.     public void setShootcount (java.lang.Integer shootcount) {
  393.         this.shootcount = shootcount;
  394.     }
  395.     /**
  396.      * Return the value associated with the column: MSCID
  397.      */
  398.     public java.lang.Integer getMscid () {
  399.         return mscid;
  400.     }
  401.     /**
  402.      * Set the value related to the column: MSCID
  403.      * @param mscid the MSCID value
  404.      */
  405.     public void setMscid (java.lang.Integer mscid) {
  406.         this.mscid = mscid;
  407.     }
  408.     /**
  409.      * Return the value associated with the column: BSCID
  410.      */
  411.     public java.lang.Integer getBscid () {
  412.         return bscid;
  413.     }
  414.     /**
  415.      * Set the value related to the column: BSCID
  416.      * @param bscid the BSCID value
  417.      */
  418.     public void setBscid (java.lang.Integer bscid) {
  419.         this.bscid = bscid;
  420.     }
  421.     /**
  422.      * Return the value associated with the column: TOWERID
  423.      */
  424.     public java.lang.Integer getTowerid () {
  425.         return towerid;
  426.     }
  427.     /**
  428.      * Set the value related to the column: TOWERID
  429.      * @param towerid the TOWERID value
  430.      */
  431.     public void setTowerid (java.lang.Integer towerid) {
  432.         this.towerid = towerid;
  433.     }
  434.     /**
  435.      * Return the value associated with the column: IFSURVEY
  436.      */
  437.     public java.lang.Integer getIfsurvey () {
  438.         return ifsurvey;
  439.     }
  440.     /**
  441.      * Set the value related to the column: IFSURVEY
  442.      * @param ifsurvey the IFSURVEY value
  443.      */
  444.     public void setIfsurvey (java.lang.Integer ifsurvey) {
  445.         this.ifsurvey = ifsurvey;
  446.     }
  447.     /**
  448.      * Return the value associated with the column: NETWORDCODE
  449.      */
  450.     public java.lang.String getNetwordcode () {
  451.         return networdcode;
  452.     }
  453.     /**
  454.      * Set the value related to the column: NETWORDCODE
  455.      * @param networdcode the NETWORDCODE value
  456.      */
  457.     public void setNetwordcode (java.lang.String networdcode) {
  458.         this.networdcode = networdcode;
  459.     }
  460.     /**
  461.      * Return the value associated with the column: RATED
  462.      */
  463.     public java.lang.Integer getRated () {
  464.         return rated;
  465.     }
  466.     /**
  467.      * Set the value related to the column: RATED
  468.      * @param rated the RATED value
  469.      */
  470.     public void setRated (java.lang.Integer rated) {
  471.         this.rated = rated;
  472.     }
  473.     /**
  474.      * Return the value associated with the column: MAXSHOOT
  475.      */
  476.     public java.lang.Integer getMaxshoot () {
  477.         return maxshoot;
  478.     }
  479.     /**
  480.      * Set the value related to the column: MAXSHOOT
  481.      * @param maxshoot the MAXSHOOT value
  482.      */
  483.     public void setMaxshoot (java.lang.Integer maxshoot) {
  484.         this.maxshoot = maxshoot;
  485.     }
  486.     /**
  487.      * Return the value associated with the column: MAINTENANCE
  488.      */
  489.     public java.lang.String getMaintenance () {
  490.         return maintenance;
  491.     }
  492.     /**
  493.      * Set the value related to the column: MAINTENANCE
  494.      * @param maintenance the MAINTENANCE value
  495.      */
  496.     public void setMaintenance (java.lang.String maintenance) {
  497.         this.maintenance = maintenance;
  498.     }
  499.     /**
  500.      * Return the value associated with the column: AEGISAGREEMENT
  501.      */
  502.     public java.lang.String getAegisagreement () {
  503.         return aegisagreement;
  504.     }
  505.     /**
  506.      * Set the value related to the column: AEGISAGREEMENT
  507.      * @param aegisagreement the AEGISAGREEMENT value
  508.      */
  509.     public void setAegisagreement (java.lang.String aegisagreement) {
  510.         this.aegisagreement = aegisagreement;
  511.     }
  512.     public boolean equals (Object obj) {
  513.         if (null == obj) return false;
  514.         if (!(obj instanceof test.src.CdmaBts)) return false;
  515.         else {
  516.             test.src.CdmaBts cdmaBts = (test.src.CdmaBts) obj;
  517.             if (null == this.getId() || null == cdmaBts.getId()) return false;
  518.             else return (this.getId().equals(cdmaBts.getId()));
  519.         }
  520.     }
  521.     public int hashCode () {
  522.         if (Integer.MIN_VALUE == this.hashCode) {
  523.             if (null == this.getId()) return super.hashCode();
  524.             else {
  525.                 String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
  526.                 this.hashCode = hashStr.hashCode();
  527.             }
  528.         }
  529.         return this.hashCode;
  530.     }
  531.     public String toString () {
  532.         return super.toString();
  533.     }
  534. }

 

BaseCdmaBtsDAO.java

  1. package test.src.base;
  2. import org.hibernate.Hibernate;
  3. import org.hibernate.Session;
  4. import test.src.dao.iface.CdmaBtsDAO;
  5. import org.hibernate.criterion.Order;
  6. /**
  7.  * This is an automatically generated DAO class which should not be edited.
  8.  */
  9. public abstract class BaseCdmaBtsDAO extends test.src.dao._RootDAO {
  10.     public BaseCdmaBtsDAO () {}
  11.     
  12.     public BaseCdmaBtsDAO (Session session) {
  13.         super(session);
  14.     }
  15.     // query name references
  16.     public static CdmaBtsDAO instance;
  17.     /**
  18.      * Return a singleton of the DAO
  19.      */
  20.     public static CdmaBtsDAO getInstance () {
  21.         if (null == instance) instance = new test.src.dao.CdmaBtsDAO();
  22.         return instance;
  23.     }
  24.     public Class getReferenceClass () {
  25.         return test.src.CdmaBts.class;
  26.     }
  27.     public Order getDefaultOrder () {
  28.         return Order.asc("Name");
  29.     }
  30.     /**
  31.      * Cast the object as a test.src.CdmaBts
  32.      */
  33.     public test.src.CdmaBts cast (Object object) {
  34.         return (test.src.CdmaBts) object;
  35.     }
  36.     public test.src.CdmaBts get(java.lang.Integer key)
  37.     {
  38.         return (test.src.CdmaBts) get(getReferenceClass(), key);
  39.     }
  40.     public test.src.CdmaBts get(java.lang.Integer key, Session s)
  41.     {
  42.         return (test.src.CdmaBts) get(getReferenceClass(), key, s);
  43.     }
  44.     public test.src.CdmaBts load(java.lang.Integer key)
  45.     {
  46.         return (test.src.CdmaBts) load(getReferenceClass(), key);
  47.     }
  48.     public test.src.CdmaBts load(java.lang.Integer key, Session s)
  49.     {
  50.         return (test.src.CdmaBts) load(getReferenceClass(), key, s);
  51.     }
  52.     public test.src.CdmaBts loadInitialize(java.lang.Integer key, Session s) 
  53.     { 
  54.         test.src.CdmaBts obj = load(key, s); 
  55.         if (!Hibernate.isInitialized(obj)) {
  56.             Hibernate.initialize(obj);
  57.         } 
  58.         return obj; 
  59.     }
  60. /* Generic methods */
  61.     /**
  62.      * Return all objects related to the implementation of this DAO with no filter.
  63.      */
  64.     public java.util.List<test.src.CdmaBts> findAll () {
  65.         return super.findAll();
  66.     }
  67.     /**
  68.      * Return all objects related to the implementation of this DAO with no filter.
  69.      */
  70.     public java.util.List<test.src.CdmaBts> findAll (Order defaultOrder) {
  71.         return super.findAll(defaultOrder);
  72.     }
  73.     /**
  74.      * Return all objects related to the implementation of this DAO with no filter.
  75.      * Use the session given.
  76.      * @param s the Session
  77.      */
  78.     public java.util.List<test.src.CdmaBts> findAll (Session s, Order defaultOrder) {
  79.         return super.findAll(s, defaultOrder);
  80.     }
  81.     /**
  82.      * Persist the given transient instance, first assigning a generated identifier. (Or using the current value
  83.      * of the identifier property if the assigned generator is used.) 
  84.      * @param cdmaBts a transient instance of a persistent class 
  85.      * @return the class identifier
  86.      */
  87.     public java.lang.Integer save(test.src.CdmaBts cdmaBts)
  88.     {
  89.         return (java.lang.Integer) super.save(cdmaBts);
  90.     }
  91.     /**
  92.      * Persist the given transient instance, first assigning a generated identifier. (Or using the current value
  93.      * of the identifier property if the assigned generator is used.) 
  94.      * Use the Session given.
  95.      * @param cdmaBts a transient instance of a persistent class
  96.      * @param s the Session
  97.      * @return the class identifier
  98.      */
  99.     public java.lang.Integer save(test.src.CdmaBts cdmaBts, Session s)
  100.     {
  101.         return (java.lang.Integer) save((Object) cdmaBts, s);
  102.     }
  103.     /**
  104.      * Either save() or update() the given instance, depending upon the value of its identifier property. By default
  105.      * the instance is always saved. This behaviour may be adjusted by specifying an unsaved-value attribute of the
  106.      * identifier property mapping. 
  107.      * @param cdmaBts a transient instance containing new or updated state 
  108.      */
  109.     public void saveOrUpdate(test.src.CdmaBts cdmaBts)
  110.     {
  111.         saveOrUpdate((Object) cdmaBts);
  112.     }
  113.     /**
  114.      * Either save() or update() the given instance, depending upon the value of its identifier property. By default the
  115.      * instance is always saved. This behaviour may be adjusted by specifying an unsaved-value attribute of the identifier
  116.      * property mapping. 
  117.      * Use the Session given.
  118.      * @param cdmaBts a transient instance containing new or updated state.
  119.      * @param s the Session.
  120.      */
  121.     public void saveOrUpdate(test.src.CdmaBts cdmaBts, Session s)
  122.     {
  123.         saveOrUpdate((Object) cdmaBts, s);
  124.     }
  125.     /**
  126.      * Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent
  127.      * instance with the same identifier in the current session.
  128.      * @param cdmaBts a transient instance containing updated state
  129.      */
  130.     public void update(test.src.CdmaBts cdmaBts) 
  131.     {
  132.         update((Object) cdmaBts);
  133.     }
  134.     /**
  135.      * Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent
  136.      * instance with the same identifier in the current session.
  137.      * Use the Session given.
  138.      * @param cdmaBts a transient instance containing updated state
  139.      * @param the Session
  140.      */
  141.     public void update(test.src.CdmaBts cdmaBts, Session s)
  142.     {
  143.         update((Object) cdmaBts, s);
  144.     }
  145.     /**
  146.      * Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
  147.      * Session or a transient instance with an identifier associated with existing persistent state. 
  148.      * @param id the instance ID to be removed
  149.      */
  150.     public void delete(java.lang.Integer id)
  151.     {
  152.         delete((Object) load(id));
  153.     }
  154.     /**
  155.      * Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
  156.      * Session or a transient instance with an identifier associated with existing persistent state. 
  157.      * Use the Session given.
  158.      * @param id the instance ID to be removed
  159.      * @param s the Session
  160.      */
  161.     public void delete(java.lang.Integer id, Session s)
  162.     {
  163.         delete((Object) load(id, s), s);
  164.     }
  165.     /**
  166.      * Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
  167.      * Session or a transient instance with an identifier associated with existing persistent state. 
  168.      * @param cdmaBts the instance to be removed
  169.      */
  170.     public void delete(test.src.CdmaBts cdmaBts)
  171.     {
  172.         delete((Object) cdmaBts);
  173.     }
  174.     /**
  175.      * Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
  176.      * Session or a transient instance with an identifier associated with existing persistent state. 
  177.      * Use the Session given.
  178.      * @param cdmaBts the instance to be removed
  179.      * @param s the Session
  180.      */
  181.     public void delete(test.src.CdmaBts cdmaBts, Session s)
  182.     {
  183.         delete((Object) cdmaBts, s);
  184.     }
  185.     
  186.     /**
  187.      * Re-read the state of the given instance from the underlying database. It is inadvisable to use this to implement
  188.      * long-running sessions that span many business tasks. This method is, however, useful in certain special circumstances.
  189.      * For example 
  190.      * <ul> 
  191.      * <li>where a database trigger alters the object state upon insert or update</li>
  192.      * <li>after executing direct SQL (eg. a mass update) in the same session</li>
  193.      * <li>after inserting a Blob or Clob</li>
  194.      * </ul>
  195.      */
  196.     public void refresh (test.src.CdmaBts cdmaBts, Session s)
  197.     {
  198.         refresh((Object) cdmaBts, s);
  199.     }
  200. }

 

_RootDAO.java

  1. package test.src.dao;
  2. import org.hibernate.Session;
  3. public abstract class _RootDAO extends test.src.base._BaseRootDAO {
  4.     public _RootDAO () {}
  5.     
  6.     public _RootDAO (Session session) {
  7.         setSession(session);
  8.     }
  9. /*
  10.     If you are using lazy loading, uncomment this
  11.     Somewhere, you should call RootDAO.closeCurrentThreadSessions();
  12.     public void closeSession (Session session) {
  13.         // do nothing here because the session will be closed later
  14.     }
  15. */
  16. /*
  17.     If you are pulling the SessionFactory from a JNDI tree, uncomment this
  18.     protected SessionFactory getSessionFactory(String configFile) {
  19.         // If you have a single session factory, ignore the configFile parameter
  20.         // Otherwise, you can set a meta attribute under the class node called "config-file" which
  21.         // will be passed in here so you can tell what session factory an individual mapping file
  22.         // belongs to
  23.         return (SessionFactory) new InitialContext().lookup("java:/{SessionFactoryName}");
  24.     }
  25. */
  26. }

CdmaBtsDAO.java

  1. package test.src.dao;
  2. import org.hibernate.Session;
  3. import test.src.base.BaseCdmaBtsDAO;
  4. public class CdmaBtsDAO extends BaseCdmaBtsDAO implements test.src.dao.iface.CdmaBtsDAO {
  5.     public CdmaBtsDAO () {}
  6.     
  7.     public CdmaBtsDAO (Session session) {
  8.         super(session);
  9.     }
  10. }

最后,是JUNIT 測試類:CdmaBtsTest

 

CdmaBtsDAO.java

  1. package test.src.dao.iface;
  2. import java.io.Serializable;
  3. public interface CdmaBtsDAO {
  4.     public test.src.CdmaBts get(java.lang.Integer key);
  5.     public test.src.CdmaBts load(java.lang.Integer key);
  6.     public java.util.List<test.src.CdmaBts> findAll ();
  7.     /**
  8.      * Persist the given transient instance, first assigning a generated identifier. (Or using the current value
  9.      * of the identifier property if the assigned generator is used.) 
  10.      * @param cdmaBts a transient instance of a persistent class 
  11.      * @return the class identifier
  12.      */
  13.     public java.lang.Integer save(test.src.CdmaBts cdmaBts);
  14.     /**
  15.      * Either save() or update() the given instance, depending upon the value of its identifier property. By default
  16.      * the instance is always saved. This behaviour may be adjusted by specifying an unsaved-value attribute of the
  17.      * identifier property mapping. 
  18.      * @param cdmaBts a transient instance containing new or updated state 
  19.      */
  20.     public void saveOrUpdate(test.src.CdmaBts cdmaBts);
  21.     /**
  22.      * Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent
  23.      * instance with the same identifier in the current session.
  24.      * @param cdmaBts a transient instance containing updated state
  25.      */
  26.     public void update(test.src.CdmaBts cdmaBts);
  27.     /**
  28.      * Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
  29.      * Session or a transient instance with an identifier associated with existing persistent state. 
  30.      * @param id the instance ID to be removed
  31.      */
  32.     public void delete(java.lang.Integer id);
  33.     /**
  34.      * Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
  35.      * Session or a transient instance with an identifier associated with existing persistent state. 
  36.      * @param cdmaBts the instance to be removed
  37.      */
  38.     public void delete(test.src.CdmaBts cdmaBts);
  39. }

        最后,是JUNIT 的测试类:CdmaBtsTest.java

  1. package test.src;
  2. import junit.framework.TestCase;
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import test.src.dao.CdmaBtsDAO;
  6. import test.src.dao._RootDAO;
  7. public class CdmaBtsTest extends TestCase {
  8.     @Before
  9.     public void setUp() throws Exception {
  10.     }
  11.     @After
  12.     public void tearDown() throws Exception {
  13.     }
  14.     public void testInsert() {
  15.         /*
  16.          * sessionFactory=new Configuration().configure().buildSessionFactory();
  17.          * Session s=sessionFactory.openSession();
  18.          * 
  19.          * Transaction t=s.beginTransaction();
  20.          * 
  21.          * CdmaBts bts=new CdmaBts("1001"); bts.setCODE("What");
  22.          * 
  23.          * s.save(bts); t.commit(); s.close();
  24.          */
  25.         _RootDAO.initialize();
  26.         CdmaBtsDAO dao = new CdmaBtsDAO();
  27.         CdmaBts bts = new CdmaBts();
  28. //      bts.setId(11032);
  29.         bts.setCode(bts.toString());
  30.         dao.save(bts);
  31.     }
  32. }

      另外,还需要新建一个log4j.properties文件:

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=warn, stdout

#log4j.logger.org.hibernate=info
log4j.logger.org.hibernate=debug

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug

### log just the SQL
#log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug

### log cache activity ###
#log4j.logger.org.hibernate.cache=debug

### log transaction activity
#log4j.logger.org.hibernate.transaction=debug

### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
 

       以上是一个简单的 hibernate 实例。

 

      可以运行 junit 测试类 CdmaBtsTest 看到运行结果。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值