|
2007年2月8日
作者 cctvx1 ?關鍵字:ActiveMQ,實踐?
??? 一.安裝ActiveMQ
?????? 首先去http://activemq.apache.org/download.html 下載最新版本4.1.0release (http://activemq.apache.org/activemq-410-release.html), ??? 解壓apache-activemq-4.1-incubator.zip(或者apache-activemq-4.1-incubator.tar.gz)目錄如下: ?????? ?????? +bin?????? (windows下面的bat和unix/linux下面的sh) ?????? +conf????? (activeMQ配置目錄,包含最基本的activeMQ配置文件) ?????? +data????? (默認是空的) ?????? +docs????? (index,replease版本里面沒有文檔,-.-b不知道為啥不帶) ?????? +example?? (幾個例子 ?????? +lib?????? (activemMQ使用到的lib) ?????? -apache-activemq-4.1-incubator.jar? (ActiveMQ的binary) ?????? -LICENSE.txt?????? ?????? -NOTICE.txt??????? ?????? -README.txt ?????? -user-guide.html
?????? 你可以使用bin\activemq.bat(activemq) 啟動,如果一切順利,你就會看見類似下面的信息 ????? (細節可能不一樣,比如路徑,或者jmx,jdbc信息)
? ACTIVEMQ_HOME: D:\java\framework_and_lib\activemq\apache-activemq-4.1-incubator\ bin\.. Loading message broker from: xbean:activemq.xml INFO? BrokerService????????????????? - ActiveMQ null JMS Message Broker (localho st) is starting INFO? BrokerService????????????????? - For help or more information please see: http://incubator.apache.org/activemq/ INFO? ManagementContext????????????? - JMX consoles can connect to service:jmx:r mi:///jndi/rmi://localhost:1099/jmxrmi INFO? JDBCPersistenceAdapter???????? - Database driver recognized: [apache_derby _embedded_jdbc_driver] INFO? DefaultDatabaseLocker????????? - Attempting to acquire the exclusive lock to become the Master broker INFO? DefaultDatabaseLocker????????? - Becoming the master on dataSource: org.ap ache.derby.jdbc.EmbeddedDataSource@1d840cd INFO? JournalPersistenceAdapter????? - Journal Recovery Started from: Active Jou rnal: using 5 x 20.0 Megs at: D:\java\framework_and_lib\activemq\apache-activemq -4.1-incubator\activemq-data\journal INFO? JournalPersistenceAdapter????? - Journal Recovered: 0 message(s) in transa ctions recovered. INFO? TransportServerThreadSupport?? - Listening for connections at: tcp://P-SUW EI:61616 WARN? MulticastDiscoveryAgent??????? - brokerName not set INFO? TransportConnector???????????? - Connector default Started INFO? TransportServerThreadSupport?? - Listening for connections at: stomp://P-S UWEI:61613 INFO? TransportConnector???????????? - Connector stomp Started INFO? NetworkConnector?????????????? - Network Connector default Started INFO? BrokerService????????????????? - ActiveMQ JMS Message Broker (localhost, I D:P-SUWEI-1207-1170916242296-1:0) started?????
???????? *。幾個小提示 ? 1. 這個僅僅是最基礎的ActiveMQ的配置,很多地方都沒有配置因此不要直接使用這個配置用于生產系統 ? 2. 有的時候由于端口被占用,導致ActiveMQ錯誤,ActiveMQ可能需要以下端口1099(JMX),61616(默認的TransportConnector) ? 3. 如果沒有物理網卡,或者MS的LoopBackAdpater Multicast會報一個錯誤
???? 二. 測試你的ActiveMQ ??????? ????????? 由于ActiveMQ是一個獨立的jms provider,所以我們不需要其他任何第三方服務器就可以馬上做我們的測試了.編譯 ???? example目錄下面的程序 ????????? ?? ProducerTool/ConsumerTool 是JMS參考里面提到的典型應用,Producer產生消息,Consumer消費消息 ?? 而且這個例子還可以加入參數幫助你測試剛才啟動的本地ActiveMQ或者是遠程的ActiveMQ
?? ProducerTool [url] broker的地址,默認的是tcp://localhost:61616 ??????????????? [true|flase] 是否使用topic,默認是false ???????? [subject] subject的名字,默認是TOOL.DEFAULT ???????? [durabl] 是否持久化消息,默認是false ???????? [messagecount] 發送消息數量,默認是10 ???????? [messagesize] 消息長度,默認是255 ???????? [clientID] durable為true的時候,需要配置clientID ???????? [timeToLive] 消息存活時間 ???????? [sleepTime] 發送消息中間的休眠時間 ???????? [transacte]? 是否采用事務
????????? ????????? ConsumerTool [url] broker的地址,默認的是tcp://localhost:61616 ??????????????? [true|flase] 是否使用topic,默認是false ???????? [subject] subject的名字,默認是TOOL.DEFAULT ???????? [durabl] 是否持久化消息,默認是false ???????? [maxiumMessages] 接受最大消息數量,0表示不限制 ??????? ???????? [clientID] durable為true的時候,需要配置clientID ???????? ???????? [transacte]? 是否采用事務 ???????? [sleepTime]? 接受消息中間的休眠時間,默認是0,onMeesage方法不休眠 ???????? [receiveTimeOut] 接受超時
????????? 我們這樣可以使用: ?? java -classpath .\apache-activemq-4.1-incubator.jar;example\bin ProducerTool? tcp://192.168.3.142:61616 test.mysubject ?? java -classpath .\apache-activemq-4.1-incubator.jar;example\bin ConsumerTool? tcp://192.168.3.142:61616 test.mysubject
?? 當然你可以使用上面的參數進行更復雜的測試,持久,事務
?? 如果出現下面的信息,恭喜你,你的ActiveMQ已經能夠工作了 ???????? ? Connecting to URL: tcp://192.168.3.142:61616 ? Publishing a Message with size 255 to queue: TOOL.DEFAULT ? Using non-durable publishing ? Sleeping between publish 0 ms ? Sending message: Message: 0 sent at: Thu Feb 08 15:05:34 CST 2007? ... ? Sending message: Message: 1 sent at: Thu Feb 08 15:05:34 CST 2007? ... ???????? 。。。。。。。。
? Connecting to URL: tcp://192.168.3.142:61616 ? Consuming queue: test.mysubject ???????? Using non-durable subscription ???????? Received: Message: 0 sent at: Thu Feb 08 14:51:34 CST 2007? ... ???????? Received: Message: 1 sent at: Thu Feb 08 14:51:34 CST 2007? ... ? 。。。。
???????? 三.小結 ????? ????? 我們已經下載,啟動,并且用程序測試了我們的ActiveMQ,而后面將在這個能跑得ActiveMQ進一步的走下去,一步一步展示ActiveMQ的高級特性。
2007年2月7日
?? 作者cctvx1 ?? 關鍵字:ActiveMQ,實踐 ??? ?? 一.ActiveMQ是什么?? ????? ActiveMQ is the most popular and powerful open source Message Bus. ???????????????????????????????????????????????? 引用ActiveMQ官方網站
???? ActiveMQ 是一個完全支持JMS1.1和J2EE 1.4規范的 JMS Provider實現,盡管JMS規范出臺 已經是很久的事情了,但是JMS在當今的J2EE應用中間仍然扮演著特殊的地位。 ??? 下面是它的特性列表 (詳細的特性清單請參考http://activemq.apache.org/features.html) ?? ?1.多種語言和協議編寫客戶端 ?? ??語言: Java, C, C++, C#, Ruby, Perl, Python, PHP ????? ??應用協議: OpenWire,Stomp REST,WS Notification,XMPP,AMQP ?? ?2.完全支持JMS1.1和J2EE 1.4規范? (持久化,XA消息,事務) ?? ?3.對Spring的支持,ActiveMQ可以很容得內嵌到使用Spring的系統里面去,而且也支持Spring2.0的特性 ?????? 4.通過了常見J2EE服務器(如 Geronimo,JBoss 4, GlassFish,WebLogic)的測試,其中通過JCA 1.5 resource adaptors的配置, ????? 可以讓ActiveMQ可以自動的部署到任何兼容J2EE 1.4 商業服務器上 ?????? 5.支持多種傳送協議:in-VM,TCP,SSL,NIO,UDP,JGroups,JXTA ?????? 6.支持通過JDBC和journal提供高速的消息持久化 ?????? 7.從設計上保證了高性能的集群,客戶端-服務器,點對點 ?????? 8.支持Ajax ?????? 9.支持與Axis的整合 ?????? 10.可以很容易得調用內嵌JMS provider,進行測試 ?????? ???? 二.ActiveMQ的競爭者??? ??????? ??????? 1.其他開源 JMS provider(資料來自 java-source.net) : ??????? jbossmq(jboss 4) ??????? jboss messaging (jboss 5) ??????? joram-4.3.21? 2006-09-22 ??????? openjms-0.7.7-alpha-3.zip December 26, 2005 ??????? mantamq 官網暫時無法訪問 ??????? ubermq? 官網暫時無法訪問 ??????? SomnifugiJMS? 2005-7-27 ?????????? 開源的JMS Provider大部分都已經停止發展了,剩下的幾個都是找到了東家,和某種J2EE 服務器掛鉤, ??????? 比如jboss mq 與jboss,joram與jonas(objectweb組織),ActiveMQ 與Geronimo(ASF APACHE基金組織), ??????? 而在這3個之間,從網絡底層來看,只有ActiveMQ使用了NIO,單從這個角度來看ActiveMQ在性能上會有 ??????? 一定的優勢??????
??????? 2.商業JMS provider ??????? IBM WebSphere MQ ??????? BEA WebLogic JMS ??????? Oracle AQ ??????? NonStop Server for Java Message Service(JMS) ??????? Sun Java System Message Queue ??????? Sonic jms ??????? TIBCO Enterprise For JMS ??????? iLinkMQ (國內) ?????????? 現在的商業J2EE 應用服務器大部分都會有JMS Provider的實現,畢竟應用服務器都已經花費不薄,也不在乎 ??????? 在里面送一個JMS Provider了,當然還是有獨立的比如IBM WebSphere MQ,Sonic JMS ,前者肯定是商用MQ ?????? (這個概念不僅僅是JMS Provier了,只能說JMS 只是它提供的一個應用)中間的巨無霸了。 ??????? ???????? 從這點來看,ActiveMQ明顯的競爭者并不多,因為它是作為獨立的開源JMS Provider出現的,很容易被用于多種結構設計中, ??????? 使用ActiveMQ作為默認JMS Provider的開源項目有ServiceMix,Geronimo. ? ?????????????????????????????????????????????????????????????????????????????????????????????? (待續) ??????? P.S ??????????? Monday, February 5, 2007 ????? Apache ActiveMQ graduates from the incubator? ????? Apache ActiveMQ has now graduated to become a top level project (TLP) at Apache! Its new site is now hosted at http://activemq.apache.org/. Many thanks to all those in the Incubator and ActiveMQ communities for making this happen!
2007年1月30日
主要就是正則表達式的運用,除了mod_rewrite之外還有一個urlrewritefilter 下面是一個測試二級域名映射規則
RewriteEngine On RewriteCond %{HTTP_HOST} ^[^www.]+.test.ecom$ Rewriterule ^(.+) %{HTTP_HOST}$1 [C]? Rewriterule ^([^www.]+)\.test\.ecom(.*) /shop_$1$2 Rewriterule ^www.test.ecom(.*) /$1 [nc,PT] RewriteRule /shop_(.+)/pic/(.*)$ /pic/$2 [nc,PT] RewriteRule /shop_(.+)/js/(.*)$ /js/$2 [nc,PT] RewriteRule /shop_(.+)/css/(.*)$ /css/$2 [nc,PT] RewriteRule /shop_(.+)/(.+).do?(\.*)$? /$2.do?domainName=$1&%{QUERY_STRING} [L,nc]
RewriteLog "logs/rewrite.log" RewriteLogLevel 3
關鍵字段: ??????????????? RewriteCond 表示如果條件滿足則使用下面的Rewriterule ??????????????? Rewriterule 就是采用具體的正則表達式來匹配? ??????????????????????????????????? Rewriterule 后面還可以帶有參數
???????????? 見apache參考 ?????????? http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html ?????????
- '
chain|C ' (chained with next rule) This flag chains the current rule with the next rule (which itself can be chained with the following rule, and so on). This has the following effect: if a rule matches, then processing continues as usual - the flag has no effect. If the rule does not match, then all following chained rules are skipped. For instance, it can be used to remove the ``.www '' part, inside a per-directory rule set, when you let an external redirect happen (where the ``.www '' part should not occur!).
- '
cookie|CO= NAME:VAL:domain[:lifetime[:path]]' (set cookie) This sets a cookie in the client's browser. The cookie's name is specified by NAME and the value is VAL. The domain field is the domain of the cookie, such as '.apache.org', the optional lifetime is the lifetime of the cookie in minutes, and the optional path is the path of the cookie
- '
env|E= VAR:VAL' (set environment variable) This forces an environment variable named VAR to be set to the value VAL, where VAL can contain regexp backreferences ($N and %N ) which will be expanded. You can use this flag more than once, to set more than one variable. The variables can later be dereferenced in many situations, most commonly from within XSSI (via <!--#echo var="VAR"--> ) or CGI ($ENV{'VAR'} ). You can also dereference the variable in a later RewriteCond pattern, using %{ENV:VAR} . Use this to strip information from URLs, while maintaining a record of that information.
- '
forbidden|F ' (force URL to be forbidden) This forces the current URL to be forbidden - it immediately sends back a HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with appropriate RewriteConds to conditionally block some URLs.
- '
gone|G ' (force URL to be gone) This forces the current URL to be gone - it immediately sends back a HTTP response of 410 (GONE). Use this flag to mark pages which no longer exist as gone.
- '
handler|H =Content-handler' (force Content handler) Force the Content-handler of the target file to be Content-handler. For instance, this can be used to simulate the mod_alias directive ScriptAlias , which internally forces all files inside the mapped directory to have a handler of ``cgi-script ''.
- '
last|L ' (last rule) Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/ ') to a real one, e.g., '/e/www/ '.
- '
next|N ' (next round) Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop. Be careful not to create an infinite loop!
- '
nocase|NC ' (no case) This makes the Pattern case-insensitive, ignoring difference between 'A-Z' and 'a-z' when Pattern is matched against the current URL.
- '
noescape|NE ' (no URI escaping of output) This flag prevents mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from happening. This allows percent symbols to appear in the output, as in
RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
which would turn '/foo/zed ' into a safe request for '/bar?arg=P1=zed '.
- '
nosubreq|NS ' (not for internal sub-requests) This flag forces the rewriting engine to skip a rewriting rule if the current request is an internal sub-request. For instance, sub-requests occur internally in Apache when mod_include tries to find out information about possible directory default files (index.xxx files). On sub-requests it is not always useful, and can even cause errors, if the complete set of rules are applied. Use this flag to exclude some rules. To decide whether or not to use this rule: if you prefix URLs with CGI-scripts, to force them to be processed by the CGI-script, it's likely that you will run into problems (or significant overhead) on sub-requests. In these cases, use this flag.
- '
proxy|P ' (force proxy) This flag forces the substitution part to be internally sent as a proxy request and immediately (rewrite processing stops here) put through the proxy module. You must make sure that the substitution string is a valid URI (typically starting with http:// hostname) which can be handled by the Apache proxy module. If not, you will get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map remote content into the namespace of the local server.
Note: mod_proxy must be enabled in order to use this flag.
- '
passthrough|PT ' (pass through to next handler) This flag forces the rewrite engine to set the uri field of the internal request_rec structure to the value of the filename field. This flag is just a hack to enable post-processing of the output of RewriteRule directives, using Alias , ScriptAlias , Redirect , and other directives from various URI-to-filename translators. For example, to rewrite /abc to /def using mod_rewrite , and then /def to /ghi using mod_alias :
RewriteRule ^/abc(.*) /def$1 [PT] Alias /def /ghi
If you omit the PT flag, mod_rewrite will rewrite uri=/abc/... to filename=/def/... as a full API-compliant URI-to-filename translator should do. Then mod_alias will try to do a URI-to-filename transition, which will fail.
Note: You must use this flag if you want to mix directives from different modules which allow URL-to-filename translators. The typical example is the use of mod_alias and mod_rewrite .
- '
qsappend|QSA ' (query string append) This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.
- '
redirect|R [=code]' (force redirect) Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the appropriate number or use one of the following symbolic names: temp (default), permanent , seeother . Use this for rules to canonicalize the URL and return it to the client - to translate ``/~ '' into ``/u/ '', or to always append a slash to /u/ user, etc. Note: When you use this flag, make sure that the substitution field is a valid URL! Otherwise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend http://thishost[:thisport]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this point, and redirect immediately. To stop rewriting, you should add the 'L' flag.
- '
skip|S =num' (skip next rule(s)) This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N , where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!)
- '
type|T =MIME-type' (force MIME type) Force the MIME-type of the target file to be MIME-type. This can be used to set up the content-type based on some conditions. For example, the following snippet allows .php files to be displayed by mod_php if they are called with the .phps extension:
RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]
????????????????
2007年1月23日
ConcurrentModificationException 一個不該犯的低級錯誤,今天的代碼突然拋了一個concurrentModificationException錯誤, Iterator的一個基本概念沒有掌握導致的這個錯誤,就是在Iterator的實現類 比如Hashtable里面的內部類 ?private class Enumerator<T> implements Enumeration<T>, Iterator<T>
會在next,或者remove的時候檢查當前集合是否會在修改狀態,如果是的話 就會拋出 ConcurrentModificationException,而他自己remove則是使用了同步的方法 而且同步了modCount;expectedModCount;
?public T next() { ???? if (modCount != expectedModCount) ??throw new ConcurrentModificationException(); ???? return nextElement(); ?}
public void remove() { ???? if (!iterator) ??throw new UnsupportedOperationException(); ???? if (lastReturned == null) ??throw new IllegalStateException("Hashtable Enumerator"); ???? if (modCount != expectedModCount) ??throw new ConcurrentModificationException();
???? synchronized(Hashtable.this) { ??Entry[] tab = Hashtable.this.table; ??int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
??for (Entry<K,V> e = tab[index], prev = null; e != null; ?????? prev = e, e = e.next) { ????? if (e == lastReturned) { ???modCount++; ???expectedModCount++; ???if (prev == null) ?????? tab[index] = e.next; ???else ?????? prev.next = e.next; ???count--; ???lastReturned = null; ???return; ????? } ??} ??throw new ConcurrentModificationException(); ???? } ?} ??? } 而自己在next的同時,修改了這個集合,導致了這個錯誤的出現
2007年1月3日
Spring 官方已經提到這個錯誤了
http://www.springframework.org/docs/reference/xsd-config.html#xsd-config-integration-resin
A.3.3.1. XML parsing errors in the Resin v.3 application server
If you are using the XSD-style for Spring 2.0 XML configuration and deploying to v.3 of Caucho's Resin application server, you will need to set some configuration options prior to startup so that an XSD-aware parser is available to Spring. Please do read this resource
而resin給出來的參考就是他默認不是使用xerces和xalan作為xml和xslt的默認解析器
正是由于他默認不是采用以上作為xml,xstl的解析器,導致了在resin下面 使用spring 2.0 新xsd配置方式會報錯誤
(主要就是xml中的attribute和propertie 他取不到)
解決的方法就是讓resin使用xerces和xalan作為xml和xslt的默認解析器
配置:
在resin.conf的<web-app>或者<server>節點下添加
<!-- xml --> <system-property javax.xml.parsers.DocumentBuilderFactory= ???????????? "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/> <system-property javax.xml.parsers.SAXParserFactory= ???????????? "org.apache.xerces.jaxp.SAXParserFactoryImpl"/> ?? ??? <!--? xslt --> <system-property javax.xml.transform.TransformerFactory= ???????????? "org.apache.xalan.processor.TransformerFactoryImpl"/>
然后把相應的jar加入%RESIN_HOME%/lib 目錄,這里需要說明的是我在測試activemq的時候
加入xerces和xalan后,他包其他class無法找到,感覺好像是默認的web-app目錄下的jar無效了,我暫時直接加入系統classpath解決的
這點不知道是不是我自己的平臺問題。
經過測試 resin 3.0.22+spring 2.0+activemq xsd配置方式ok了,
ps. ^.^ 以前的resin下面項目沒有用2.0配置,自己也學習到了新東西
2006年12月10日
2006年11月27日
Apache 2.2.3 Subversion 1.4.0(r21228) integrate reference : ?????????
http://xrinehart.cnblogs.com/archive/2005/10/27/262759.html
?????????
http://xrinehart.cnblogs.com/archive/2005/10/29/264659.html
?????????
http://www.apachelounge.com/forum/viewtopic.php?t=121
????????????????????? (maniac provide svn 1.4.0 module win32? binary for apache 2.2.x) Warning: ??????? subversion.tigris.org ??????? Windows binaries - ATTENTION!: The mod_dav_svn binaries available here are NOT compatible with Apache 2.2
FAQ: ???? Error:? Expected fromat '3' of repository;found format '5' ???????????? use "--pre-1.4-compatible", default format is "5" !! ??????????? Integrate Guide: ??????????? I? use other complie svn module for apache 2.2.3 , ???? Step1: ???????????? copy *.dll to? %APACHE_HOME%\bin ???????????? copy *.so? to? %APACHE_HOME%\modules ???? Step2: ???????????? edit %APACHE_HOME%\conf\httpd.conf ???????????? find: ???????????????? #LoadModule dav_module? modules\mod_dav.so ???????????????? #LoadModule dav_fs_module modules\mod_dav_fs.so ???????????? change: "#" to "" ???????????????? LoadModule dav_module? modules\mod_dav.so ???????????????? LoadModule dav_fs_module modules\mod_dav_fs.so ???????????? and add SVN Module: ???????????????? #SVN ???????????????? LoadModule dav_svn_module?? modules\mod_dav_svn.so ???????????????? LoadModule authz_svn_module? modules\mod_authz_svn.so ????? Step3:? ????????????? config? SVN auth,add httpd.conf ????????????? use apache basic auth,gen password file ??????????????? %APACHE_HOME%\bin\htpasswd -cm D:/server/webservice/clear/Apache2.2/svn-auth/svn-auth-file harry
??????????????? <IfModule dav_svn_module> ???????????????? <Location /svn> ?????????????????? DAV svn ?????????????????? SVNParentPath D:/SubversionRoot ?????????????????? AuthTypeBasic ?????????????????? AuthName "Subversion Repository" ?????????????????? AuthUserFile D:/server/webservice/clear/Apache2.2/svn-auth/svn-auth-file ?????? Require valid-user ???????????????? </Location> ??????????????? </IfModule> ??????? 主要就是svn官方的win binary不支持apache 2.2的新module調用。 ??????
????????????????
?
2006年11月17日
?? 我記得以前在Matrix上面,老是看見"農民"的blog <<一畝三分地>>,? 不過我一直都沒有經營好自己的這塊田地,matrix上的blog已經荒廢很久了。
???是該拿起鋤頭reload了,如果blog算是一種態度的話,我要重新找回這種態度,一晃眼,2006年就過去了,在春天之前,我又感受到了嚴寒,也許想法太多,與其這樣不如 just do it!
演示的sqlMap 配置文件,通過'$'和'*'的使用,達到動態映射Table到一個map的作用
<?
xml?version="1.0"?encoding="UTF-8"?
?>
<!
DOCTYPE?sqlMap?PUBLIC?"-//iBATIS.com//DTD?SQL?Map?2.0//EN"?"http://www.ibatis.com/dtd/sql-map-2.dtd"?
>
<
select?
id
="useAutoResultMapExample"
?parameterClass
="map"
>
USE?$dbName$
SELECT *? FROM?? $tableName$
</
select
>
</
sqlMap
>
也就是在IBatis里面配置一個statment,去執行多個查詢,充分利用了map映射的特性.
去執行多個查詢。
比如 select * from myexample select * from mywork
使用"*" 而且沒有用resultClass 指定返回
但是在默認配置下,在使用的時候的時候
2次以上傳入不同的$dbName$,$tabeName$ 調用這個useAutoResultMapExample,
就要報java.sql.SQLException: Invalid column name錯誤
因為iBatis自己有 AutoResultMap的cache,盡管你傳入的$tableName$不同,但是他總是
用第一個建立的AutoResultMap的cache去匹配以后的$tableName$當然有錯誤了
解決方法: 使用多個statment或者使用 remapResults="true" (為了效率他默認的是false)
以上由于效率問題,建議還是采用多個statement 映射到不同的model上面去,不建議生產系統也這么使用。
|