mashiguang

小马快跑

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  20 随笔 :: 0 文章 :: 60 评论 :: 0 Trackbacks

2010年12月8日 #

spring2.5-reference.pdf
http://m0.mail.sina.com.cn/apps/netdisk/download.php?id=d9d1668c0b162f26d115a49e0b308e4f


deerjet src.zip
http://m0.mail.sina.com.cn/apps/netdisk/download.php?id=c859c9a30c5f19e2732255e81a4f0c36

jQueryAPI-100214.chm
http://m0.mail.sina.com.cn/apps/netdisk/download.php?id=c64a572a16f169ac6db829a3122c4279

hibernate_annotations.pdf
http://m0.mail.sina.com.cn/apps/netdisk/download.php?id=88bd4e31848fda5ca2e65b6fc19df73f

hibernate_reference.pdf
http://m0.mail.sina.com.cn/apps/netdisk/download.php?id=603986150b7056ce617289370197ea9a

HQL与Criteria对照.pdf
http://m0.mail.sina.com.cn/apps/netdisk/download.php?id=c2805f9d49171f6165baa528a29774c7

oracle编程艺术.pdf
http://m0.mail.sina.com.cn/apps/netdisk/download.php?id=0c39f09f81f674ef67016482a224a025

精通oracle10g pl_sql编程.pdf
http://m0.mail.sina.com.cn/apps/netdisk/download.php?id=455bb7bbfeff510ee66acafe6c8f035b
posted @ 2011-08-11 23:05 mashiguang| 编辑 收藏

public PageModel<CrmWarning> query(PageModel<CrmWarning> pageModel)
            
throws Exception {
        Assert.notNull(pageModel);
        
        DetachedCriteria dc 
= DetachedCriteria.forClass(CrmWarning.class);
        
        
/*
         * 添加查询条件
         * 如:dc.add(Restrictions.like("key", "%"+pageModel.getCondition("key")+"%"));
         * 
         * 
*/
        
if (null != pageModel.getCondition("warnLevel")) {
            dc.add(Restrictions.eq(
"warnLevel", pageModel.getCondition("warnLevel")));
        }
        
if (StringUtils.isNotBlank((String)pageModel.getCondition("detail"))) {
            dc.add(Restrictions.like(
"detail""%"+pageModel.getCondition("detail")+"%"));
        }
        
if (StringUtils.isNotBlank((String)pageModel.getCondition("warnDate"))) {
            
/*
             * warnDate格式是yyyy-MM-dd,这里改成查询这一天的预警
             * Restrictions.sqlRestriction()允许写原生sql的方式完成特殊需求,如下
             * 
*/
            dc.add(Restrictions.sqlRestriction(
"to_char(time_start,'yyyy-MM-dd') = '" + pageModel.getCondition("warnDate"+ "'"));
        }
        
if (null != pageModel.getCondition("templateId")) {
            
/*
             * 这里的templateId是模板的主键id,查询时应该转换成模板对象
             * 
*/
            CrmWarnTemplate warnTemplate 
= new CrmWarnTemplate();
            warnTemplate.setTemplateId((Long)pageModel.getCondition(
"templateId"));
            dc.add(Restrictions.eq(
"crmWarnTemplate", warnTemplate));
        }
        
        dc.addOrder(Order.asc(
"crmWarnTemplate"));
        dc.addOrder(Order.desc(
"timeStart"));
        
        pageModel.setDateList(warningDao.query(dc, pageModel.getFirstNote(), pageModel.getNumInPage()));
        pageModel.setTotal(warningDao.count(dc));
        
        
return pageModel;
    }
posted @ 2011-08-11 22:50 mashiguang| 编辑 收藏

package com.jl.dao.bookplatform.impl;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.dao.DataAccessException;

import com.jl.dao.baseDao.GenericDao;
import com.jl.dao.bookplatform.ProductItemDao;
import com.jl.entity.bookplatform.CrmProduct;
import com.jl.entity.bookplatform.CrmProductItem;
import com.jl.entity.bookplatform.ProductItemConfig;

public class ProductItemDaoImpl extends GenericDao<CrmProductItem, Long> implements ProductItemDao {

    
    
public List<ProductItemConfig> getProductItemConfigs(Long productId, Long planetypeId) throws DataAccessException{
        String sql 
= "select chi.charge_item_id \"chargeItemId\"," +
                
" chi.charge_item \"chargeItem\"," +
                
" chi.charge_unit \"chargeUnit\"," +
                
" cpi.product_id \"productId\"," +
                
" cpi.product_item_id \"productItemId\"," +
                
" cpi.sale_planetype_id \"salePlanetypeId\"," +
                
" cpi.inland_price \"inlandPrice\"," +
                
" cpi.outland_price \"outlandPrice\"" +
                
" from (select * from crm_charge_item chi2 where chi2.if_regular = 1) chi left join crm_product_item cpi" +
                
" on cpi.charge_item_id = chi.charge_item_id " +
                
" and cpi.product_id = ?" +
                
" and cpi.sale_planetype_id = ?" +
                
" order by chi.charge_item_id";
        
        Session session 
= getSession();
        Query query 
= session.createSQLQuery(sql)
            .addScalar(
"chargeItemId", Hibernate.LONG)
            .addScalar(
"chargeItem",Hibernate.STRING)
            .addScalar(
"chargeUnit",Hibernate.STRING)
            .addScalar(
"productId",Hibernate.LONG)
            .addScalar(
"productItemId",Hibernate.LONG)
            .addScalar(
"salePlanetypeId",Hibernate.LONG)
            .addScalar(
"inlandPrice",Hibernate.DOUBLE)
            .addScalar(
"outlandPrice",Hibernate.DOUBLE)
            .setResultTransformer(Transformers.aliasToBean(ProductItemConfig.
class))
            .setParameter(
0, productId)
            .setParameter(
1, planetypeId);
        
        List
<ProductItemConfig> configs = query.list();
        
        
return configs;
    }

    
public List<CrmProductItem> getProductItem(CrmProduct product) throws DataAccessException {
        
        String hql 
= "from CrmProductItem cpi where cpi.crmProduct = ?";
        Session session 
= getSession();
        Query query 
= session.createSQLQuery(hql).setParameter(0, product);
        
        List
<CrmProductItem> items = query.list();
        
return items;
    }
    
    
public void copy(Long productId_dest,Long productId_orig,String createMan) throws DataAccessException {
        String sql 
= "insert into crm_product_item " +
                
" select hibernate_sequence.nextval," +
                
" ?," +
                
" cpi.charge_item_id," +
                
" cpi.sale_planetype_id," +
                
" cpi.inland_price," +
                
" cpi.outland_price," +
                
" ?," +
                
" sysdate" +
                
" from crm_product_item cpi" +
                
" where cpi.product_id = ?";
        
        Session session 
= getSession();
        Query sqlQuery 
= session.createSQLQuery(sql)
                        .setParameter(
0, productId_dest)
                        .setParameter(
1, createMan)
                        .setParameter(
2, productId_orig);
        sqlQuery.executeUpdate();
    }
    
    
}
posted @ 2011-08-11 22:25 mashiguang| 编辑 收藏

1,配置tomcat启动参数
直接在%tomcat_home%\bin下建立tomcat_debug.bat文件,内容如下:

cd %CATALINE_HOME%/bin
set JPDA_ADDRESS=8787
set JPDA_TRANSPORT=dt_socket
set CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787
startup

需要远程调试时从tomcat_debug.bat启动。

2,eclipse调试
选择菜单"Run>Debug...",弹出窗口里右键点击"Remote Java Application",选择"New",如图:


点击"Debug"按钮,开始远程调试,当程序运行到断点时,Eclipse会捕获到。


有关普通java app的远程调试可以参考http://blog.chenlb.com/2010/07/eclipse-remoting-debug-java-app.html
posted @ 2011-02-26 17:39 mashiguang 阅读(440) | 评论 (2)编辑 收藏

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 
<HEAD>
  
<TITLE> New Document </TITLE>
  
<META NAME="Generator" CONTENT="EditPlus">
  
<META NAME="Author" CONTENT="">
  
<META NAME="Keywords" CONTENT="">
  
<META NAME="Description" CONTENT="">
  
<script type="text/javascript" src="jquery-1.4.2.js"></script>
  
<script type="text/javascript" src="jquery.validate.js"></script>
  
<SCRIPT LANGUAGE="JavaScript">
  
<!--
    jQuery(
function(){        
        jQuery.validator.methods.compareDate 
= function(value, element, param) {
            
//var startDate = jQuery(param).val() + ":00";补全yyyy-MM-dd HH:mm:ss格式
            //value = value + ":00";
            
            
var startDate = jQuery(param).val();
            
            
var date1 = new Date(Date.parse(startDate.replace("-""/")));
            
var date2 = new Date(Date.parse(value.replace("-""/")));
            
return date1 < date2;
        };
        
        jQuery(
"#form1").validate({
            focusInvalid:
false,
            rules:{
                
"timeStart":{
                    required: 
true
                },
                
"timeEnd": {
                    required: 
true,
                    compareDate: 
"#timeStart"
                }
            },
            messages:{
                
"timeStart":{
                    required: 
"开始时间不能为空"
                },
                
"timeEnd":{
                    required: 
"结束时间不能为空",
                    compareDate: 
"结束日期必须大于开始日期!"
                }
            }
        });
    });
  
//-->
  </SCRIPT>
 
</HEAD>

 
<BODY>
 
<form id="form1" name="form1" method="post" action="demo.html">
   
<p>timeStart:
     
<input name="timeStart" type="text" id="timeStart" value="2011-02-17 10:00:00"> yyyy-MM-dd HH:mm:ss
   
</p>
   
<p>timeEnd:
     
<input name="timeEnd" type="text" id="timeEnd" value="2011-02-17 9:00:00"> yyyy-MM-dd HH:mm:ss
   
</p>
   
<p>
     
<input type="submit" name="Submit" value="提交">
   
</p>
 
</form>
  
 
</BODY>
</HTML>
posted @ 2011-02-17 10:34 mashiguang 阅读(11910) | 评论 (9)编辑 收藏

在Oracle定义变量时,常有VARCHAR2 (3 Char)或者VARCHAR2 (10 Byte)的数据类型,那么3char或者10Byte到底代表几个汉字,几个字符呢,上次外公司一同事讨论这个问题,一下没给解释清楚,所以下来以后整理如下:

总结:
当NLS_CHARACTERSET=AL32UTF8时()
NLS_LENGTH_SEMANTICS=BYTE时,一个汉字代表三个字节
NLS_LENGTH_SEMANTICS=CHAR时,一个汉字代表一个字节
当NLS_CHARACTERSET=US7ASCII时(字符集为单字节)
NLS_LENGTH_SEMANTICS=BYTE时,一个汉字代表两个字节
NLS_LENGTH_SEMANTICS=CHAR时,一个汉字代表两个字节

现象:
select * from nls_database_parameters;
….      …………..
NLS_CHARACTERSET        AL32UTF8

…..

NLS_LENGTH_SEMANTICS BYTE

….

NLS_NCHAR_CHARACTERSET      AL16UTF16

NLS_RDBMS_VERSION      10.2.0.4.0
 

SQL> alter session set nls_length_semantics='BYTE';

SQL> create table nls_byte(c1 varchar2(7));

SQL> insert into nls_byte values('测试机');

 insert into nls_byte values('测试机')

 ORA-12899: 列 "SYS"."NLS_BYTE"."C1" 的值太大 (实际值: 9, 最大值: 7)

SQL> insert into nls_byte values('测试a');

 1 row inserted
 
SQL> select table_name,column_name,t.DATA_TYPE,t.DATA_LENGTH,t.CHAR_USED from user_tab_columns t where table_name='NLS_BYTE';

 TABLE_NAME COLU DATA_TYP DATA_LENGTH CHAR_USED

---------- ---- -------- ----------- ---------

NLS_BYTE   C1   VARCHAR2           7 B
  
NLS_LENGTH_SEMANTICS allows you to specify the length of a column datatype in terms of CHARacters rather than in terms of BYTEs. Typically this is when using an AL32UTF8 or other varying width NLS_CHARACTERSET database where one character is not always one byte. While using CHAR semantics has as such no added value in a 7/8 bit characterset it's fully supported so any application code / table setup using CHAR can also be used in a 7/8bit characterset like US7ASCII/WE8MSWIN1252.
This parameter is a 9i (and up) feature and is not available in older releases

翻译过来就是:这个参数允许将列的数据单位设为字符而不是byte.这个问题会在字符集设为UTF8的时候出现. 此参数在9i以上版本有效.

NLS_LENGTH_SEMANTICS 设置.

1.      NLS_DATABASE_PARAMETERS中的值是在数据库创建的时候确定的,一般都为BYTE

2.     此参数可以以 “ALTER SYSTEM SET NLS_LENGTH_SEMANTICS=CHAR scope=both”方式修改,但是需要重启数据库才能生效.

3.     也可用” ALTER SESSION SET NLS_LENGTH_SEMANTICS=CHAR”使对当前session生效.

4.     此参数可以在10G以上版本中,在环境变量或注册表中设置(注意需要大写),设定后从当前客户端启动的所有会话都采用新的取值.

5.     修改后只对新建的列生效,对于已有的列没有作用

6.     新建或升级DB时用BYTE,否则XDB或dba_tables会出现问题.

7.     NLS_LENGTH_SEMANTICS对sys用户下的对象无效.

8.     如果对于7/8bit的字符集,设为byte/char意义不大,因为无论是char和byte都对应一个byte.

测试:

一.在当前session中修改此参数

 SQL> alter session set nls_length_semantics='char';

 Session altered

 SQL> create table nls_char(c1 varchar2(7),c2 varchar2(7));

 Table created

 SQL> desc nls_char

Name Type        Nullable Default Comments

---- ----------- -------- ------- --------

C1   VARCHAR2(7) Y                      

C2   VARCHAR2(7) Y                      

 SQL> insert into nls_char values('测试机','测试测试测试');

 1 row inserted 

如果对于alter system,效果是一样的

二.对于已经存在的表,

 SQL> desc nls_byte

Name Type             Nullable Default Comments

---- ---------------- -------- ------- --------

C1   VARCHAR2(7 BYTE) Y                      

SQL> alter table nls_byte modify c1 varchar2(7 char);

 Table altered

 SQL> desc nls_byte

Name Type        Nullable Default Comments

---- ----------- -------- ------- --------

C1   VARCHAR2(7) Y                      

 SQL> insert into nls_byte values('测试机');

 1 row inserted
 
1.      exp/imp : 不能直接导入,因为会采用source table的建表方式在target db里建表,即使目标库设的值为char.

*可以预先在目标库中以char方式建表

*然后导入,指定参数ignore=y

  2. Alter table

     alter table "<owner>"."<table>" modify "<column>" char (10 char);

      创建脚本,修改列设定.

 注:

Bug-3611750, ora-01450 online rebuild of index fails, 可以在重建索引前指定byte, 10.2.0.5以上已经修复

Bug 1488174 UNICODE: ALTER SYSTEM SET NLS_LENGTH_SEMANTICS DOESN'T
TAKE EFFECT, 用此语句修改后,实际上不起作用,需要重启才能生效, 但是如果用alter session方式即时生效,不用重启.

进一步测试,在另一个字符集设为us7ascii的DB设置此参数

SQL> select * from nls_database_parameters

6          NLS_CHARACTERSET  US7ASCII

SQL> alter session set nls_length_semantics=byte;

Session altered.

SQL> create table nls_byte(c1 varchar2(7));

Table created.

SQL> insert into  nls_byte values('测试测试');

insert into  nls_byte values('测试测试')

ERROR at line 1:

ORA-12899: value too large for column "TEA"."NLS_BYTE"."C1" (actual: 8,

maximum: 7)

SQL> desc nls_byte

 Name                        Null?    Type

 -------------------------------

 C1                                   VARCHAR2(7)

SQL> alter session set nls_length_semantics=char;

Session altered.

SQL> create table nls_char(c1 varchar2(7));

Table created.

SQL> insert into  nls_char values('测试测试');

insert into  nls_char values('测试测试')

ERROR at line 1:

ORA-12899: value too large for column "TEA"."NLS_CHAR"."C1" (actual: 8,

maximum: 7)

SQL> desc nls_char

 Name                        Null?    Type

 ----------------------------------------- -------- -------------------

C1                                  VARCHAR2(7)
 
 可以看出,在字符集为单字节的情况下,无论取何值,汉字都是以二个字节的方式存在的.

 


本文转自http://www.wudeyao.com/post-69.html
posted @ 2011-01-21 12:49 mashiguang 阅读(1402) | 评论 (0)编辑 收藏

在foreach调用remove可能会引发ConcurrentModificationException。
如:
for(Object obj : list){
    .remove(obj);
}

最好像下面这样写:
for (Iterator it = list.iterator(); it.hasNext();) {
......
it.remove();
}

(添加20160420)
如果foreach的同时需要add element,就不能使用iterator了,最好重新启用一个新的list暂存新的集合元素。
posted @ 2010-12-08 09:47 mashiguang 阅读(417) | 评论 (0)编辑 收藏