??xml version="1.0" encoding="utf-8" standalone="yes"?>国产亚洲精品成人AA片,亚洲国产日韩综合久久精品,最新亚洲卡一卡二卡三新区http://m.tkk7.com/buaacaptain/archive/2006/12/07/86096.html舚w舚wThu, 07 Dec 2006 07:19:00 GMThttp://m.tkk7.com/buaacaptain/archive/2006/12/07/86096.htmlhttp://m.tkk7.com/buaacaptain/comments/86096.htmlhttp://m.tkk7.com/buaacaptain/archive/2006/12/07/86096.html#Feedback1http://m.tkk7.com/buaacaptain/comments/commentRss/86096.htmlhttp://m.tkk7.com/buaacaptain/services/trackbacks/86096.html阅读全文

舚w 2006-12-07 15:19 发表评论
]]>
一步一步教你远E调用EJBhttp://m.tkk7.com/buaacaptain/archive/2006/09/09/68706.html舚w舚wSat, 09 Sep 2006 05:48:00 GMThttp://m.tkk7.com/buaacaptain/archive/2006/09/09/68706.htmlhttp://m.tkk7.com/buaacaptain/comments/68706.htmlhttp://m.tkk7.com/buaacaptain/archive/2006/09/09/68706.html#Feedback1http://m.tkk7.com/buaacaptain/comments/commentRss/68706.htmlhttp://m.tkk7.com/buaacaptain/services/trackbacks/68706.html 

前期准备Q弄清楚weblogicQ或jbossQ、tomcat、JBluderQ或eclipseQMyEclipseQ的使用Ҏ(gu)Q能写一个简单的Zstruts框架的web工程Q然后准备两台联|的?sh)脑Q局域网也可以)Q如果没有条Ӟ也可以在同一台电(sh)脑上分别安装两个web服务器(例如Qweblogic和tomcatQ来代替Q本文将采用后一U方法,采用weblogic作EJB容器Qtomcat作web容器Q用struts工程来调用EJB

准备好了吗?让我们开始下一?/p>

W一步:写一个简单的EJB。写EJB最好用的还是JBuilderQ毕竟够?c)化。当然作Z业h士,eclipse搭配MyEclipse是最佳选择Q不q作为初学者,采用JBuilder。以下是本文试所用到的EJB?/p>

remote接口Q?/p>

package testhello;

import javax.ejb.EJBObject;

public interface SayHello extends EJBObject {
    public String sayHello(String name) throws java.rmi.RemoteException;
}

home接口Q?/p>

package testhello;

import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;

public interface SayHelloHome extends EJBHome {
    public SayHello create() throws CreateException, RemoteException;
}

beanc:

package testhello;

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;

public class SayHelloBean implements SessionBean {
    SessionContext sessionContext;
    public void ejbCreate() throws CreateException {
    }

    public void ejbRemove() {
    }

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }


    public void setSessionContext(SessionContext sessionContext) {
        this.sessionContext = sessionContext;
    }

    public String  sayHello(String name) {
        return "Hello "+name;
    }
}

如果你是采用上面两种工具来写的话Q配|文件就不必考虑?/p>

W二步:利用JBuilder或eclipse这个EJB工程~译q打包,会得C个jar(如果你的工程名叫testhelloQ那么这个jar文g是testhello.jar)文g。如果你的EJB容器Qweblogic或JBossQ是在本ZQ那么在JBuilder或eclipse中就可以直接鼠标叛_EJB工程Q来部vEJB。如果需要部|到q程服务器上Q只需要通过EJB容器的控制台testhello.jar上传到远E端Q然后在EJB Modler里面按提C部|好EJB。最后,别忘了在JNDI Tree里面察看你的EJB工程的JNDI名,本例的JNDI名叫SayHello

W三步:remote接口和home接口打包成jar文gQcopyC要远E调用EJB的struts工程下的lib目录Q例如:helloapp ->WEB-INF ->libQ?/p>

W四步:weblogic的weblogic.jarQ在weblogic的安装目录->weblogic81Q?gt;serverQ?gt;lib文g夹中Qcopy到tomcat安装目录下的Q?gt;sharedQ?gt;lib文g夹中Q其实这里我们需要用到的只是weblogic.jar里的几个class文g而已Q不q对于初学者而言Q先不必LI到底只需要那几个class?/p>

W五步:~写一个简单的struts工程Q其实这些都可以用工L成)Q一下是调用EJB的HelloAction的源代码(特别要注意的是,记得要将之前W三步生成的jar包导入编辑器中,否则下面的代码编译通不q。如果你不知道导入jar包,把那个jar包多copy一份到你的jdk安装目录 -> jre-> lib-> ext文g夹下)

package logging.actions;
import logging.Constants;

import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;
import org.apache.struts.validator.DynaValidatorForm;

public final class HelloAction extends Action{
 
 public ActionForward execute(ActionMapping mapping,
         ActionForm form,
         HttpServletRequest request,
         HttpServletResponse response)
 throws Exception{

        InitialContext ctx=this.getInitialContext();

  //查找JNDI名ؓSayHello的EJBlg
        Object obj=ctx.lookup("SayHello");


  //获得q程EJBlg的home接口的引?br />        testhello.SayHelloHome home=(testhello.SayHelloHome)PortableRemoteObject.narrow(obj,testhello.SayHelloHome.class);


  //获得q程EJBlg的remote接口的引?br />        testhello.SayHello hello=home.create();
        
        String name="飘然随风";
        String sayString=hello.sayHello(name);
        
        request.setAttribute("userName",name);
        request.setAttribute("passWord",sayString);
        request.removeAttribute(mapping.getAttribute());
      
  return mapping.findForward("loginSuccess");
 }
 

/*以下Ҏ(gu)是作用是Q通过传递环境属性选择JNDI驱动和服务器的网l位|,
  q连接到q接到JNDI树?br />  q是采用weblogic做EJB容器Ӟq程调用EJB的固定初始化模式Q初学者可以死C?br />*/
 private  InitialContext getInitialContext() throws Exception {
  //EJB容器的地址
     String url = "t3://image:7001";
     String user = null;
     String password = null;
     Properties properties;
  
        properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY,
                       "weblogic.jndi.WLInitialContextFactory");
        properties.put(Context.PROVIDER_URL, url);
        if (user != null) {
            properties.put(Context.SECURITY_PRINCIPAL, user);
            properties.put(Context.SECURITY_CREDENTIALS,
                           password == null ? "" : password);
        }
        return new javax.naming.InitialContext(properties);
 }
}

W六步:如果你严格按照上面的步骤做了Q那么剩下的是同时启动weblogic和tomcat来测试了?/p>

舚w 2006-09-09 13:48 发表评论
]]>
深入 Lucene 索引机制http://m.tkk7.com/buaacaptain/archive/2006/08/01/61256.html舚w舚wTue, 01 Aug 2006 15:12:00 GMThttp://m.tkk7.com/buaacaptain/archive/2006/08/01/61256.htmlhttp://m.tkk7.com/buaacaptain/comments/61256.htmlhttp://m.tkk7.com/buaacaptain/archive/2006/08/01/61256.html#Feedback1http://m.tkk7.com/buaacaptain/comments/commentRss/61256.htmlhttp://m.tkk7.com/buaacaptain/services/trackbacks/61256.html

Lucene 是一个基?Java 的全文检索工具包Q你可以利用它来Z的应用程序加入烦引和索功能。Lucene 目前是著名的 Apache Jakarta 家族中的一个开源项目,下面我们卛_学习 Lucene 的烦引机制以及它的烦引文件的l构?/p>

在这文章中Q我们首先演C如何?Lucene 来烦引文档,接着讨论如何提高索引的性能。最后我们来分析 Lucene 的烦引文件结构。需要记住的是,Lucene 不是一个完整的应用E序Q而是一个信息检索包Q它方便你ؓ你的应用E序d索引和搜索功能?/p>

架构概览

图一昄?Lucene 的烦引机制的架构。Lucene 使用各种解析器对各种不同cd的文档进行解析。比如对?HTML 文档QHTML 解析器会做一些预处理的工作,比如qo文档中的 HTML 标签{等。HTML 解析器的输出的是文本内容Q接着 Lucene 的分词器(Analyzer)从文本内容中提取出烦引项以及相关信息Q比如烦引项的出现频率。接着 Lucene 的分词器把这些信息写到烦引文件中?/p>
图一QLucene 索引机制架构
图一QLucene 索引机制架构




回页?/font>


用Lucene索引文档

接下来我一步一步的来演C如何利?Lucene Z的文档创建烦引。只要你能将要烦引的文g转化成文本格式,Lucene pZ的文档徏立烦引。比如,如果你想?HTML 文档或?PDF 文档建立索引Q那么首先你需要从q些文档中提取出文本信息Q然后把文本信息交给 Lucene 建立索引。我们接下来的例子用来演C如何利?Lucene 为后~名ؓ txt 的文件徏立烦引?/p>

1Q?准备文本文g

首先把一些以 txt 为后~名的文本文g攑ֈ一个目录中Q比如在 Windows q_上,你可以放?C:\\files_to_index 下面?/p>

2Q?创徏索引

清单1是ؓ我们所准备的文档创建烦引的代码?/p>
清单1Q用 Lucene 索引你的文档
package lucene.index;

import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.util.Date;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;

/**
 * This class demonstrates the process of creating an index with Lucene 
 * for text files in a directory.
 */
public class TextFileIndexer {
 public static void main(String[] args) throws Exception{
   //fileDir is the directory that contains the text files to be indexed
   File   fileDir  = new File("C:\\files_to_index ");

   //indexDir is the directory that hosts Lucene's index files
   File   indexDir = new File("C:\\luceneIndex");
   Analyzer luceneAnalyzer = new StandardAnalyzer();
   IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);
   File[] textFiles  = fileDir.listFiles();
   long startTime = new Date().getTime();

   //Add documents to the index
   for(int i = 0; i < textFiles.length; i++){
     if(textFiles[i].isFile() >> textFiles[i].getName().endsWith(".txt")){
       System.out.println("File " + textFiles[i].getCanonicalPath() 
              + " is being indexed");
       Reader textReader = new FileReader(textFiles[i]);
       Document document = new Document();
       document.add(Field.Text("content",textReader));
       document.add(Field.Text("path",textFiles[i].getPath()));
       indexWriter.addDocument(document);
     }
   }

   indexWriter.optimize();
   indexWriter.close();
   long endTime = new Date().getTime();

   System.out.println("It took " + (endTime - startTime) 
              + " milliseconds to create an index for the files in the directory "
              + fileDir.getPath());
  }
}

正如清单1所C,你可以利?Lucene 非常方便的ؓ文档创徏索引。接下来我们分析一下清?中的比较关键的代码,我们先从下面的一条语句开始看赗?/p>
Analyzer luceneAnalyzer = new StandardAnalyzer();

q条语句创徏了类 StandardAnalyzer 的一个实例,q个cL用来从文本中提取出烦引项的。它只是抽象c?Analyzer 的其中一个实现。Analyzer 也有一些其它的子类Q比?SimpleAnalyzer {?/p>

我们接着看另外一条语句:


IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);

q条语句创徏了类 IndexWriter 的一个实例,该类也是 Lucene 索引机制里面的一个关键类。这个类能创Z个新的烦引或者打开一个已存在的烦引ƈ所引添加文档。我们注意到该类的构造函数接受三个参敎ͼW一个参数指定了存储索引文g的\径。第二个参数指定了在索引q程中用什么样的分词器。最后一个参数是个布?yu)变量,如果gؓ真,那么pC创徏一个新的烦引,如果gؓ假,pC打开一个已l存在的索引?/p>

接下来的代码演示了如何添加一个文档到索引文g中?/p>
Document document = new Document();
document.add(Field.Text("content",textReader));
document.add(Field.Text("path",textFiles[i].getPath()));
indexWriter.addDocument(document);

首先W一行创Zc?Document 的一个实例,它由一个或者多个的?Field)l成。你可以把这个类惌成代表了一个实际的文档Q比如一?HTML 面Q一?PDF 文档Q或者一个文本文件。而类 Document 中的域一般就是实际文档的一些属性。比如对于一?HTML 面Q它的域可能包括标题Q内容,URL {。我们可以用不同cd?Field 来控制文档的哪些内容应该索引Q哪些内容应该存储。如果想获取更多的关?Lucene 的域的信息,可以参?Lucene 的帮助文档。代码的W二行和W三行ؓ文档d了两个域Q每个域包含两个属性,分别是域的名字和域的内容。在我们的例子中两个域的名字分别?content"?path"。分别存储了我们需要烦引的文本文g的内容和路径。最后一行把准备好的文档dC索引当中?/p>

当我们把文档d到烦引中后,不要忘记关闭索引Q这h保证 Lucene 把添加的文档写回到硬盘上。下面的一句代码演CZ如何关闭索引?/p>
indexWriter.close();

利用清单1中的代码Q你可以成功的文本文档添加到索引中去。接下来我们看看对烦引进行的另外一U重要的操作Q从索引中删除文档?/p>



回页?/font>


从烦引中删除文档

cIndexReader负责从一个已l存在的索引中删除文档,如清?所C?/p>
清单2Q从索引中删除文?/b>
File   indexDir = new File("C:\\luceneIndex");
IndexReader ir = IndexReader.open(indexDir);
ir.delete(1);
ir.delete(new Term("path","C:\\file_to_index\lucene.txt"));
ir.close();

在清?中,W二行用静态方?IndexReader.open(indexDir) 初始化了c?IndexReader 的一个实例,q个Ҏ(gu)的参数指定了索引的存储\径。类 IndexReader 提供了两U方法去删除一个文档,如程序中的第三行和第四行所C。第三行利用文档的编h删除文档。每个文档都有一个系l自动生成的~号。第四行删除了\径ؓ"C:\\file_to_index\lucene.txt"的文档。你可以通过指定文g路径来方便的删除一个文档。值得注意的是虽然利用上述代码删除文档使得该文档不能被索到Q但是ƈ没有物理上删除该文档。Lucene 只是通过一个后~名ؓ .delete 的文件来标记哪些文档已经被删除。既然没有物理上删除Q我们可以方便的把这些标Cؓ删除的文档恢复过来,如清?3 所C,首先打开一个烦引,然后调用Ҏ(gu) ir.undeleteAll() 来完成恢复工作?/p>
清单3Q恢复已删除文档
File   indexDir = new File("C:\\luceneIndex");
IndexReader ir = IndexReader.open(indexDir);
ir.undeleteAll();
ir.close();

你现在也许想知道如何物理上删除烦引中的文档,Ҏ(gu)也非常简单。清?4 演示了这个过E?/p>
清单4Q如何物理上删除文档
File   indexDir = new File("C:\\luceneIndex");
Analyzer luceneAnalyzer = new StandardAnalyzer();
IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,false);
indexWriter.optimize();
indexWriter.close();

在清?4 中,W三行创Zc?IndexWriter 的一个实例,q且打开了一个已l存在的索引。第 4 行对索引q行清理Q清理过E中把所有标Cؓ删除的文档物理删除?/p>

Lucene 没有直接提供Ҏ(gu)Ҏ(gu)档进行更斎ͼ如果你需要更C个文档,那么你首先需要把q个文档从烦引中删除Q然后把新版本的文档加入到烦引中厅R?/p>



回页?/font>


提高索引性能

利用 LuceneQ在创徏索引的工E中你可以充分利用机器的g资源来提高烦引的效率。当你需要烦引大量的文gӞ你会注意到烦引过E的瓉是在往盘上写索引文g的过E中。ؓ了解册个问? Lucene 在内存中持有一块缓冲区。但我们如何控制 Lucene 的缓冲区呢?q运的是QLucene 的类 IndexWriter 提供了三个参数用来调整缓冲区的大以及往盘上写索引文g的频率?/p>

1Q合q因子(mergeFactorQ?/p>

q个参数军_了在 Lucene 的一个烦引块中可以存攑֤文档以及把盘上的索引块合q成一个大的烦引块的频率。比如,如果合ƈ因子的值是 10Q那么当内存中的文档数达?10 的时候所有的文档都必d到磁盘上的一个新的烦引块中。ƈ且,如果盘上的索引块的隔数辑ֈ 10 的话Q这 10 个烦引块会被合ƈ成一个新的烦引块。这个参数的默认值是 10Q如果需要烦引的文档数非常多的话q个值将是非怸合适的。对批处理的索引来讲Qؓq个参数赋一个比较大的g得到比较好的索引效果?/p>

2Q最合q文档数

q个参数也会影响索引的性能。它军_了内存中的文档数臛_辑ֈ多少才能它们写回磁盘。这个参数的默认值是10Q如果你有够的内存Q那么将q个值尽量设的比较大一些将会显著的提高索引性能?/p>

3Q最大合q文档数

q个参数军_了一个烦引块中的最大的文档数。它的默认值是 Integer.MAX_VALUEQ将q个参数讄为比较大的值可以提高烦引效率和索速度Q由于该参数的默认值是整型的最大|所以我们一般不需要改动这个参数?/p>

清单 5 列出了这个三个参数用法,清单 5 和清?1 非常怼Q除了清?5 中会讄刚才提到的三个参数?/p>
清单5Q提高烦引性能
/**
 * This class demonstrates how to improve the indexing performance 
 * by adjusting the parameters provided by IndexWriter.
 */
public class AdvancedTextFileIndexer  {
  public static void main(String[] args) throws Exception{
    //fileDir is the directory that contains the text files to be indexed
    File   fileDir  = new File("C:\\files_to_index");

    //indexDir is the directory that hosts Lucene's index files
    File   indexDir = new File("C:\\luceneIndex");
    Analyzer luceneAnalyzer = new StandardAnalyzer();
    File[] textFiles  = fileDir.listFiles();
    long startTime = new Date().getTime();

    int mergeFactor = 10;
    int minMergeDocs = 10;
    int maxMergeDocs = Integer.MAX_VALUE;
    IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);        
    indexWriter.mergeFactor = mergeFactor;
    indexWriter.minMergeDocs = minMergeDocs;
    indexWriter.maxMergeDocs = maxMergeDocs;

    //Add documents to the index
    for(int i = 0; i < textFiles.length; i++){
      if(textFiles[i].isFile() >> textFiles[i].getName().endsWith(".txt")){
        Reader textReader = new FileReader(textFiles[i]);
        Document document = new Document();
        document.add(Field.Text("content",textReader));
        document.add(Field.Keyword("path",textFiles[i].getPath()));
        indexWriter.addDocument(document);
      }
    }

    indexWriter.optimize();
    indexWriter.close();
    long endTime = new Date().getTime();

    System.out.println("MergeFactor: " + indexWriter.mergeFactor);
    System.out.println("MinMergeDocs: " + indexWriter.minMergeDocs);
    System.out.println("MaxMergeDocs: " + indexWriter.maxMergeDocs);
    System.out.println("Document number: " + textFiles.length);
    System.out.println("Time consumed: " + (endTime - startTime) + " milliseconds");
  }
}

通过q个例子Q我们注意到在调整缓冲区的大以及写盘的频率上?Lucene l我们提供了非常大的灉|性。现在我们来看一下代码中的关键语句。如下的代码首先创徏了类 IndexWriter 的一个实例,然后对它的三个参数进行赋倹{?/p>
int mergeFactor = 10;
int minMergeDocs = 10;
int maxMergeDocs = Integer.MAX_VALUE;
IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);        
indexWriter.mergeFactor = mergeFactor;
indexWriter.minMergeDocs = minMergeDocs;
indexWriter.maxMergeDocs = maxMergeDocs;

下面我们来看一下这三个参数取不同的值对索引旉的媄响,注意参数值的不同和烦引之间的关系。我们ؓq个实验准备?10000 个测试文档。表 1 昄了测试结果?/p>
?Q测试结?/b>
?Q测试结? src=

通过?1Q你可以清楚地看C个参数对索引旉的媄响。在实践中,你会l常的改变合q因子和最合q文档数的值来提高索引性能。只要你有够大的内存,你可以ؓ合ƈ因子和最合q文档数q两个参数赋量大的g提高索引效率Q另外我们一般无需更改最大合q文档数q个参数的|因ؓpȝ已经默认它讄成了最大?/p>



回页?/font>


Lucene 索引文gl构分析

在分?Lucene 的烦引文件结构之前,我们先要理解反向索引QInverted indexQ这个概念,反向索引是一U以索引ؓ中心来组l文档的方式Q每个烦引项指向一个文档序列,q个序列中的文档都包含该索引V相反,在正向烦引中Q文档占据了中心的位|,每个文档指向了一个它所包含的烦引项的序列。你可以利用反向索引L的找到那些文档包含了特定的烦引项。Lucene正是使用了反向烦引作为其基本的烦引结构?/p>



回页?/font>


索引文g的逻辑视图

在Lucene 中有索引块的概念Q每个烦引块包含了一定数目的文档。我们能够对单独的烦引块q行索。图 2 昄?Lucene 索引l构的逻辑视图。烦引块的个数由索引的文档的L以及每个索引块所能包含的最大文档数来决定?/p>
?Q烦引文件的逻辑视图
?Q烦引文件的逻辑视图




回页?/font>


Lucene 中的关键索引文g

下面的部分将会分析Lucene中的主要的烦引文Ӟ可能分析有些索引文g的时候没有包含文件的所有的字段Q但不会影响到对索引文g的理解?/p>

1Q烦引块文g

q个文g包含了烦引中的烦引块信息Q这个文件包含了每个索引块的名字以及大小{信息。表 2 昄了这个文件的l构信息?/p>
?Q烦引块文gl构
?Q烦引块文gl构

2Q域信息文g

我们知道Q烦引中的文档由一个或者多个域l成Q这个文件包含了每个索引块中的域的信息。表 3 昄了这个文件的l构?/p>
?Q域信息文gl构
?Q域信息文gl构

3Q烦引项信息文g

q是索引文g里面最核心的一个文Ӟ它存储了所有的索引的g及相关信息,q且以烦引项来排序。表 4 昄了这个文件的l构?/p>
?Q烦引项信息文gl构
?Q烦引项信息文gl构

4Q频率文?/p>

q个文g包含了包含烦引项的文档的列表Q以及烦引项在每个文档中出现的频率信息。如果Lucene在烦引项信息文g中发现有索引和搜烦词相匚w。那?Lucene ׃在频率文件中找有哪些文g包含了该索引V表5昄了这个文件的一个大致的l构Qƈ没有包含q个文g的所有字Dc?/p>
?Q频率文件的l构
?Q频率文件的l构

5Q位|文?/p>

q个文g包含了烦引项在每个文档中出现的位|信息,你可以利用这些信息来参与对烦引结果的排序。表 6 昄了这个文件的l构


?Q位|文件的l构
?Q位|文件的l构

到目前ؓ止我们介l了 Lucene 中的主要的烦引文件结构,希望能对你理?Lucene 的物理的存储l构有所帮助?/p>



回页?/font>


ȝ

目前已经有非常多的知名的l织正在使用 LuceneQ比如,Lucene ?Eclipse 的帮助系l,ȝ理工学院?OpenCourseWare 提供了搜索功能。通过阅读q篇文章Q希望你能对 Lucene 的烦引机制有所了解Qƈ且你会发现利?Lucene 创徏索引是非常简单的事情?/p>

舚w 2006-08-01 23:12 发表评论
]]>
xslhttp://m.tkk7.com/buaacaptain/archive/2006/07/30/60862.html舚w舚wSun, 30 Jul 2006 06:57:00 GMThttp://m.tkk7.com/buaacaptain/archive/2006/07/30/60862.htmlhttp://m.tkk7.com/buaacaptain/comments/60862.htmlhttp://m.tkk7.com/buaacaptain/archive/2006/07/30/60862.html#Feedback0http://m.tkk7.com/buaacaptain/comments/commentRss/60862.htmlhttp://m.tkk7.com/buaacaptain/services/trackbacks/60862.htmlhttp://m.tkk7.com/rickhunter/articles/59742.html
http://www.blueidea.com/tech/web/2004/1798_4.asp

 本期介绍多个XSL对于VBScript、JScript增加的方法、属性,以充分发挥XML的优势,用于<xsl:script>?lt;xsl:eval>标记内表辑ּ的编写或<xsl:if>?lt;xsl:when>的expr属性?

  一、absoluteChildNumber

  含义Q返回结点相对于它所有的兄弟Q不论名字是否相同)的序受?/p>

  语法QabsoluteChildNumber(node)

  参数Qnode ── 对象Q欲q回~号的结炏V?/p>

  CZQ?/p>

  1、假定文档结构ؓQ?lt;document><head/><body/></document>Q其中document为顶层结点,下述表达式将输出Q?/p>

<xsl:eval>
absoluteChildNumber(this.selectNodes('/document/body').item(0))
</xsl:eval>

  2、确定当前结点相对于其所有兄弟的序号Q?/p>

<xsl:eval>
absoluteChildNumber(this)
</xsl:eval>

  二、ancestorChildNumber

  含义Q从l定l点出发Ҏ(gu)l定先l点名返回最q的先l点的序P相对于同名结点)。如果找不祖先,则返??/p>

  语法QancestorChildNumber(bstrNodeName, pNode)

  参数Q?/p>

  bstrNodeName ── 字符丌Ӏ被搜烦的祖先结点的名字?/p>

  pNode ── 对象。搜索开始位|的l点?/p>

  CZ查找当前l点最q的名ؓreport先l点Q?/p>

ancestorChildNumber('report',this)

  三、attributes

  含义Q返回结点属性的集合?/p>

  语法Qobject.attributes

  参数Qobject ── l点对象?/p>

  CZQ当前结点属性的个数

this.attributes.length

  当前l点W三个属性的?/p>

this.attributs.item(2).value

?br />
this.attributes.item(2).text

?br />
this.attributes(2).text

  注意Q如果给定的下标大于属性d?出错,W一个属性的下标??/p>

  四、baseName

  含义Q返回有名字I间限制的基本名Q即不包括名字前~?/p>

  语法Qobject.baseName

  参数Qobject ── l点对象

  CZQ当前结点的基本名:

this.baseName

  五、childNumber

  含义Q返回结点相对于同名同胞(yu)的序受?/p>

  语法QchildNumber(object)

  参数Qobject ── l点对象

  CZQ假定XML文档l构如下Q?/p>

<x><y><z></z></y></x>

  如果当前l点是zQ则childNumber(this)q回1Q而absoluteChildNumber(this)q回3?

  六、dataType

  含义Q设定或dl点的数据类型?/p>

  语法Q设定结点的数据cd object.dataType=objValue
     dl点的数据类?objValue=object.dataType

  参数Qobject ── l点对象?br />
  CZQ读取当前结点的数据cdQ?/p>

dtType=this.dataType

  七、depth

  含义Q指定结点出现在文档树上的深度,卌l点位于文档W几层,层l点位于W一层,根结点(即用"/"表示的结点)位于W?层?/p>

  语法Qdepth(pNode)

  参数QpNode ── l点对象

  CZQ当前结点的深度Q?/p>

depth(this)

  八、firstChild、lastChild

  含义Q返回结点的W一个子l点Q或最后一个子l点Q?/p>

  语法QpNode.firstChild
     pNode.lastChild

  参数QpNode ── l点对象

  CZQ当前结点的W一个结点的名字Q?/p>

this.firstChild.nodeName

  ?ji)、formatIndex

  含义Q用指定的计数系l格式化提供的整数?/p>

  语法QformatIndex(lIndex, bstrFormat)

  参数Q?/p>

  lIndex ── 整型数值或变量

  bstrFormat ── 数据格式Q可选值有a、A、i、I??1Q以0打头的数值Ş式,如果要求固定长度的编号如0001?002则非常有用)?/p>

  CZQ当前结点的大写|马数字~号Q?/p>

formatIndex(childNumber(this),'I')

  十、formatNumber

  含义Q以指定格式输出数倹{?/p>

  语法QformatNumber(dblNumber, bstrFormat)

  参数Q说明同formatNumberQ不同之处在于格式化的可以是数?/p>

  CZQ对变量a的值格式化Z位小敎ͼ

formatNumber(a,'#.00')Q?/p>

  十一、hasChildNodes

  含义Q如果结Ҏ(gu)子结点则q回trueQ?1Q,否则为falseQ?Q?/p>

  语法QpNode.hasChildNodes()

  注意Q与此前介绍的函C同,此函数后必须带一个空括号?/p>

  CZQ判断当前结Ҏ(gu)否有子结点:

this.hasChildNodes

  十二、namespaceURI、prefix

  含义Q返回结点名字空间的全局资源标识W(或前~Q?/p>

  语法QpNode.namespaceURI
     pNode.prifix

  十三、nextSibling、previousSibling、parentNode

  含义Q返回结点的下一个兄弟(或前一个兄弟、或l点的父l点Q?/p>

  语法QpNode.nextSibling
     pNode.previousSibling
     pNode.parentNode

  注意Q对根结点(?/"Q应用parentNodeҎ(gu)、对W一个孩子结点应用previousSiblingҎ(gu)、对最后一个孩子结点应用nextSiblingҎ(gu)均会D错误Q可通过此过关系q算W?=Q等于)?=Q不{于Q来判断一个结Ҏ(gu)否某一指定l点Q格式ؓpNode1 = pNode2或pNode2 != pNode2?/p>

  十四、nodeName

  含义Q返回元素、属性、入口的名字或其他类型结点的一个特定字W串?/p>

  语法QpNode.nodeName

  CZQ当前结点的名字Q?/p>

this.nodeName

  十五、nodeType、NodeTypeString

  含义Q返回结点的cd的数值Ş式(或字W串形式Q?br />
  语法QpNode.nodeType ?pNode.nodeTypeString

  q回|

 l点cd l点cd?/font> l点的字WŞ式描q?/font>
 Element 1 'element'
 Element Attribute 2 'attribute'
 Markup-Delimited Region of Text 3 'text'
 Processing Instruction 7 'processing_instruction'
 Comment 8 'comment'
 Document Entity 9 'document'

  十六、nodeTypedValue

  含义Q以l点预定义的数据cdq回l点的倹{?/p>

  语法QpNode.nodeTypedValue

  CZQ假定当前结点的数据cd是fixed.14.4Q下例将以数D回结点的|而不是文本一个字W串Q?/p>

this.nodeTypedValue

  十七、nodeValue

  含义Q返回结点的文本?/p>

  语法QpNode.nodeValue

  注意Q该Ҏ(gu)不用于元素类l点Q可用于属性、CDATA、注释、文本等l点?/p>

  CZQ当前元素第一个属性的|

this.attributes(0).nodeValue

  当前元素内的文本Q假定该元素内只有文本,无其它元素,?lt;mark>text</mark>Q徏议多几ơ掌握其切的用法)?/p>

this.firstChild.nodeValue

  十八、ownerDocument

  含义Q返回包含该l点的文档的栏V?/p>

  语法QpNode.ownerDocument

  注意Q该Ҏ(gu)用于文档的根l点出错?/p>

  十九(ji)、selectNodes

  含义Q给定的样式匚w应用于当前结点ƈq回匚w的结炚w合?/p>

  语法QpNode.selectNodes('pattern')

  提示Qpattern的编写与<xsl:for-each>的select属性的值类|其中?/"开头表CZ文档的根出发搜烦Q以"http://"开头表遍历文档的所有结点;?.."开头表CZ当前l点的父l点开始;如果Ʋ从当前l点向下搜烦则不能有以上Ҏ(gu)字符打头?/p>

  CZQ与当前l点同名的元素在其父元素内的个数Q?/p>

childNumber(this.selectNodes("../"+this.nodeName+"[end()]").item(0))

  当前元素内名字ؓ"skill"的元素的个数Q?/p>

childNumber(this.selectNodes("skill[end()]").item(0))

  二十、selectSingleNode

  含义Q与selectNodescMQ不同的只返回匹配的W一个结炏V而不是结炚w合?/p>

  语法QpNode.selectSingleNode('pattern')

  CZQ与当前l点同名的元素在其父元素内的个数Q?/p>

childNumber(this.selectSingleNode("../"+this.nodeName+"[end()]"))

  当前元素内名字ؓ"skill"的元素的个数Q?/p>

childNumber(this.selectSingleNode("skill[end()]"))

  二十一、text

  含义Q返回结点与它的子树内的文字内容?/p>

  语法QpNode.text

  CZQ整个文档内的文字内容:

this.ownerDocument.text

  当前元素及其子树的文字内容:

this.text

  二十二、xml

  含义Q返回结点及其后代的XML表示?/p>

  语法QpNode.xml

  CZQ当前文档的XML内容Q?/p>

this.ownerDocument.xml

  另有几个函数不作介绍Q列于其下以供参考,如感兴趣Q请讉Khttp://msdn.microsoft.com获取详细说明?/p>

formatTime(varTime, bstrFormat,varDestLocale)
formatDate(varDate, bstrFormat,varDestLocale)
apendChild(newChild)
definition
CloneNode
insertBefore(newChild, refChild)
parsed
removeChild(oldChild)
replaceChild(newChild, oldChild)
specified
transformNode(stylesheet)
transformNodeToObject(stylesheet,outputObject)
uniqueID(pNode)



舚w 2006-07-30 14:57 发表评论
]]>
Oracle 10G 在fedora core4上的安装http://m.tkk7.com/buaacaptain/archive/2006/07/21/59302.html舚w舚wThu, 20 Jul 2006 16:31:00 GMThttp://m.tkk7.com/buaacaptain/archive/2006/07/21/59302.htmlhttp://m.tkk7.com/buaacaptain/comments/59302.htmlhttp://m.tkk7.com/buaacaptain/archive/2006/07/21/59302.html#Feedback0http://m.tkk7.com/buaacaptain/comments/commentRss/59302.htmlhttp://m.tkk7.com/buaacaptain/services/trackbacks/59302.html 1.当然是下载Y件包:http://www.oracle.com/technology ... racle10g/index.html
选择自己需要的 .我下载的?for linux x86.(注意,下蝲前需要先注册用户)
2.解压
gunzip ship.db.lix32.cpio.gz
cpio -idmv < ship.db.lix32.cpio
解压后在当前目录下Ş成目?Disk1.
3.打开帮助文g.Quick Installation Guide for Linux x86
在Disk1/目录下有个DOC目录,打开里面的README文g,其中有此帮助文?
4.安帮助一步步设至.基本没有问题.
5.很重?因ؓORACLE10g不支持FC4,所以需作必要修?
z扑ֈ文g./Disk1/install/oraparam.ini,打开,删除如下内容(记得先备?
[Certified Versions]
Linux=redhat-2.1,redhat-3,SuSE-9,SuSE-8,UnitedLinux-1.0

[UnitedLinux-1.0-optional]
TEMP_SPACE=80
SWAP_SPACE=150
MIN_DISPLAY_COLORS=256


[Linux-redhat-2.1-optional]
TEMP_SPACE=80
SWAP_SPACE=150
MIN_DISPLAY_COLORS=256

[Linux-redhat-3.0-optional]
TEMP_SPACE=80
SWAP_SPACE=150
MIN_DISPLAY_COLORS=256

[Linux-SuSE-9-optional]
TEMP_SPACE=80
SWAP_SPACE=150
MIN_DISPLAY_COLORS=256

[Linux-SuSE-8-optional]
TEMP_SPACE=80
SWAP_SPACE=150
MIN_DISPLAY_COLORS=256

6.讄语言支持.׃ORACLE安装界面中文支持不好,q行
export LC_ALL=en_us,否则Ҏ(gu)出现q.
好了 ,现在q行./runInstall.安向导往下走可以了

舚w 2006-07-21 00:31 发表评论
]]>
议HashMaphttp://m.tkk7.com/buaacaptain/archive/2006/07/20/59178.html舚w舚wThu, 20 Jul 2006 06:14:00 GMThttp://m.tkk7.com/buaacaptain/archive/2006/07/20/59178.htmlhttp://m.tkk7.com/buaacaptain/comments/59178.htmlhttp://m.tkk7.com/buaacaptain/archive/2006/07/20/59178.html#Feedback1http://m.tkk7.com/buaacaptain/comments/commentRss/59178.htmlhttp://m.tkk7.com/buaacaptain/services/trackbacks/59178.html大家都知道,在Java里对对象的操作是Z引用的。而当我们需要对一l对象操作的时候,需要有接收q一l引用的容器。^时我们最常用的就是数l。在Java里可以定义一个对象数l来完成许多操作。可是,数组长度是固定的Q如果我们需要更加灵zȝ解决Ҏ(gu)该怎么办呢Q?/p>

Java提供了container classes来解册一问题。container classes包括两个部分QCollection和Map。它们的l构是这LQ?/p>

本文重点介绍HashMap。首先介l一下什么是Map。在数组中我们是通过数组下标来对其内容烦引的Q而在Map中我们通过对象来对对象q行索引Q用来烦引的对象叫做keyQ其对应的对象叫做value。在下文中会有例子具体说明?/p>

再来看看HashMap和TreeMap有什么区别。HashMap通过hashcode对其内容q行快速查找,而TreeMap中所有的元素都保持着某种固定的顺序,如果你需要得C个有序的l果你就应该使用TreeMapQHashMap中元素的排列序是不固定的)?/p>

下面pq入本文的主题了。先举个例子说明一下怎样使用HashMap:

import java.util.*;

public class Exp1 {
     public static void main(String[] args){
          HashMap h1=new HashMap();
          Random r1=new Random();    
          for(int i=0;i<1000;i++){
               Integer t=new Integer(r1.nextInt(20));
               if(h1.containsKey(t))
                    ((Ctime)h1.get(t)).count++;
               else
                    h1.put(t, new Ctime());
          }
          System.out.println(h1);
     }
}

class Ctime{
     int count=1;
     public String toString(){
          return Integer.toString(count);
     }
}

在HashMap中通过get()来获取valueQ通过put()来插入valueQContainsKey()则用来检验对象是否已l存在。可以看出,和ArrayList的操作相比,HashMap除了通过key索引其内容之外,别的斚w差异q不大?/p>

前面介绍了,HashMap是基于HashCode的,在所有对象的类Object中有一个HashCode()Ҏ(gu)Q但是它和equalsҎ(gu)一Pq不能适用于所有的情况Q这h们就需要重写自qHashCode()Ҏ(gu)。下面就举这样一个例子:

import java.util.*;

public class Exp2 {
     public static void main(String[] args){
          HashMap h2=new HashMap();
          for(int i=0;i<10;i++)
               h2.put(new Element(i), new Figureout());
          System.out.println("h2:");
          System.out.println("Get the result for Element:");
          Element test=new Element(5);
          if(h2.containsKey(test))
               System.out.println((Figureout)h2.get(test));
          else
               System.out.println("Not found");
     }
}

class Element{
     int number;
     public Element(int n){
          number=n;
     }
}

class Figureout{
     Random r=new Random();
     boolean possible=r.nextDouble()>0.5;
     public String toString(){
          if(possible)
               return "OK!";
          else
               return "Impossible!";
     }
}

在这个例子中QElement用来索引对象Figureout,也即Element为keyQFigureout为value。在Figureout中随机生成一个QҎ(gu)Q如果它?.5大,打印“OK!”,否则打印“Impossible!”。之后查看Element(3)对应的Figureoutl果如何?/p>

l果却发玎ͼ无论你运行多次Q得到的l果都是“Not found”。也是说烦引Element(3)q不在HashMap中。这怎么可能呢?

原因得慢慢来_Element的HashCodeҎ(gu)l承自ObjectQ而Object中的HashCodeҎ(gu)q回的HashCode对应于当前的地址Q也是说对于不同的对象Q即使它们的内容完全相同Q用HashCodeQ)q回的g会不同。这样实际上q背了我们的意图。因为我们在使用HashMapӞ希望利用相同内容的对象烦引得到相同的目标对象Q这需要HashCode()在此时能够返回相同的倹{在上面的例子中Q我们期望new Element(i) (i=5)与 Element test=new Element(5)是相同的Q而实际上q是两个不同的对象,管它们的内容相同,但它们在内存中的地址不同。因此很自然的,上面的程序得不到我们设想的结果。下面对ElementcL改如下:

class Element{
     int number;
     public Element(int n){
          number=n;
     }
     public int hashCode(){
          return number;
     }
     public boolean equals(Object o){
          return (o instanceof Element) && (number==((Element)o).number);
     }
}

在这里Element覆盖了Object中的hashCode()和equals()Ҏ(gu)。覆盖hashCode()使其以number的g为hashcodeq回Q这样对于相同内容的对象来说它们的hashcode也就相同了。而覆盖equals()是ؓ了在HashMap判断两个key是否相等时ɾl果有意义(有关重写equals()的内容可以参考我的另一文章《重新编写ObjectcM的方?》)。修改后的程序运行结果如下:

h2:
Get the result for Element:
Impossible!

误住:如果你想有效的用HashMapQ你必重写在其的HashCode()?/p>

q有两条重写HashCode()的原则:

  1. 不必Ҏ(gu)个不同的对象都生一个唯一的hashcodeQ只要你的HashCodeҎ(gu)使get()能够得到put()放进ȝ内容可以了。即“不Z原则”?
  2. 生成hashcode的算法尽量hashcode的值分散一些,不要很多hashcode都集中在一个范围内Q这h利于提高HashMap的性能。即“分散原则”?

至于W二条原则的具体原因Q有兴趣者可以参考Bruce Eckel的《Thinking in Java》,在那里有对HashMap内部实现原理的介l,q里׃赘述了?/p>

掌握了这两条原则Q你p够用好HashMap~写自己的程序了。不知道大家注意没有Qjava.lang.Object中提供的三个Ҏ(gu)Qclone()Qequals()和hashCode()虽然很典型,但在很多情况下都不能够适用Q它们只是简单的由对象的地址得出l果。这需要我们在自己的程序中重写它们Q其实javacd中也重写了千千万万个q样的方法。利用面向对象的多态性——覆盖,Java的设计者很优雅的构ZJava的结构,也更加体CJava是一门纯OOP语言的特性?/p>

Java提供的Collection和Map的功能是十分强大的,它们能够使你的程序实现方式更为灵z,执行效率更高。希望本文能够对大家更好的用HashMap有所帮助?



舚w 2006-07-20 14:14 发表评论
]]>
Linux下挂载硬盘分区的几种Ҏ(gu)http://m.tkk7.com/buaacaptain/archive/2006/07/19/58884.html舚w舚wTue, 18 Jul 2006 17:19:00 GMThttp://m.tkk7.com/buaacaptain/archive/2006/07/19/58884.htmlhttp://m.tkk7.com/buaacaptain/comments/58884.htmlhttp://m.tkk7.com/buaacaptain/archive/2006/07/19/58884.html#Feedback1http://m.tkk7.com/buaacaptain/comments/commentRss/58884.htmlhttp://m.tkk7.com/buaacaptain/services/trackbacks/58884.html1、用Autofs自动挂蝲分区
2、修?etc/fstab
3、编写shell脚本Q开动运行mount命o

Ҏ(gu)一、用Autofs
1、Autofs的特点:Autofs与Mount/Umount的不同之处在于,它是一U看守程序(deamonQ。如果它到用户正试图访问一个尚未挂接的文gpȝQ它?yu)׃自动该文gp? l,如果该文件系l存在,那么Autofs会自动将其挂接。另一斚wQ如果它到某个已挂接的文gpȝ在一D|间内没有被用,那么Autofs会自? 其卸蝲。因此一旦运行了Autofs后,用户׃在需要手动完成文件系l的挂接和卸载?br /> 2、Autofs的安装: 只需执行以下一条命令:rpm Qivh autofsQ?.1.3Q?0.i386.rpm。安装完成后Q以后每ơ启动LinuxQAutofs都会自动q行?br /> 3、Autofs的配|:首先Q?/font> Autofs需要从/etc/auto.masterq个文g中读取配|信息。该文g? 可以同时指定多个挂接点,每个挂接点单独用一行来定义,每一行可包括3个部分,分别用于指定挂接点位|,挂接旉使用的配|文Ӟ卻I所谓的map file)及所挂接文gpȝ在空闲多长时间后自动被卸载。例如,auto.master文g中包括如下一行: /auto /etc/auto.misc Q-timeout 60?/font> ? 中第一部分指定一个安装点?autoQ第二部分指?auto的map文g?etc/auto.miscQ第三部分指定文件系l在其空?0U后自动 被卸载。其ơ,?etc/auto.miscq个文gd挂接旉要用的配置信息。例如,auto.misc文g包括如下内容
cd              -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
Windows_C -fstype=auto,iocharset=cp936 :/dev/hda1
Windows_D -fstype=auto,iocharset=cp936 :/dev/hda5
Windows_E -fstype=auto,iocharset=cp936 :/dev/hda6
其中W一行指定将讑֤/dev/cdrom挂接?auto的cd子目录中Q第二行指定 硬盘的Windows分区挂接?auto的Windows_*子目录中。每一行的W二个|fstype是一个可选项Q用来表明所挂接的文件系l的cd和挂接选项Q在 mount命o能用挂接选项同样适用于-fstype? 修改了配|文件后Q可通过执行命o?etc/init.d/autofs restart”,使新的配|生效? 现在输入命o“ls /auto/cd”,Autofs会自动检光׃是否有光盘,如果有,它会自动其挂接?auto/cd中,q样ls׃列出其中的内宏V如果我们在 60U内没有再次讉K/auto/cdӞAutofs会自动将其卸载掉?br />转蝲自:http://family.chinaok.com/showcontent.php?articleid=1674


1、fstab文g的作?br /> 文g/etc/fstab存放的是pȝ中的文gpȝ信息。当正确的设|了该文Ӟ则可以通过"mount  /directoryname"命o来加载一个文件系l,每种文gpȝ都对应一个独立的行,每行中的字段都有I格或tab键分开。同时fsck? mount、umount的等命o都利用该E序?br />
2、下面是/etc/fatab文g的一个示例行Q?
fs_spec fs_file fs_type fs_options fs_dump fs_pass 
/dev/hda1   /   ext2     defaults    1    1 

fs_spec  - 该字D定义希望加载的文gpȝ所在的讑֤或远E文件系l,对于一般的本地块设备情冉|_IDE讑֤一般描qCؓ /dev/hdaXNQX是IDE 讑֤通道(a, b, or c)QN代表分区PSCSI讑֤一描述?dev/sdaXN。对于NFS情况Q格式一般ؓ:,例如Q? `knuth.aeb.nl:/'。对于procfsQ用`proc'来定义?

fs_file - 该字D|q希望的文gpȝ加蝲的目录点Q对于swap讑֤Q该字段为noneQ对于加载目录名包含I格的情况,?0来表C空根{?

fs_type - 定义了该讑֤上的文gpȝQ一般常见的文gcd为ext2 (Linux讑֤的常用文件类?、vfat(Windowspȝ的fat32格式)、NTFS、iso9600{?
 
fs_options - 指定加蝲该设备的文gpȝ是需要用的特定参数选项Q多个参数是由逗号分隔开来。对于大多数pȝ使用"defaults"可以满需要。其他常见的选项包括Q?
选项              含义
ro      以只L式加载该文gpȝ
sync    不对该设备的写操作进行缓冲处理,q可以防止在非正常关机时情况下破坏文件系l,但是却降低了计算机速度
user    允许普通用户加载该文gpȝ
quota   强制在该文gpȝ上进行磁盘定额限?
noauto  不再使用mount Qa命oQ例如系l启动时Q加载该文gpȝ

fs_dump - 该选项?dump"命o使用来检查一个文件系l应该以多快频率q行转储Q若不需要{储就讄该字Dؓ0

fs_pass - 该字D被fsck命o用来军_在启动时需要被扫描的文件系l的序Q根文gpȝ"/"对应该字D늚值应该ؓ1Q其他文件系l应该ؓ2。若该文件系l无需在启动时扫描则设|该字段?

3、修?etc/fstab实现自动挂蝲Windows分区Qƈ昄中文目录
LABEL=/ / ext3 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
LABEL=/usr /usr ext3 defaults 1 2
/dev/hda9 swap swap defaults 0 0
#d如下几行
/dev/hda1 /mnt/win_c vfat codepage=936,iocharset=cp936 0 0
/dev/hda5 /mnt/win_d vfat codepage=936,iocharset=cp936 0 0
/dev/hda6 /mnt/win_e vfat codepage=936,iocharset=cp936 0 0

4、对部分分区格式的支持需要编译相关的支持到内怺来实玎ͼ如NTFS?br />



首先,以rootw䆾登陆Q在/mnt下,你要有win_c win_d win_eq几个目录,如果没有可以通过在虚拟终端分别输入mkdir /mnt/win_c,mkdir /mnt/win_d,mkdir /mnt/win_e来徏立。接着打开虚拟l端Q,输入 vi mymountQ然后按insert输入如下代码Q?br /> #!/bin/bash
case $1 in
m)
mount -o iocharset=cp936 -t vfat /dev/hda1 /mnt/win_c
mount -o iocharset=cp936 -t vfat /dev/hda5 /mnt/win_d
mount -o iocharset=cp936 -t vfat /dev/hdc6 /mnt/win_e
;;
u)
umount -o iocharset=cp936 -t vfat /dev/hda1 /mnt/win_c
umount -o iocharset=cp936 -t vfat /dev/hda5 /mnt/win_d
umount -o iocharset=cp936 -t vfat /dev/hda6 /mnt/win_e
;;
esac
然后按Esc输入:wq回R可以了.W一?!/bin/bash指定以bash shell执行此文
?case $1 in 为取的命令行参数.若ؓm则开始挂?若ؓu则卸?其中-o
iocharset=cp936能够昄中文?-t vfat 为指定文件系l类型ؓWINDOWS下的VFAT文gp?br /> l?win_c win_d win_e为目?mnt下的子目?
到这里,该程序已l写好了.但是它还没有执行权利.我们只要输入下面q个命o可以了.
chmod u+x mymount
到这步你只要输入./mymount m,可以挂载windows分区?如果?etc/rc.d/rc.local 文g中添加这一行:
sh ./root/mymount m
重启后linux会自动挂载windows分区?br />

http://bbs.chinaunix.net/archiver/?tid-431527.html



舚w 2006-07-19 01:19 发表评论
]]>
string和stringbufferhttp://m.tkk7.com/buaacaptain/archive/2006/07/13/58031.html舚w舚wThu, 13 Jul 2006 09:47:00 GMThttp://m.tkk7.com/buaacaptain/archive/2006/07/13/58031.htmlhttp://m.tkk7.com/buaacaptain/comments/58031.htmlhttp://m.tkk7.com/buaacaptain/archive/2006/07/13/58031.html#Feedback0http://m.tkk7.com/buaacaptain/comments/commentRss/58031.htmlhttp://m.tkk7.com/buaacaptain/services/trackbacks/58031.html  非可变对象一旦创Z后就不能再被改变Q可变对象则可以在创Z后被改变。String对象是非可变对象QStringBuffer对象则是可变对象。ؓ获得更佳的性能你需要根据实际情况小心}慎地选择到底使用q两者中的某一个。下面的话题会作详细的阐q。(注意Q这个章节假设读者已l具备Java的String和StringBuffer的相兛_知识。)
 
创徏字符串的较佳途径
你可以按照以下方式创建字W串对象Q?br />1. String s1 = "hello"; 
    String s2 = "hello"; 
2. String s3 = new String("hello");
    String s4 = new String("hello");
 
上面哪种方式会带来更好的性能呢?下面的代码片断用来测量二者之间的区别?br />
StringTest1.java
package com.performance.string;
/** This class shows the time taken for creation of
 *  String literals and String objects.
 */
public class StringTest1 {
public static void main(String[] args){
    // create String literals
    long startTime = System.currentTimeMillis();
    for(int i=0;i<50000;i++){
    String s1 = "hello";
    String s2 = "hello";
    }
    long endTime = System.currentTimeMillis();
    System.out.println("Time taken for creation of String literals : "
                  + (endTime - startTime) + " milli seconds" );
    // create String objects using 'new' keyword       
    long startTime1 = System.currentTimeMillis();
    for(int i=0;i<50000;i++){
    String s3 = new String("hello");
    String s4 = new String("hello");
    }
    long endTime1 = System.currentTimeMillis();
    System.out.println("Time taken for creation of String objects : "
                  + (endTime1 - startTime1)+" milli seconds");
    }
}
q段代码的输出:
Time taken for creation of String literals : 0 milli seconds
Time taken for creation of String objects : 170 milli seconds
 
JVM是怎样处理字符串的呢?
  Java虚拟Zl护一个内部的滞留字符串对象的列表Q唯一字符串的池)来避免在堆内存中产生重复的String对象。当JVM从class文g里加载字W串字面量ƈ执行的时候,它会先检查一下当前的字符串是否已l存在于滞留字符串列表,如果已经存在Q那׃会再创徏一个新的String对象而是引用指向已l存在的String对象QJVM会在内部为字W串字面量作q种查,但ƈ不会为通过new关键字创建的String对象作这U检查。当然你可以明确C用String.intern()Ҏ(gu)强制JVM为通过 new关键字创建的String对象作这L查。这样可以强制JVM查内部列表而用已有的String对象?br />  所以结论是QJVM会内在地为字W串字面量维护一些唯一的String对象Q程序员不需要ؓ字符串字面量而发愁,但是可能会被一些通过 new关键字创建的String对象而困扎ͼ不过他们可以使用intern()Ҏ(gu)来避免在堆内存上创徏重复的String对象来改善Java的运行性能。下一节会向大家展示更多的信息?br /> 
下图展示了未使用intern()Ҏ(gu)来创建字W串的情c?br /> 
string_creating_without_intern() method
  你可以自׃?=操作W和String.equals()Ҏ(gu)来编码测试上面提到的区别?=操作W会q回true如果一些引用指向一个相同的对象但不会判断String对象的内Ҏ(gu)否相同;String.equals()Ҏ(gu)会返回true如果被操作的String对象的内容相同。对于上面的代码会有s1==s2Q因为s1和s2两个引用指向同一个对象,对于上面的代码,s3.equals(s4)会返回true因ؓ两个对象的内定w一样ؓ”hello”。你可以从上囄U机制。在q里有三个独立的包含了相同的内容Q”hello”)的对象,实际上我们不需要这么三个独立的对象—— 因q行它们的话既浪Ҏ(gu)间又费内存?br /> 
  那么怎样才能保String对象不会重复呢?下一个话题会늛对于内徏String机制的兴?br /> 
滞留字符串的优化作用
  同一个字W串对象被重复地创徏是不必要的,String.intern ()Ҏ(gu)可以避免q种情况。下图说明了String.intern()Ҏ(gu)是如何工作的QString.intern()Ҏ(gu)查字W串对象的存在性,如果需要的字符串对象已l存在,那么它会引用指向已l存在的字符串对象而不是重新创Z个。下图描l了使用了intern()Ҏ(gu)的字W串字面量和字符串对象的创徏情况?br /> 
string_creating_with_intern() method
下面的例E帮助大家了解String.intern()Ҏ(gu)的重要性?br />StringTest2.java
 
package com.performance.string;
// This class shows the use of intern() method to improve performance
public class StringTest2 {
public static void main(String[] args){
    // create String references like s1,s2,s3...so on..
    String variables[] = new String[50000];
    for( int i=0;i<variables.length;i++){
        variables[i] = "s"+i;
    }
    // create String literals
    long startTime0 = System.currentTimeMillis();
    for(int i=0;i<variables.length;i++){
        variables[i] = "hello";
    }
    long endTime0 = System.currentTimeMillis();
    System.out.println("Time taken for creation of String literals : "
                         + (endTime0 - startTime0) + " milli seconds" );
    // create String objects using 'new' keyword       
    long startTime1 = System.currentTimeMillis();
    for(int i=0;i<variables.length;i++){
        variables[i] = new String("hello");
    }
    long endTime1 = System.currentTimeMillis();
    System.out.println("Time taken for creation of String objects with 'new' key word : "
                        + (endTime1 - startTime1)+" milli seconds");
    // intern String objects with intern() method   
    long startTime2 = System.currentTimeMillis();
    for(int i=0;i<variables.length;i++){
        variables[i] = new String("hello");
        variables[i] = variables[i].intern();
    }
    long endTime2 = System.currentTimeMillis();
    System.out.println("Time taken for creation of String objects with intern(): "
                        + (endTime2 - startTime2)+" milli seconds");
    }
}
q是上面那段代码的输出结果:
Time taken for creation of String literals : 0 milli seconds
Time taken for creation of String objects with 'new' key word : 160 milli seconds
Time taken for creation of String objects with intern(): 60 milli seconds
 
q接字符串时候的优化技?br />  你可以?操作W或者String.concat()或者StringBuffer.append(){办法来q接多个字符Ԍ那一U办法具有最佳的性能呢?
  如何作出选择取决于两U情景,W一U情景是需要连接的字符串是在编译期军_的还是在q行期决定的Q第二种情景是你使用的是 StringBufferq是String。通常E序员会认ؓStringBuffer.append()Ҏ(gu)会优?操作W或 String.concat()Ҏ(gu)Q但是在一些特定的情况下这个假x不成立的?br /> 
1) W一U情景:~译期决定相对于q行期决?br />L下面的StringTest3.java代码和输出结果?br />
package com.performance.string;
/** This class shows the time taken by string concatenation at compile time and run time.*/
public class StringTest3 {
  public static void main(String[] args){
    //Test the String Concatination
    long startTime = System.currentTimeMillis();
    for(int i=0;i<5000;i++){
    String result = "This is"+ "testing the"+ "difference"+ "between"+
            "String"+ "and"+ "StringBuffer";
    }
    long endTime = System.currentTimeMillis();
    System.out.println("Time taken for string concatenation using + operator : "
         + (endTime - startTime)+ " milli seconds");
    //Test the StringBuffer Concatination
    long startTime1 = System.currentTimeMillis();
    for(int i=0;i<5000;i++){
    StringBuffer result = new StringBuffer();
         result.append("This is");
        result.append("testing the");
        result.append("difference");
        result.append("between");
       result.append("String");
       result.append("and");
       result.append("StringBuffer");
     }
    long endTime1 = System.currentTimeMillis();
    System.out.println("Time taken for String concatenation using StringBuffer : "
           + (endTime1 - startTime1)+ " milli seconds");
  }
}
q是上面的代码的输出l果Q?br />Time taken for String concatenation using + operator : 0 milli seconds
Time taken for String concatenation using StringBuffer : 50 milli seconds
很有地Q?操作W居然比StringBuffer.append()Ҏ(gu)要快Qؓ什么呢Q?br /> 
  q里~译器的优化起了关键作用Q编译器像下面D例的那样单地在编译期q接多个字符丌Ӏ它使用~译期决定取代运行期军_Q在你用new关键字来创徏String对象的时候也是如此?br /> 
~译前:
String result = "This is"+"testing the"+"difference"+"between"+"String"+"and"+"StringBuffer";
~译后:
String result = "This is testing the difference between String and StringBuffer";

q里String对象在编译期决定了而StringBuffer对象是在q行期决定的。运行期军_需要额外的开销当字W串的值无法预先知道的时候,~译期决定作用于字符串的值可以预先知道的时候,下面是一个例子?br /> 
~译前:
public String getString(String str1,String str2) {
    return str1+str2;
}
~译后:
return new StringBuffer().append(str1).append(str2).toString();
q行期决定需要更多的旉来运行?br /> 
2) W二U情景:使用StringBuffer取代String
看看下面的代码你会发C情景一相反的结果——连接多个字W串的时候StringBuffer要比String快?br />StringTest4.java
 
package com.performance.string;
/** This class shows the time taken by string concatenation
using + operator and StringBuffer  */
public class StringTest4 {
 public static void main(String[] args){
    //Test the String Concatenation using + operator
    long startTime = System.currentTimeMillis();
    String result = "hello";
    for(int i=0;i<1500;i++){
        result += "hello";
    }
    long endTime = System.currentTimeMillis();
    System.out.println("Time taken for string concatenation using + operator : "
                  + (endTime - startTime)+ " milli seconds");
    //Test the String Concatenation using StringBuffer
    long startTime1 = System.currentTimeMillis();
    StringBuffer result1 = new StringBuffer("hello");
    for(int i=0;i<1500;i++){
        result1.append("hello");
    }
    long endTime1 = System.currentTimeMillis();
    System.out.println("Time taken for string concatenation using StringBuffer :  "
                  + (endTime1 - startTime1)+ " milli seconds");
    }
}
q是上面的代码的输出l果Q?br />Time taken for string concatenation using + operator : 280 milli seconds
Time taken for String concatenation using StringBuffer : 0 milli seconds
看得出StringBuffer.append()Ҏ(gu)要比+操作W要快得多,Z么呢Q?br />
  原因是两者都是在q行期决定字W串对象Q但?操作W用不同于StringBuffer.append()的规则通过String和StringBuffer来完成字W串q接操作。(译注Q什么样的规则呢Q)
 
借助StringBuffer的初始化q程的优化技?br />  你可以通过StringBuffer的构造函数来讑֮它的初始化容量,q样可以明显地提升性能。这里提到的构造函数是StringBuffer(int length)Qlength参数表示当前的StringBuffer能保持的字符数量。你也可以用ensureCapacity(int minimumcapacity)Ҏ(gu)在StringBuffer对象创徏之后讄它的定w。首先我们看看StringBuffer的缺省行为,然后再找Z条更好的提升性能的途径?br /> 
StringBuffer的缺省行为:
  StringBuffer在内部维护一个字W数l,当你使用~省的构造函数来创徏StringBuffer对象的时候,因ؓ没有讄初始化字W长度,StringBuffer的容量被初始化ؓ16个字W,也就是说~省定w是16个字W。当StringBuffer辑ֈ最大容量的时候,它会自w容量增加到当前?倍再?Q也是Q?*旧?2Q?br />  如果你用缺省|初始化之后接着往里面q加字符Q在你追加到W?6个字W的时候它会将定w增加?4Q?*16+2Q,当追加到34个字W的时候就会将定w增加?0Q?*34+2Q。无Z事只要StringBuffer到达它的最大容量它?yu)׃得不创徏一个新的字W数l然后重新将旧字W和新字W都拯一遍——这也太昂贵了点。所以LlStringBuffer讄一个合理的初始化容量值是错不了的Q这样会带来立竿见媄的性能增益?br />  我利用两个StringBuffer重新试了上面的StringTest4.java代码Q一个未使用初始化容量D另一个用了。这ơ我q加?0000个’hello’对象没有?操作W。区别是我用StringBuffer(250000)的构造函数来初始化第二个 StringBuffer了?br /> 
输出l果如下Q?br />Time taken for String concatenation using StringBuffer with out setting size: 280 milli seconds
Time taken for String concatenation using StringBuffer with setting size: 0 milli seconds
StringBuffer初始化过E的调整的作用由此可见一斑。所以,使用一个合适的定w值来初始化StringBuffer永远都是一个最佳的?br /> 
关键?br />1. 无论何时只要可能的话使用字符串字面量来常见字W串而不是用new关键字来创徏字符丌Ӏ?br />2. 无论何时当你要用new关键字来创徏很多内容重复的字W串的话Q请使用String.intern()Ҏ(gu)?br />3. +操作W会为字W串q接提供最佳的性能——当字符串是在编译期军_的时候?br />4. 如果字符串在q行期决定,使用一个合适的初期定w值初始化的StringBuffer会ؓ字符串连接提供最佳的性能

http://java.chinaitlab.com/JDK/364481.html

舚w 2006-07-13 17:47 发表评论
]]>
xml的document和xml字符串间的{?/title><link>http://m.tkk7.com/buaacaptain/archive/2006/07/13/57953.html</link><dc:creator>舚w</dc:creator><author>舚w</author><pubDate>Thu, 13 Jul 2006 04:52:00 GMT</pubDate><guid>http://m.tkk7.com/buaacaptain/archive/2006/07/13/57953.html</guid><wfw:comment>http://m.tkk7.com/buaacaptain/comments/57953.html</wfw:comment><comments>http://m.tkk7.com/buaacaptain/archive/2006/07/13/57953.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/buaacaptain/comments/commentRss/57953.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/buaacaptain/services/trackbacks/57953.html</trackback:ping><description><![CDATA[ <table cellspacing="1" cellpadding="4" width="100%" border="0"> <tbody> <tr> <td valign="top"> <div id="kceogm8" class="subhead"> <b>XML字符串和XML DOCUMENT的相互{?/b> </div> </td> </tr> <tr> <td class="content" valign="top"> <table width="200" align="right" border="0"> <tbody> <tr> <td> </td> </tr> </tbody> </table> <p> <font size="2">在做一般的XML数据交换q程中,我更乐意传递XML字符Ԍ而不是格式化的XML Document。这涉及到XML字符串和Xml Document的{换问题,说白了这是个很简单的问题Q本文就各种XML解析器分别列丑֦下,以方便自׃后查阅?/font> </p> <p> <br /> <strong> <font size="2">一、用最原始的javax.xml.parsersQ标准的jdk api</font> </strong> </p> <p> <font size="2">// 字符串{XML<br />String xmlStr = \"......\";<br />StringReader sr = new StringReader(xmlStr); <br />InputSource is = new InputSource(sr); <br />DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); <br />DocumentBuilder builder=factory.newDocumentBuilder(); <br />Document doc = builder.parse(is); </font> </p> <p> <font size="2">//XML转字W串<br />TransformerFactory  tf  =  TransformerFactory.newInstance();<br />Transformer t = tf.newTransformer();<br />t.setOutputProperty(\"encoding\",\"GB23121\");//解决中文问题Q试q用GBK不行<br />ByteArrayOutputStream  bos  =  new  ByteArrayOutputStream();<br />t.transform(new DOMSource(doc), new StreamResult(bos));<br />String xmlStr = bos.toString();</font> </p> <p> <font size="2">q里的XML DOCUMENT为org.w3c.dom.Document</font> </p> <p> <strong> <font size="2">二、用dom4j后程序变得更?/font> </strong> </p> <p> <font size="2">// 字符串{XML<br />String xmlStr = \"......\";<br />Document document = DocumentHelper.parseText(xmlStr);</font> </p> <p> <font size="2">// XML转字W串 <br />Document document = ...;<br />String text = document.asXML();</font> </p> <p> <font size="2">q里的XML DOCUMENT为org.dom4j.Document</font> </p> <p> <strong> <font size="2">三、用JDOM</font> </strong> </p> <p> <font size="2">JDOM的处理方式和W一U方法处理非常类?/font> </p> <p> <font size="2">//字符串{XML<br />String xmlStr = \".....\";<br />StringReader sr = new StringReader(xmlStr);<br />InputSource is = new InputSource(sr);<br />Document doc = (new SAXBuilder()).build(is);</font> </p> <p> <font size="2">//XML转字W串<br />Format format = Format.getPrettyFormat();<br />format.setEncoding(\"gb2312\");//讄xml文g的字Wؓgb2312Q解决中文问?br />XMLOutputter xmlout = new XMLOutputter(format);<br />ByteArrayOutputStream bo = new ByteArrayOutputStream();<br />xmlout.output(doc,bo);<br />String xmlStr = bo.toString();</font> </p> <p> <font size="2">q里的XML DOCUMENT为org.jdom.Document</font> </p> <p> <strong> <font size="2">四、JAVASCRIPT中的处理</font> </strong> </p> <p> <br /> <font size="2">//字符串{XML<br />var xmlStr = \".....\";<br />var xmlDoc = new ActiveXObject(\"Microsoft.XMLDOM\");<br />xmlDoc.async=false;<br />xmlDoc.loadXML(xmlStr);<br />//可以处理q个xmlDoc?br />var name = xmlDoc.selectSingleNode(\"/person/name\");<br />alert(name.text);</font> </p> <p> <font size="2">//XML转字W串<br />var xmlDoc = ......;<br />var xmlStr = xmlDoc.xml</font> </p> <p> <font size="2">q里的XML DOCUMENT为javascript版的XMLDOM</font> </p> </td> </tr> </tbody> </table> <img src ="http://m.tkk7.com/buaacaptain/aggbug/57953.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/buaacaptain/" target="_blank">舚w</a> 2006-07-13 12:52 <a href="http://m.tkk7.com/buaacaptain/archive/2006/07/13/57953.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于clob字段的一些讨?/title><link>http://m.tkk7.com/buaacaptain/archive/2006/07/11/57616.html</link><dc:creator>舚w</dc:creator><author>舚w</author><pubDate>Tue, 11 Jul 2006 03:07:00 GMT</pubDate><guid>http://m.tkk7.com/buaacaptain/archive/2006/07/11/57616.html</guid><wfw:comment>http://m.tkk7.com/buaacaptain/comments/57616.html</wfw:comment><comments>http://m.tkk7.com/buaacaptain/archive/2006/07/11/57616.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/buaacaptain/comments/commentRss/57616.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/buaacaptain/services/trackbacks/57616.html</trackback:ping><description><![CDATA[在网上闲逛找C解决Ҏ(gu)Q?br />     现在3.x中对blob和clob增加了org.hibernate.lob.SerializableBlob和org.hibernate.lob.SerializableClobcȝ装?br /><br />其次如果你将前面的测试程序放到weblogic的容器中通过weblogic的数据源得到q接的话Q你会发现oracle.sql.BLOB blob = (oracle.sql.BLOB)person.getImage();?oracle.sql.CLOB clob = (oracle.sql.CLOB)person.getArticle();q俩行会出错Q原因就是weblogicq行了包装?br /><br />现在以上两个问题的l合解决Ҏ(gu)用以下代码说明:<br /><br /><br /><br />            for (int i = 0; i < 10; i++) {<br />                LargeObject large = new LargeObject();<br />                large.setId(i + "");<br />                large.setName("林意?);<br /><br />                // 插入一个小数据数据<br />                large.setImage(Hibernate.createBlob(new byte[1]));<br />                large.setArticle(Hibernate.createClob(" "));<br /><br />                session.save(large);<br />                session.flush();<br /><br />                // 锁定该记?br />                session.refresh(large, LockMode.UPGRADE);<br /><br />                // 插入囄数据<br />                String fileName = "E:/AAA/" + i + ".jpg";<br />                SerializableBlob sb = (SerializableBlob)large.getImage();<br />                java.sql.Blob wrapBlob = sb.getWrappedBlob();<br />                // 通过非weblogic容器中数据源获得q接的情?br />                if(wrapBlob instanceof oracle.sql.BLOB){<br />                    oracle.sql.BLOB blob = (oracle.sql.BLOB) wrapBlob;<br />                    OutputStream out = blob.getBinaryOutputStream();<br />                    out.write(getData(fileName));<br />                    out.close();<br />                }<br />                // 使用weblogic的Oracle Thin drivercdq接池,驱动cdQoracle.jdbc.OracleDriver<br />                else if(wrapBlob instanceof weblogic.jdbc.vendor.oracle.OracleThinBlob){<br />                    OracleThinBlob blob = (OracleThinBlob)wrapBlob;<br />                    OutputStream out = blob.getBinaryOutputStream();<br />                    out.write(getData(fileName));<br />                    out.close();<br />                }<br /><br /><br />                // 插入文章数据<br />                fileName = "E:/AAA/" + i + ".java";<br />                SerializableClob cb = (SerializableClob)large.getArticle();<br />                java.sql.Clob wrapClob = cb.getWrappedClob();<br />                // 通过非weblogic容器中数据源获得q接的情?br />                if(wrapClob instanceof oracle.sql.CLOB){<br />                    oracle.sql.CLOB clob = (oracle.sql.CLOB) wrapClob;<br />                    Writer writer = clob.getCharacterOutputStream();<br />                    String article = new String(getData(fileName));<br />                    writer.write(article);<br />                    writer.close();<br />                }<br />                // 使用weblogic的Oracle Thin drivercdq接池,驱动cdQoracle.jdbc.OracleDriver<br />                else if(wrapClob instanceof weblogic.jdbc.vendor.oracle.OracleThinClob){<br />                    OracleThinClob clob = (OracleThinClob)wrapClob;<br />                    Writer writer = clob.getCharacterOutputStream();<br />                    String article = new String(getData(fileName));<br />                    writer.write(article);<br />                    writer.close();<br />                }<br />            }<br /><br /><br />***************************************************<br /><span id="wumei24" class="postbody">采用得是ORACLE9i数据库,Jboss或Weblogic?<br />JDBC采用ORACLE9i自带的Class12.jar <br />Q-Q-Q-Q-Q-Q-Q?<br />数据库结构: <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span id="24c8k84" class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />CREATE TABLE SNCPARAMETERS <br /><span style="COLOR: #000000">(</span><br />  ID     NUMBER<span style="COLOR: #000000">(</span><span style="COLOR: #000000" ?="">19</span><span style="COLOR: #000000">)</span>                             NOT <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">NULL</span>, <br />  SNCID  NUMBER<span style="COLOR: #000000">(</span><span style="COLOR: #000000" ?="">19</span><span style="COLOR: #000000">)</span>, <br />  NAME   VARCHAR2<span style="COLOR: #000000">(</span><span style="COLOR: #000000" ?="">255</span><span style="COLOR: #000000">)</span>, <br />  VALUE  CLOB <br /><span style="COLOR: #000000">)</span><br /></div><br /></td></tr></tbody></table><span id="miaa4yg" class="postbody"><br />Q-Q-Q-Q-Q-Q-Q- <br />BO采用xdoclet建立的: <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span id="ycg4moo" class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span> SNCParameters <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">extends</span> BaseObject <br /><span style="COLOR: #000000">{</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     * Returns the id. <br />     * <br />     * @return      long <br />     * @hibernate.id <br />     *          column = "id" <br />     *          type = "long" <br />     *          generator-class = "native" <br />     *          unsaved-value = "null" <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Long</span> getId<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> id; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     *    Sets the Id attribute of the SNCParameters object <br />     * <br />     * @param    id  The new Id value <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setId<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Long</span> id<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">id</span> = id; <br />    <span style="COLOR: #000000">}</span><br /><br /><br />    <span style="COLOR: #6666ff">/** <br />     * Returns the name. <br />     * <br />     * @return      String <br />     * <br />     * @hibernate.property <br />     *          column = "name" <br />     *          type = "string" <br />     *          not-null = "true" <br />     *          unique = "false" <br />     */</span><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">String</span> getName<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> name; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     *    Sets the Name attribute of the SNCParameters object <br />     * <br />     * @param    name  The new Name value <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> name<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">name</span> = name; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     * Returns the sncId. <br />     * <br />     * @return      Long <br />     * <br />     * @hibernate.property <br />     *          column = "sncId" <br />     *          type = "long" <br />     *          not-null = "true" <br />     *          unique = "false" <br />     */</span><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Long</span> getSncId<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> sncId; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     *    Sets the SncId attribute of the SNCParameters object <br />     * <br />     * @param    sncId  The new SncId value <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setSncId<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Long</span> sncId<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">sncId</span> = sncId; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     * Returns the values. <br />     * <br />     * @return      Clob <br />     * <br />     * @hibernate.property <br />     *          column = "value" <br />     *          type = "clob" <br />     *          not-null = "true" <br />     *          unique = "false" <br />     */</span><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Clob</span> getValue<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> value; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     *    Sets the Values attribute of the SNCParameters object <br />     * <br />     * @param    values  The new Values value <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setValue<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Clob</span> value<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">value</span> = value; <br />    <span style="COLOR: #000000">}</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">Long</span> id; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">Long</span> sncId; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">String</span> name; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">Clob</span> value; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">String</span> valueString; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">String</span> getValueString<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> valueString; <br />    <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setValueString<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span>  valueString<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">valueString</span> = valueString; <br />    <span style="COLOR: #000000">}</span><br /><span style="COLOR: #000000">}</span><br /></div><br /></td></tr></tbody></table><span id="ucecy4m" class="postbody"><br /><br /><span style="FONT-WEIGHT: bold">注:valueStringq不映射到数据库的CLOB字段Q只是方侉K要用这个BO的h用GET、SET 处理q个巨长的CLOB字段</span><br />Q-Q-Q-Q-Q-Q- <br />xdocLet生成的XML文gQ?<br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span id="swywgy8" class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br /><?xml version="<span style="COLOR: #000000" ?="">1</span>.<span style="COLOR: #000000" ?="">0</span>"?> <br /><br /><!DOCTYPE hibernate-mapping <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">PUBLIC</span><br />    "-<span style="COLOR: #6666ff">//Hibernate/Hibernate Mapping DTD 2.0//EN" </span><br />    "http:<span style="COLOR: #6666ff">//hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"></span><br /><br /><hibernate-mapping> <br />    <<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span><br />        name="com.<span style="COLOR: #000000">idncn</span>.<span style="COLOR: #000000">mc</span>.<span style="COLOR: #000000">bo</span>.<span style="COLOR: #000000">SNCParameters</span>" <br />        table="SNCParameters" <br />        dynamic-update="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />        dynamic-insert="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />    > <br /><br />        <id <br />            name="id" <br />            column="id" <br />            type="long" <br />            unsaved-value="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>" <br />        > <br />            <generator <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span>="native"> <br />            </generator> <br />        </id> <br /><br />        <property <br />            name="name" <br />            type="string" <br />            update="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            insert="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            column="name" <br />            not-<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            unique="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />        /> <br /><br />        <property <br />            name="sncId" <br />            type="long" <br />            update="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            insert="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            column="sncId" <br />            not-<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            unique="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />        /> <br /><br />        <property <br />            name="value" <br />            type="clob" <br />            update="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            insert="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            column="value" <br />            not-<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            unique="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />        /> <br />    </<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span>> <br /><br /></hibernate-mapping> <br /></div><br /></td></tr></tbody></table><span id="c4kuomg" class="postbody"><br />Q-Q-Q-Q-Q-Q-Q-Q-Q-Q- <br />insert的代码: <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span id="kmww2ge" class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">List</span> batchAddSncParameters<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">List</span> sncParametersList, <span style="COLOR: #aaaadd" ?="">Long</span> sncId<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span> DbAccessException <br />    <span style="COLOR: #000000">{</span><br />        logger.<span style="COLOR: #000000">enterMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #aaaadd" ?="">List</span> ret = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span><span style="COLOR: #aaaadd" ?="">ArrayList</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">try</span><br />        <span style="COLOR: #000000">{</span><br />            sess = getSession<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />            <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>sncParametersList != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span> && sncParametersList.<span style="COLOR: #000000">size</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span> > <span style="COLOR: #000000" ?="">0</span><span style="COLOR: #000000">)</span><br />            <span style="COLOR: #000000">{</span><br />                <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">for</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> i = <span style="COLOR: #000000" ?="">0</span>; i < sncParametersList.<span style="COLOR: #000000">size</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; i++<span style="COLOR: #000000">)</span><br />                <span style="COLOR: #000000">{</span><br />                    SNCParameters cp = <span style="COLOR: #000000">(</span>SNCParameters<span style="COLOR: #000000">)</span> sncParametersList.<span style="COLOR: #000000">get</span><span style="COLOR: #000000">(</span>i<span style="COLOR: #000000">)</span>; <br />                    long newId = -<span style="COLOR: #000000" ?="">1</span>; <br />                    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>cp != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span><span style="COLOR: #000000">)</span><br />                    <span style="COLOR: #000000">{</span><br />                        SNCParameters cpNew = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> SNCParameters<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                        cpNew.<span style="COLOR: #000000">setSncId</span><span style="COLOR: #000000">(</span>sncId<span style="COLOR: #000000">)</span>; <br />                        cpNew.<span style="COLOR: #000000">setName</span><span style="COLOR: #000000">(</span>cp.<span style="COLOR: #000000">getName</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                        cpNew.<span style="COLOR: #000000">setValue</span><span style="COLOR: #000000">(</span>Hibernate.<span style="COLOR: #000000">createClob</span><span style="COLOR: #000000">(</span>" "<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                        newId = <span style="COLOR: #000000">(</span><span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Long</span><span style="COLOR: #000000">)</span> sess.<span style="COLOR: #000000">save</span><span style="COLOR: #000000">(</span>cpNew<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">longValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                        sess.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br /><br />                        sess.<span style="COLOR: #000000">refresh</span><span style="COLOR: #000000">(</span>cpNew, LockMode.<span style="COLOR: #000000">UPGRADE</span><span style="COLOR: #000000">)</span>; <br />                        <span style="COLOR: #aaaadd" ?="">String</span> content = cp.<span style="COLOR: #000000">getValueString</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br /><br />                        <span style="COLOR: #aaaadd" ?="">String</span> appserver = <span style="COLOR: #aaaadd" ?="">System</span>.<span style="COLOR: #000000">getProperty</span><span style="COLOR: #000000">(</span>"appserver", "jboss"<span style="COLOR: #000000">)</span>; <br />                        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>!appserver.<span style="COLOR: #000000">equalsIgnoreCase</span><span style="COLOR: #000000">(</span>"jboss"<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span><br />                        <span style="COLOR: #000000">{</span><br />                            <span style="COLOR: #6666ff">//weblogic</span><br />                            OracleThinClob clob = <span style="COLOR: #000000">(</span>OracleThinClob<span style="COLOR: #000000">)</span> cpNew.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            java.<span style="COLOR: #000000">io</span>.<span style="COLOR: #000000">Writer</span> pw = clob.<span style="COLOR: #000000">getCharacterOutputStream</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">write</span><span style="COLOR: #000000">(</span>content<span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">close</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                        <span style="COLOR: #000000">}</span><br />                        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">else</span><br />                        <span style="COLOR: #000000">{</span><br />                            <span style="COLOR: #6666ff">//jboss</span><br />                            oracle.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">CLOB</span> clob = <span style="COLOR: #000000">(</span>oracle.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">CLOB</span><span style="COLOR: #000000">)</span> cpNew.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            java.<span style="COLOR: #000000">io</span>.<span style="COLOR: #000000">Writer</span> pw = clob.<span style="COLOR: #000000">getCharacterOutputStream</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">write</span><span style="COLOR: #000000">(</span>content<span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">close</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                        <span style="COLOR: #000000">}</span><br />                        ret.<span style="COLOR: #000000">add</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span><span style="COLOR: #aaaadd" ?="">Long</span><span style="COLOR: #000000">(</span>newId<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                    <span style="COLOR: #000000">}</span><br />                <span style="COLOR: #000000">}</span><br />            <span style="COLOR: #000000">}</span><br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">catch</span><span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Exception</span> e<span style="COLOR: #000000">)</span><br />        <span style="COLOR: #000000">{</span><br />            logger.<span style="COLOR: #000000">error</span><span style="COLOR: #000000">(</span>e<span style="COLOR: #000000">)</span>; <br />            ErrorReason errorReason = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> ErrorReason<span style="COLOR: #000000">(</span>ErrorReason.<span style="COLOR: #000000">INSERT_OBJECT_FAILED_REASON</span><span style="COLOR: #000000">)</span>; <br />            throw <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> DbAccessException<span style="COLOR: #000000">(</span>DbAccessException.<span style="COLOR: #000000">DBA_OPERATE_EXCEPTION</span>, errorReason<span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">finally</span><br />        <span style="COLOR: #000000">{</span><br />            closeSession<span style="COLOR: #000000">(</span>sess<span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">exitMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> ret; <br />    <span style="COLOR: #000000">}</span><br /></div><br /></td></tr></tbody></table><span id="ymwqqgy" class="postbody"><br />Q-Q-Q-Q-Q-Q-Q-Q-Q?<br />注:Weblogic必须使用<span style="FONT-WEIGHT: bold">weblogic.jdbc.vendor.oracle.OracleThinClob</span><br />Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q?<br />dCLOB字段Q?<br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span id="2uo4sks" class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">List</span> selectSncParametersBySncId<span style="COLOR: #000000">(</span>long sncId<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span> DbAccessException <br />    <span style="COLOR: #000000">{</span><br />        logger.<span style="COLOR: #000000">enterMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #aaaadd" ?="">List</span> ret = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span><span style="COLOR: #aaaadd" ?="">ArrayList</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">try</span><br />        <span style="COLOR: #000000">{</span><br />            sess = getSession<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />            <span style="COLOR: #aaaadd" ?="">String</span> query = "select cp from cp in <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span> com.<span style="COLOR: #000000">idncn</span>.<span style="COLOR: #000000">mc</span>.<span style="COLOR: #000000">bo</span>.<span style="COLOR: #000000">SNCParameters</span> where cp.<span style="COLOR: #000000">sncId</span> = ?"; <br />            logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"SQL=" + query<span style="COLOR: #000000">)</span>; <br />            <span style="COLOR: #aaaadd" ?="">List</span> iter = sess.<span style="COLOR: #000000">find</span><span style="COLOR: #000000">(</span>query, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span><span style="COLOR: #aaaadd" ?="">Long</span><span style="COLOR: #000000">(</span>sncId<span style="COLOR: #000000">)</span>, Hibernate.<span style="COLOR: #000000">LONG</span><span style="COLOR: #000000">)</span>; <br />            <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">for</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> i = <span style="COLOR: #000000" ?="">0</span>; i < iter.<span style="COLOR: #000000">size</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; i++<span style="COLOR: #000000">)</span><br />            <span style="COLOR: #000000">{</span><br />                SNCParameters newCp = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> SNCParameters<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                SNCParameters cp = <span style="COLOR: #000000">(</span>SNCParameters<span style="COLOR: #000000">)</span><span style="COLOR: #000000">(</span>iter.<span style="COLOR: #000000">get</span><span style="COLOR: #000000">(</span>i<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"after fetch:" + cp<span style="COLOR: #000000">)</span>; <br />                newCp.<span style="COLOR: #000000">setId</span><span style="COLOR: #000000">(</span>cp.<span style="COLOR: #000000">getId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                newCp.<span style="COLOR: #000000">setSncId</span><span style="COLOR: #000000">(</span>cp.<span style="COLOR: #000000">getSncId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                newCp.<span style="COLOR: #000000">setName</span><span style="COLOR: #000000">(</span>cp.<span style="COLOR: #000000">getName</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                java.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">Clob</span> clob = cp.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>clob != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span><span style="COLOR: #000000">)</span><br />                <span style="COLOR: #000000">{</span><br />                    logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"b===" + clob.<span style="COLOR: #000000">length</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                    <span style="COLOR: #aaaadd" ?="">String</span> b = clob.<span style="COLOR: #000000">getSubString</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000" ?="">1</span>, <span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span><span style="COLOR: #000000">)</span> clob.<span style="COLOR: #000000">length</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                    <span style="COLOR: #6666ff">//logger.debug("b==="+b);</span><br />                    newCp.<span style="COLOR: #000000">setValueString</span><span style="COLOR: #000000">(</span>b<span style="COLOR: #000000">)</span>; <br />                <span style="COLOR: #000000">}</span><br />                ret.<span style="COLOR: #000000">add</span><span style="COLOR: #000000">(</span>newCp<span style="COLOR: #000000">)</span>; <br />            <span style="COLOR: #000000">}</span><br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">catch</span><span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Exception</span> e<span style="COLOR: #000000">)</span><br />        <span style="COLOR: #000000">{</span><br />            logger.<span style="COLOR: #000000">error</span><span style="COLOR: #000000">(</span>e<span style="COLOR: #000000">)</span>; <br />            ErrorReason errorReason = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> ErrorReason<span style="COLOR: #000000">(</span>ErrorReason.<span style="COLOR: #000000">SELECT_FAILED_REASON</span><span style="COLOR: #000000">)</span>; <br />            throw <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> DbAccessException<span style="COLOR: #000000">(</span>DbAccessException.<span style="COLOR: #000000">DBA_OPERATE_EXCEPTION</span>, errorReason<span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">finally</span><br />        <span style="COLOR: #000000">{</span><br />            closeSession<span style="COLOR: #000000">(</span>sess<span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">exitMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> ret; <br />    <span style="COLOR: #000000">}</span><br /></div><br /></td></tr></tbody></table><span id="iqqqyyi" class="postbody"><br />Q-Q-Q-Q-Q-Q-Q-Q?<br />更新q个字段的代码: <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span id="iisscck" class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> updateSncParameters<span style="COLOR: #000000">(</span>SNCParameters newParam<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span> DbAccessException <br />    <span style="COLOR: #000000">{</span><br />        logger.<span style="COLOR: #000000">enterMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">try</span><br />        <span style="COLOR: #000000">{</span><br />            sess = getSession<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br /><br />            <span style="COLOR: #aaaadd" ?="">Long</span> id = newParam.<span style="COLOR: #000000">getId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />            SNCParameters pp = <span style="COLOR: #000000">(</span>SNCParameters<span style="COLOR: #000000">)</span> sess.<span style="COLOR: #000000">load</span><span style="COLOR: #000000">(</span>SNCParameters.<span style="COLOR: #000000">class</span>, id, net.<span style="COLOR: #000000">sf</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">LockMode</span>.<span style="COLOR: #000000">UPGRADE</span><span style="COLOR: #000000">)</span>; <br /><br />            pp.<span style="COLOR: #000000">setSncId</span><span style="COLOR: #000000">(</span>newParam.<span style="COLOR: #000000">getSncId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />            pp.<span style="COLOR: #000000">setName</span><span style="COLOR: #000000">(</span>newParam.<span style="COLOR: #000000">getName</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />            pp.<span style="COLOR: #000000">setId</span><span style="COLOR: #000000">(</span>newParam.<span style="COLOR: #000000">getId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br /><br />            <span style="COLOR: #aaaadd" ?="">String</span> newValue = newParam.<span style="COLOR: #000000">getValueString</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"Update Length =" + newValue.<span style="COLOR: #000000">length</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br /><br />            <span style="COLOR: #aaaadd" ?="">String</span> appserver = <span style="COLOR: #aaaadd" ?="">System</span>.<span style="COLOR: #000000">getProperty</span><span style="COLOR: #000000">(</span>"appserver", "jboss"<span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"appserver: " + appserver<span style="COLOR: #000000">)</span>; <br />            <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>!appserver.<span style="COLOR: #000000">equalsIgnoreCase</span><span style="COLOR: #000000">(</span>"jboss"<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span><br />            <span style="COLOR: #000000">{</span><br />                <span style="COLOR: #6666ff">//weblogic</span><br />                OracleThinClob clob = <span style="COLOR: #000000">(</span>OracleThinClob<span style="COLOR: #000000">)</span> pp.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>pp != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span><span style="COLOR: #000000">)</span><br />                <span style="COLOR: #000000">{</span><br />                    java.<span style="COLOR: #000000">io</span>.<span style="COLOR: #000000">Writer</span> pw = clob.<span style="COLOR: #000000">getCharacterOutputStream</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">write</span><span style="COLOR: #000000">(</span>newValue<span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">close</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="COLOR: #000000">}</span><br />            <span style="COLOR: #000000">}</span><br />            <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">else</span><br />            <span style="COLOR: #000000">{</span><br />                <span style="COLOR: #6666ff">//jboss</span><br />                oracle.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">CLOB</span> clob = <span style="COLOR: #000000">(</span>oracle.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">CLOB</span><span style="COLOR: #000000">)</span> pp.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>pp != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span><span style="COLOR: #000000">)</span><br />                <span style="COLOR: #000000">{</span><br />                    java.<span style="COLOR: #000000">io</span>.<span style="COLOR: #000000">Writer</span> pw = clob.<span style="COLOR: #000000">getCharacterOutputStream</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">write</span><span style="COLOR: #000000">(</span>newValue<span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">close</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="COLOR: #000000">}</span><br />            <span style="COLOR: #000000">}</span><br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">catch</span><span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Exception</span> e<span style="COLOR: #000000">)</span><br />        <span style="COLOR: #000000">{</span><br />            logger.<span style="COLOR: #000000">error</span><span style="COLOR: #000000">(</span>e<span style="COLOR: #000000">)</span>; <br />            ErrorReason errorReason = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> ErrorReason<span style="COLOR: #000000">(</span>ErrorReason.<span style="COLOR: #000000">UPDATE_OBJECT_FAILED_REASON</span><span style="COLOR: #000000">)</span>; <br />            throw <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> DbAccessException<span style="COLOR: #000000">(</span>DbAccessException.<span style="COLOR: #000000">DBA_OPERATE_EXCEPTION</span>, errorReason<span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">finally</span><br />        <span style="COLOR: #000000">{</span><br />            closeSession<span style="COLOR: #000000">(</span>sess<span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">exitMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />    <span style="COLOR: #000000">}</span><br /></div></td></tr></tbody></table><br /><br /><img src ="http://m.tkk7.com/buaacaptain/aggbug/57616.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/buaacaptain/" target="_blank">舚w</a> 2006-07-11 11:07 <a href="http://m.tkk7.com/buaacaptain/archive/2006/07/11/57616.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://m.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> վ֩ģ壺 <a href="http://baicaijia666.com" target="_blank">պAvĻþþ޸</a>| <a href="http://3344by.com" target="_blank">Ұ߹ۿƵ</a>| <a href="http://mtsp5.com" target="_blank">AëƬA</a>| <a href="http://lybb16.com" target="_blank">ҴýһAV </a>| <a href="http://4922000.com" target="_blank">߹ۿ</a>| <a href="http://cqkalai.com" target="_blank">ѿڿŮ</a>| <a href="http://adcadm.com" target="_blank">þþŷղAV</a>| <a href="http://yinyinai155.com" target="_blank">һƵ</a>| <a href="http://www-7479.com" target="_blank">һëƬƵ</a>| <a href="http://www-887234.com" target="_blank">99ƷһƵ</a>| <a href="http://dsdkg.com" target="_blank">˳Ƶ߹ۿվ </a>| <a href="http://abbobo.com" target="_blank">޾Ʒ벻߲</a>| <a href="http://xian66.com" target="_blank">ɫŮһ</a>| <a href="http://www398ph.com" target="_blank">޾Ʒһ23Ŀ</a>| <a href="http://www621f.com" target="_blank">jizzjizzٸ</a>| <a href="http://goldwellib.com" target="_blank">AV˾Ʒһ</a>| <a href="http://cqshangshu.com" target="_blank">þþ޾ҺҺҺ</a>| <a href="http://155562.com" target="_blank">߹ۿ޾Ʒר</a>| <a href="http://www827556.com" target="_blank">޹Ʒۺ˳ۺվ</a>| <a href="http://f4f8.com" target="_blank">޴רӰԺ</a>| <a href="http://www621f.com" target="_blank">޹ۺרߵӰ</a>| <a href="http://fsszx888.com" target="_blank">޹˾Ʒ91þþ</a>| <a href="http://theav25.com" target="_blank">¹ŮһëƬ</a>| <a href="http://mtripmall.com" target="_blank">ҹƵվ</a>| <a href="http://by22877.com" target="_blank">ĻmvֻѸ</a>| <a href="http://yx6768.com" target="_blank">51ƵѹۿƵ</a>| <a href="http://by6174.com" target="_blank">պAVһ</a>| <a href="http://hberay.com" target="_blank">99Ʒѹۿ</a>| <a href="http://ding001.com" target="_blank">aëƬ</a>| <a href="http://jpvv8.com" target="_blank">Ļ벥</a>| <a href="http://see01.com" target="_blank">ҾƷѾþþþӰԺ </a>| <a href="http://s8sb.com" target="_blank">˳ѵӰ</a>| <a href="http://qixiresort.com" target="_blank">ƷŮٸAVѹۿ</a>| <a href="http://fenxiangceo.com" target="_blank">ƬƵۿ</a>| <a href="http://hidiaoyan.com" target="_blank">Ļר</a>| <a href="http://class3g.com" target="_blank">ղƷaëƬþ</a>| <a href="http://pj9xx6.com" target="_blank">ŷ͵ҹɫ</a>| <a href="http://519vip.com" target="_blank">AרAV</a>| <a href="http://lawelites.com" target="_blank">Ƶ߲</a>| <a href="http://6363388.com" target="_blank">޴ɫAvר</a>| <a href="http://eddiekidd.com" target="_blank">ػɫĴƬۿƵ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>