My-java-spark

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            5 Posts :: 0 Stories :: 4 Comments :: 0 Trackbacks

          2006年1月22日 #

          <script>
                  function window.onbeforeunload()  {
                          if (event.clientX > document.body.clientHeight || event.clientY < 0 || event.altKey)  {
                                alert("That's good.");
                          }
                  }
          </script>
           

          <--------屏蔽F5、Alt+F4的錯-------->

          <script>
                  function window.onbeforeunload()  {


                          if((event.keyCode != 0) && (event.clientX > document.body.clientHeight || event.clientY < 0) || event.altKey)  {

                                alert("That's good.");
                          }
                  }
          </script>

          posted @ 2006-01-22 15:23 spark 閱讀(417) | 評論 (0)編輯 收藏

          2006年1月16日 #

          需求分析的主要方法是用例(use-case).
          系統級別的需求其實就是系統的參與者們所要達到的目標,每一個目標就是一個用例。用例就是參與者參與活動的場景描述。
          每個用例參與者有三種,主要參與者,次要參與者和后臺參與者。用例為其工作的參與者就是主要參與者,為用例提供服務的參與者就是次要參與者,用例結果產生影響的參與者是后臺參與者。
          用例一般有前置條件和后置條件,當前置條件為真時,用例才開始運作,當用例順利完成,用例的后置條件為真。用例主要描述活動執行的“歡樂路徑”,如果在某一步有異常情況則到用例擴展中去說明。
          如果多個用例中有重復的部分,則可以提取成一個子用例。
          posted @ 2006-01-16 23:42 spark 閱讀(754) | 評論 (1)編輯 收藏

          2005年11月21日 #

          JDBC隔離級別 特征
          TRANSACTION_READ_UNCOMMITTED
          未提交的讀操作
          • 允許讀取有寫鎖定或無寫鎖定的行
          • 未應用讀鎖定
          • 無法確保并發事務將不會修改行或回退對行所做的更改
          TRANSACTION_READ_COMMITTED
          已提交的讀操作
          • 只允許讀取沒有寫鎖定的行
          • 僅為讀取當前行獲取并保持讀鎖定,但當游標離開該行時釋放讀鎖定
          • 無法確保數據在事務執行過程中不發生更改
          TRANSACTION_REPEATABLE_READ
          可重復的讀操作
          • 只允許讀取沒有寫鎖定的行
          • 讀取結果集中的每一行時獲取讀鎖定,并一直保持到事務結束為止
          TRANSACTION_SERIALIZABLE
          可序列化
          • 只允許讀取結果中沒有寫鎖定的行
          • 打開游標時獲取讀鎖定,并一直保持到事務結束為止
          posted @ 2005-11-21 11:10 spark 閱讀(1047) | 評論 (0)編輯 收藏

          2005年9月14日 #

             Spring為應用程序提供一個容器, 為應用程序的管理帶來了方便. 它與hibernate的結合, 形成一個完整的后臺體系, 也是當今應用開發流行的做法. 奮斗了一個晚上, 終于把hibernate3與spring整合了起來, hibernate2.x和hibernate3與spring的結合稍有不同, 關鍵是引入的spring的包的不同, 下面我會標識出來.

          Spring 的配置文件applicationContext.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE beans PUBLIC "spring" "../../../lib/spring-beans.dtd" >
          <beans default-autowire="no" default-dependency-check="none" default-lazy-init="false">

          <!-- 
             配置數據源
             注意: 用org.apache.commons.dbcp.BasicDataSource, 要引入 apache commons 
             的commons-collections-3.1.jar, commons-dbcp-1.2.1.jar, commons-pool-1.2.jar三個包
           
          -->
           
          <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            
          <property name="driverClassName">
             
          <value>org.gjt.mm.mysql.Driver</value>
            
          </property>
            
          <property name="url">
             
          <value>jdbc:mysql://localhost/sparkcrm</value>
            
          </property>
            
          <property name="username">
             
          <value>root</value>
            
          </property>
            
          <property name="password">
             
          <value>1111</value>
            
          </property>
           
          </bean>

           
          <!-- 配置sessionFactory, 注意這里引入的包的不同  -->
           
          <bean id="sessionFactory"
            class
          ="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            
          <property name="dataSource">
             
          <ref local="dataSource" />
            
          </property>
            
          <property name="mappingResources">
             
          <list>
               
          <value>com/sparkcrm/schema/entities/Lead.hbm.xml</value>
              
          </list>
            
          </property>
            
          <property name="hibernateProperties">
             
          <props>
              
          <prop key="hibernate.dialect">
               org.hibernate.dialect.MySQLDialect
              
          </prop>
              
          <prop key="hibernate.show_sql">true</prop>
             
          </props>
            
          </property>
           
          </bean>
           
            <!-- 配置transactionManager, 注意這里引入的包的不同  -->
           
          <bean id="transactionManager" 
            class
          ="org.springframework.orm.hibernate3.HibernateTransactionManager">
            
          <property name="sessionFactory">
             
          <ref local="sessionFactory" />
            
          </property>
           
          </bean>

          <--事務代理在這里配置, 這里省略了 -->

           
          <bean id="leadDAO" class="com.sparkcrm.schema.dao.LeadDao">
            
          <property name="sessionFactory">
             
          <ref local="sessionFactory" />
            
          </property>
           
          </bean>

          </beans>



          一個示例的hibernate的映射文件

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE hibernate-mapping PUBLIC 
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
          >
              
          <hibernate-mapping package="com.sparkcrm.schema.entities">
                
             <!-- 我在這里用了hibernate的動態模型(dynamic models) , 沒用pojo-->
              
          <class entity-name="Lead" table="Lead">
                  
          <id name="id" column="id" type="string">
                      
          <generator class="uuid.hex"/>
                  
          </id>
                  
          <property name="companyName" type="string"/>
                  
          <property name="topic" type="string"/>
                  
          <property name="contactName" type="string"/>
              
          </class>
          </hibernate-mapping>


          DAO代碼:

          import java.util.Map;
          /**
             * DAO接口
             */
          public interface IDAO {

              String create(Map
          <String, Object> map);
              
              
          void update(Map<String, Object> map);
              
              Map
          <String, Object> delete(String id);
              
              boolean share(String id, String userId, 
          int rights);
              
              boolean assign(String id, String userId);
          }



          import java.util.Map;

          import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

          import com.sparkcrm.schema.IDAO;
          import com.sparkcrm.schema.Schema;
          import com.sparkcrm.schema.metadata.Lead;
          /**
              *一個示例的DAO實現, 繼承HibernateDaoSupport, 用spring帶來的管理session等的便利
              */
          public
           class LeadDao extends HibernateDaoSupport implements IDAO {

              
          public String create(Map<String, Object> map) {
                  getHibernateTemplate().saveOrUpdate(Schema.LEAD, map);
                  
          return (String) map.get(Lead.ID);
              }


              public
           void update(Map<String, Object> map) {
                  
              }


              public
           Map<String, Object> delete(String id) {
                  
          return null;
              }


              public
           boolean share(String id, String userId, int rights) {
                  
          return false;
              }


              public
           boolean assign(String id, String userId) {
                  
          return false;
              }


          }

          示意性的測試代碼:

          import java.sql.Timestamp;
          import java.util.Date;
          import java.util.HashMap;
          import java.util.Map;

          import junit.framework.TestCase;

          import org.springframework.context.support.ClassPathXmlApplicationContext;

          import com.sparkcrm.schema.IDAO;

          public class testLeadDAO extends TestCase {
              
              ClassPathXmlApplicationContext ctx 
          = null;
              
              
          public void setUp(){
                  ctx 
          = new ClassPathXmlApplicationContext("applicationContext.xml");
              }

              
              
          public void testCreateLead(){
                   IDAO leadDao 
          = (IDAO) ctx.getBean("leadDAO");

                  Map
          <String, Object> map = new HashMap<String, Object>();
                  map.put(
          "companyName""Spark Ltd.");
                  map.put(
          "topic""This is a Good Lead!");
                  map.put(
          "contactName""abcd");
                  
                  String id 
          = leadDao.create(map);
                  System.
          out.println(id);
              }

          }

          posted @ 2005-09-14 23:16 spark 閱讀(3768) | 評論 (1)編輯 收藏

          2005年9月12日 #

                 Hibernate的動態模型為我們動態改動表結構帶來了方便, 個人認為這一點非常有價值, 現在的企業級應用系統越來越強調用戶可定制性, hibernate的這一點使用戶自定義字段或自定義表成為可能 .
          關于動態模型, 我還是把hibernate自帶的測試用例貼到這里, 用以備忘.

          java代碼:

          //$Id: DynamicClassTest.java,v 1.4 2005/03/06 16:31:24 oneovthafew Exp $
          package org.hibernate.test.dynamic;

          import java.util.ArrayList;
          import java.util.HashMap;
          import java.util.Iterator;
          import java.util.List;
          import java.util.Map;

          import junit.framework.Test;
          import junit.framework.TestSuite;

          import org.hibernate.EntityMode;
          import org.hibernate.Hibernate;
          import org.hibernate.Session;
          import org.hibernate.Transaction;
          import org.hibernate.cfg.Configuration;
          import org.hibernate.cfg.Environment;
          import org.hibernate.test.TestCase;

          /**
           * @author Gavin King
           */
          public class DynamicClassTest extends TestCase {
           
           public DynamicClassTest(String str) {
            super(str);
           }

           protected void configure(Configuration cfg) {
            cfg.setProperty(Environment.DEFAULT_ENTITY_MODE, EntityMode.MAP.toString());
           }

           public void testLazyDynamicClass() {
            Session s = openSession();
            assertTrue( "Incorrectly handled default_entity_mode", s.getEntityMode() == EntityMode.MAP );
            Session other = s.getSession( EntityMode.MAP );
            assertEquals( "openSession() using same entity-mode returned new session", s, other );

            other = s.getSession( EntityMode.POJO );
            other.close();
            assertTrue( !other.isOpen() );
            assertTrue( other.isConnected() );  // because it is linked to the "root" session's connection

            s.close();

            s = openSession();
            Transaction t = s.beginTransaction();

            Map cars = new HashMap();
            cars.put("description", "Cars");
            Map monaro = new HashMap();
            monaro.put("productLine", cars);
            monaro.put("name", "monaro");
            monaro.put("description", "Holden Monaro");
            Map hsv = new HashMap();
            hsv.put("productLine", cars);
            hsv.put("name", "hsv");
            hsv.put("description", "Holden Commodore HSV");
            List models = new ArrayList();
            cars.put("models", models);
            models.add(hsv);
            models.add(monaro);
            s.save("ProductLine", cars);
            t.commit();
            s.close();

            s = openSession();
            t = s.beginTransaction();
            
            cars = (Map) s.createQuery("from ProductLine pl order by pl.description").uniqueResult();
            models = (List) cars.get("models");
            assertFalse( Hibernate.isInitialized(models) );
            assertEquals( models.size(), 2);
            assertTrue( Hibernate.isInitialized(models) );
            
            s.clear();
            
            List list = s.createQuery("from Model m").list();
            for ( Iterator i=list.iterator(); i.hasNext(); ) {
             assertFalse( Hibernate.isInitialized( ( (Map) i.next() ).get("productLine") ) );
            }
            Map model = (Map) list.get(0);
            assertTrue( ( (List) ( (Map) model.get("productLine") ).get("models") ).contains(model) );
            s.clear();
            
            t.commit();
            s.close();

            s = openSession();
            t = s.beginTransaction();
            cars = (Map) s.createQuery("from ProductLine pl order by pl.description").uniqueResult();
            s.delete(cars);
            t.commit();
            s.close();
           }


           protected String[] getMappings() {
            return new String[] { "dynamic/ProductLine.hbm.xml" };
           }

           public static Test suite() {
            return new TestSuite(DynamicClassTest.class);
           }

          }

          配置文件:

          <?xml version="1.0"?>
          <!DOCTYPE hibernate-mapping PUBLIC
           "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
           "

          <hibernate-mapping>

          <!--

            This mapping demonstrates "dynamic" entities.
              
          -->

           <class entity-name="ProductLine">

               <id name="id"
                column="productId"
                length="32"
                type="string">
                <generator class="uuid.hex"/>
               </id>

               <property name="description"
                not-null="true"
                length="200"
                type="string"/>

               <!-- don't use sets for associations, unless you want stack overflows! -->
               <!--這一點要特別小心, 我剛開始做試驗的時候用的就是Set, 結果拋出 stack overflows異常, 害的我兩個小時搞不定, 最后還是看了這個test, 才知道用這樣的限制-->

               <bag name="models"
                 cascade="all"
                 inverse="true">
                <key column="productId"/>
                <one-to-many class="Model"/>
               </bag>

           </class>

              <class entity-name="Model">

               <id name="id"
                column="modelId"
                length="32"
                type="string">
                <generator class="uuid.hex"/>
               </id>
               
               <property name="name"
                not-null="true"
                length="25"
                type="string"/>
                
               <property name="description"
                not-null="true"
                length="200"
                type="string"/>
               
               <many-to-one name="productLine"
                column="productId"
                not-null="true"
                class="ProductLine"/>
               
           </class>

          </hibernate-mapping>


          僅列出標題  
          主站蜘蛛池模板: 秦皇岛市| 长岛县| 舒兰市| 阳新县| 钟山县| 芮城县| 安庆市| 庄浪县| 长岭县| 武定县| 钦州市| 新宁县| 云和县| 邵东县| 许昌市| 松溪县| 磐安县| 抚州市| 永康市| 鄯善县| 三原县| 宜昌市| 西城区| 新和县| 临高县| 鹿泉市| 漳浦县| 江达县| 友谊县| 乌鲁木齐县| 金寨县| 天全县| 恭城| 昌乐县| 汝城县| 钟山县| 宝兴县| 靖西县| 海阳市| 方正县| 秀山|