Spring Source吭哧哼哧,从2011年2月开始到2011年2月终于把spring-data-mongo-1.0.1给Release出来了。从1.0.0.M1到1.0.0.M3的版本叫做Spring Data Document。1.0.0.M4开始更名为Spring Data MongoDB 1.0.0 M4,不过官网并没有特别说明,乍一看有点莫名其妙,尤其是MongoTemplate从org.springframework.data.document.mongodb移动到org.springframework.data.mongodb.core,官网的HelloWorldExample却还是用org.springframework.data.document.mongodb做例子,实在造成不少误导。

 

 -----垃圾的cnblogs,编辑了半天的东西,一下子乱了格式,要重来!-----

 

  Spring Data Mongo需要依赖Spring Framework,因此,首先需要下载Spring Framework的jar包,新建一个Web工程,将Spring Framework的jar包引入。本文引用了如下组件:

   

其中,除了Spring的几个组件包以外,还引用了MongoDB的Driver:mongo-2.7.3.jar;DWR3.0的组件dwr.jar;spring-data-mongdb-1.0.1.RELEASE.jar以及Spring Data的公共组件spring-data-commons-core-1.2.1.RELEASE.jar。需要说明的是,本文所使用的Spring Data Mongo的组件版本,需要采用Spring Framework 3.0.7及以上版本,否则程序运行会报错。

 

引入上述组件后,需要修改Spring的配置文件ApplicationContext.xml文件,引入Spring Data Mongo的命名空间,并定义MongoDB的服务器地址和端口号,初始化MongoTemplate类,代码如下

View Code
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <beans xmlns="http://www.springframework.org/schema/beans"
 4         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5         xmlns:context="http://www.springframework.org/schema/context"
 6         xmlns:mongo="http://www.springframework.org/schema/data/mongo"
 7         xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
 8         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 9             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
10             http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
11             http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
12             
13     
14 
15     <context:annotation-config />
16 
17     <!-- Properties files -->
18     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
19         <property name="locations">
20             <list>
21                 <value>classpath:server.properties</value>
22             </list>
23         </property>
24     </bean>
25     
26     <mongo:mongo host="localhost" port="27017" />
27     <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
28         <constructor-arg ref="mongo" />
29         <constructor-arg name="databaseName" value="testDb" />
30     </bean>
31     
32     
33     <context:component-scan base-package="com.ics"  use-default-filters="false">
34        <context:include-filter type="regex" expression="com.ics.bean.*"/>
35        <context:include-filter type="regex" expression="com.ics.dao.*"/>
36        <context:include-filter type="regex" expression="com.ics.service.*"/>
37     </context:component-scan>
38     
39     <dwr:configuration>
40         <dwr:convert type="bean" class="com.ics.bean.HelloKitty" />
41     </dwr:configuration>
42     <dwr:annotation-scan base-package="com.ics.bean" scanDataTransferObject="true" scanRemoteProxy="true"/>
43     <dwr:annotation-scan base-package="com.ics.web.dwr" scanDataTransferObject="false" scanRemoteProxy="true"/>
44 </beans>

 下面开始一个简单的样例。首先,定义一个HelloKitty bean

View Code
 1 /**
 2  * 
 3  */
 4 package com.ics.bean;
 5 
 6 import org.directwebremoting.annotations.DataTransferObject;
 7 
 8 @DataTransferObject
 9 public class HelloKitty
10 {
11     private String id;
12     
13     private String name;
14     
15     @Override
16     public String toString()
17     {
18         return "HelloKitty[" + "id=" + id + ", name=" + name + "]";
19     }
20 
21     public String getId()
22     {
23         return id;
24     }
25 
26     public void setId(String id)
27     {
28         this.id = id;
29     }
30 
31     public String getName()
32     {
33         return name;
34     }
35 
36     public void setName(String name)
37     {
38         this.name = name;
39     }
40 }

定义数据访问类,定义两个方法,一个用于在集合中插入一条记录,另一个根据name属性查询一条记录

View Code
 1 /**
 2  * 
 3  */
 4 package com.ics.dao;
 5 
 6 import org.springframework.beans.factory.annotation.Autowired;
 7 import org.springframework.data.mongodb.core.MongoTemplate;
 8 import org.springframework.data.mongodb.core.query.Criteria;
 9 import org.springframework.data.mongodb.core.query.Query;
10 
11 import com.ics.bean.HelloKitty;
12 
13 
14 public class HelloKittyDAO
15 {
16     /**
17      * 定义集合名称
18      */
19     private static String HELLOKITTY = "HelloKitty";
20     
21     /**
22      * 操作MongoDB的对象
23      */
24     @Autowired
25     private MongoTemplate mongoTemplate;
26     
27     
28     public void createHelloKitty(HelloKitty hello)
29     {
30         mongoTemplate.insert(hello, HELLOKITTY);
31     }
32     
33     public HelloKitty getHelloKittyByName(String name)
34     {
35         return mongoTemplate.findOne(new Query(Criteria.where("name").is(name)), HelloKitty.class, HELLOKITTY);
36     }
37 }

简单的Service方法

 1 /**
 2  * 
 3  */
 4 package com.ics.service;
 5 
 6 import org.springframework.beans.factory.annotation.Autowired;
 7 
 8 import com.ics.bean.HelloKitty;
 9 import com.ics.dao.HelloKittyDAO;
10 
11 public class HelloKittyService
12 {
13     @Autowired
14     private HelloKittyDAO helloKittyDAO;
15     
16     public String createHelloKitty(HelloKitty hello)
17     {
18         helloKittyDAO.createHelloKitty(hello);
19         
20         HelloKitty ret = helloKittyDAO.getHelloKittyByName(hello.getName());
21         
22         return ret == null ? "" : ret.getId();
23     }
24 }

通过DWR发布出去

 1 /**
 2  * 
 3  */
 4 package com.ics.web.dwr;
 5 
 6 import org.directwebremoting.annotations.RemoteMethod;
 7 import org.directwebremoting.annotations.RemoteProxy;
 8 import org.springframework.beans.factory.annotation.Autowired;
 9 
10 import com.ics.bean.HelloKitty;
11 import com.ics.service.HelloKittyService;
12 
13 @RemoteProxy(name = "HelloKittyManage")
14 public class HelloKittyManage
15 {
16  @Autowired
17  private HelloKittyService helloKittyService;
18  
19  @RemoteMethod
20  public String sayHello(HelloKitty hello)
21  {
22   return "hello " + helloKittyService.createHelloKitty(hello);
23  }
24 }

 最后,在index.html访问这个DWR方法

 1 <html>
 2     <head>
 3         <title>hello DWR</title>
 4         <script type="text/javascript" src="/Mars/dwr/engine.js"></script>
 5         <script type="text/javascript" src="/Mars/dwr/util.js"></script>
 6         <script type="text/javascript" src="/Mars/dwr/interface/HelloKittyManage.js"></script>
 7         <script type="text/javascript">
 8             function sayHello() 
 9             {
10                 var helloworld = {"name":"xyzz"};
11                 HelloKittyManage.sayHello(helloworld, function(data){alert(data);});
12             }
13         </script>
14     </head>
15     <body>
16         <h3> Spring 3.X with DWR</h3>
17         <href="javascript:void(0);" onclick="sayHello(); return false;">Retrieve test data</a><br/>
18     </body>
19 </html>

启动MongoDB服务器,运行样例程序。

在页面点击“Retrieve test data”,将会弹出“Hello 4f9fe5112d0182c5bc0a6c39”字样,其中“4f9fe5112d0182c5bc0a6c39”就是刚刚插入MongoDB中自动生成的ID。So easy,:)

posted @ 2012-05-01 21:32 Bryan Wong 阅读(231) 评论(0) 编辑

 

定义


BHCA:Busy Hour Call Attempts(忙时试呼次数),在一小时之内,系统能建立通话连接的绝对数量值。BHCA为忙时最大试呼次数,与话务量无关。


Busy Hour Call Attempts represent the number of times a telephone call is attempted during the busiest hour of the day.


CAPS:Call Attempt Per Second(每秒试呼次数),它表征了呼叫的强度。BHCA值最后体现为CAPS,CAPS乘以3600就是BHCA了。


 


计算方法


BHCA是程控交换机控制部件呼叫处理能力的重要指标,公式为单位时间内的试呼次数。CAPS乘以3600就是BHCA。


CAPS = 用户数×平均话务量/平均占用时长


平均话务量:指的是每用户的平均话务量。


如果用户忙时平均呼叫次数为x,则其CAPS=用户数 * (x/3600)


BHCA = CAPS × 3600 / 用户数=平均话务量×3600 / 平均占用时长

posted @ 2012-03-04 16:36 Bryan Wong 阅读(26) 评论(0) 编辑

Java的集合类关系图:

List:add/remove/get/set。

1,ArrayList:其实就是数组,容量一大,频繁增删就是噩梦,适合随机查找;

2,LinkedList:增加了push/[pop|remove|pull],好啰嗦,其实都是removeFirst;

3,Vector:历史遗留产物,同步版的ArrayList,名字起的奇奇怪怪,代码和ArrayList太像;

4,Stack:继承自Vector。Java里其实没有纯粹的Stack,自己实现一个吧,用组合的方式,封装一下LinkedList即可;

5,Queue:为什么归到这里呢?本来是单独的一类,不过在SUN的JDK里就是用LinkedList来提供这个功能的,主要方法是offer/pull/peek。

 

Set:add/remove。get和set呢?抱歉欠奉,可以用迭代器或者转换成list。

1,HashSet:没啥好说的,内部采用HashMap实现的;

2,LinkedHashSet:同上,采用LinkedHashMap实现;

3,TreeSet:TreeMap。

 

Map:put/get/remove。

1,HashMap/HashTable:散列表,啥都不说了,和ArrayList一样采用数组实现,超过初始容量会对性能有损耗;

2,LinkedHashMap:这个类有点意思,继承自HashMap,但通过重写嵌套类HashMap.Entry实现了链表结构,同样有容量的问题;

3,Properties:没错,这玩意是继承的HashTable。

 

顺便818坑爹的Arrays.asList,这个方法的实现依赖一个嵌套类,这个嵌套类竟然也叫ArrayList!太坑爹了。

 

 

 

posted @ 2011-12-13 22:30 Bryan Wong 阅读(139) 评论(0) 编辑
摘要: 微软的StyleCop作为一款代码分析插件,集成到Visual Studio 2008和Visual Studio 2010之中,可以帮助开发人员迅速地理清编程规范问题。对确保软件质量,确保软件开发效率而言,意义非凡。与同样出自微软的另一款代码分析工具fxcop通过分析程序集来检查各类编程规范错误不同的是,StyleCop是针对C#源代码的分析工具。有点类似java的checkstyle。Styl...阅读全文
posted @ 2010-07-04 17:25 Bryan Wong 阅读(1534) 评论(3) 编辑
摘要: 什么是圈复杂度: 比较通用的解释:一种代码复杂度的衡量标准,中文名称叫做圈复杂度。在软件测试的概念里,圈复杂度“用来衡量一个模块判定结构的复杂程度,数量上表现为独立现行路径条数,即合理的预防错误所需测试的最少路径条数,圈复杂度大说明程序代码可能质量低且难于测试和维护,根据经验,程序的可能错误和高的圈复杂度有着很大关系”。圈复杂度是一种为程序逻辑复杂性提供定量测度的软件度量,...阅读全文
posted @ 2010-06-06 22:10 Bryan Wong 阅读(771) 评论(0) 编辑
摘要: Scrum严格区分这两类人:对承担项目的人赋予权力,使其完成必要工作,确保项目成功;无责任人员则无权对项目施加不必要的干涉。这两类人在Scrum中被形象地称为“猪”和“鸡”。 “鸡”是旁观者。这起源于一则古老笑话:一只鸡和一头猪在路上走,鸡对猪说:“你想不想和我一起开家餐馆?”猪想了想,答到:“好的,我很乐意。你想为餐馆起个什么名字呢?”鸡回答道:“火腿和蛋!”猪停步,犹豫了一下,说:“三思过后,我决定不和你开这家餐馆了。因为我得全身心付出,而你仅仅是牵涉入内。”在Scrum方法中,上述区分很重要,它关系到Scrum的全面可见性原则。必须时刻区分责任人和出主意的。在敏捷项目的运作中,Scrum阅读全文
posted @ 2010-04-26 22:00 Bryan Wong 阅读(151) 评论(0) 编辑
摘要: 断言是J2SE 1.4开始引入的,其语法如下assert <逻辑表达式>assert <逻辑表达式> : <信息表达式>第一种语法,如果逻辑表达式判断false时将抛出AssertionError异常,第二种语法在抛出异常的同时还会打印信息表达式的值。断言的编译如果使用的是 J2SE 1.4,则必须告诉编译器需要使用断言,语法如下javac -source 1....阅读全文
posted @ 2010-04-11 22:08 Bryan Wong 阅读(72) 评论(0) 编辑
摘要: 一,编译时常量使用static final类似于C/C++/C#中的const。应用于基本类型,java编译器可以将该常量值代入任何可能用它的计算式中,这样可以减轻运行时的负担。二,运行时初始化,其后不可改变的变量分两种情况:如果是值类型,表示其值不可改变;如果是引用类型,表示其引用(指向)不可改变,但其引用的对象(状态和行为)可以改变。c#采用单独的关键字readonly指定。三,只读参数与第二种情况类似,在方法内部无法修改修饰为final的参数的引用指向。四,密封类与密封方法密封类表示该类不允许继承,密封方法表示该方法不可以被重写。c#采用单独的关键字sealed来指定。final关键字在阅读全文
posted @ 2010-04-11 21:01 Bryan Wong 阅读(23) 评论(0) 编辑