Annotations | Lazy | Fetch |
---|---|---|
@[One|Many]ToOne](fetch=FetchType.LAZY) | @LazyToOne(PROXY) | @Fetch(SELECT) |
@[One|Many]ToOne](fetch=FetchType.EAGER) | @LazyToOne(FALSE) | @Fetch(JOIN) |
@ManyTo[One|Many](fetch=FetchType.LAZY) | @LazyCollection(TRUE) | @Fetch(SELECT) |
@ManyTo[One|Many](fetch=FetchType.EAGER) | @LazyCollection(FALSE) | @Fetch(JOIN) |
緙撳瓨鐨勬敞閲婂啓娉曞涓嬶紝鍔犲湪Entity鐨刯ava綾諱笂錛?br />
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
緙撳瓨鐨勬柟寮忔湁鍥涚錛屽垎鍒負(fù)錛?/p>
姝ゅ叧閿瓧璁╄鍒欏紩鎿庣煡閬擄紝myGlobalList瀵硅薄搴旇鍙互浠庤鍒欎腑璁塊棶.rule錛氬畾涔変簡涓涓鍒?br />甯哥敤鐨勫睘鎬э細(xì)
rule "<name>"
<attribute>*
when
<conditional element>*
then
<action>*
end
<name> 鍗硆ule鐨勫悕瀛楁爣璇?br />
<attribute>:
lock-on-active錛歵rue 鍙互鐪嬩綔鏄痭o-loop鐨勫姞寮虹増錛屽綋鏉′歡緇撴灉鏇存敼鍚庯紝涓嶄絾淇敼姝ゆ潯浠剁殑瑙勫垯涓嶄細(xì)閲嶆柊鎵ц錛屾枃浠朵腑鐨勪換浣曡鍒欙紙鍏?active-lock 灞炴ц璁句負(fù)true
錛変笉浼?xì)閲嶆柊鎵ц銆?/pre>salience
錛?00 浣跨敤瀹冨彲浠ヨ瑙勫垯鎵ц寮曟搸鐭ラ亾搴旇鍚姩瑙勫垯鐨勭粨鏋滆鍙ョ殑欏哄簭銆傚叿鏈夋渶楂樻樉钁楀肩殑瑙勫垯鐨勭粨鏋滆鍙ラ鍏堟墽琛岋紱鍏鋒湁絎簩楂樻樉钁楀肩殑瑙勫垯鐨勭粨鏋滆鍙ョ浜屾墽琛岋紝渚濇綾繪帹銆傚綋鎮(zhèn)ㄩ渶瑕佽瑙勫垯鎸夐瀹氫箟欏哄簭鍚姩鏃訛紝榪欎竴鐐歸潪甯擱噸瑕併?br />
鍏朵粬灞炴х殑瑙i噴璇瘋http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-expert/html_single/index.html#d0e2607
when:濉啓鏉′歡鐨勫湴鏂癸紝姣斿錛?br />Cheese( type == "stilton", price < 10, age == "mature" )鎴?br />then:涓氬姟瑙勫垯鐨勫湴鏂癸紝鐣ャ?br />
Cheese( type == "stilton" && price < 10, age == "mature" )
2.鐢ㄦ硶
瑙勫垯鏂囦歡瀹氫箟濂藉悗錛屽氨璇ユ槸鎬庝箞浣跨敤瀹冧簡
濡備笂鍥撅紝file rule瀹氫箟濂藉悗錛屽氨璇ユ槸濡備綍浣跨敤瀹冧簡銆傛渶閲嶈鐨勪袱涓被RuleBase鍜學(xué)orkingMemory
涓嬮潰鏄竴涓猠xample:
public class RulesEngine {
private RuleBase rules;
private boolean debug = false;
public RulesEngine(String rulesFile) throws RulesEngineException {
super();
try {
// Read in the rules source file
Reader source = new InputStreamReader(RulesEngine.class
.getResourceAsStream("../../rules/" + rulesFile));
// Use package builder to build up a rule package
PackageBuilder builder = new PackageBuilder();
// This will parse and compile in one step
builder.addPackageFromDrl(source);
// Get the compiled package
Package pkg = builder.getPackage();
// Add the package to a rulebase (deploy the rule package).
rules = RuleBaseFactory.newRuleBase();
rules.addPackage(pkg);
} catch (Exception e) {
throw new RulesEngineException(
"Could not load/compile rules file: " + rulesFile, e);
}
}
public RulesEngine(String rulesFile, boolean debug)
throws RulesEngineException {
this(rulesFile);
this.debug = debug;
}
public void executeRules(WorkingEnvironmentCallback callback) {
WorkingMemory workingMemory = rules.newStatefulSession();
if (debug) {
workingMemory
.addEventListener(new DebugWorkingMemoryEventListener());
}
callback.initEnvironment(workingMemory);
workingMemory.fireAllRules();
}
}
RulesEngine鏋勯犳柟娉曟紨紺轟簡濡備綍鍘昏鍏ヤ竴涓猺ule鏂囦歡,騫舵瀯寤轟簡涓涓猂uleBase瀵硅薄(RuleBase 鏄竴涓寘鍚簡rule鏂囦歡鐨勬墍鏈夎鍒欑殑闆嗗悎)
executeRules鏂規(guī)硶瀹氫箟浜嗗浣曚嬌鐢ㄨ鍒欐枃浠朵腑瀹氫箟鐨勯偅浜涘唴瀹癸紝鐢≧uleBase鏋勫緩涓涓猈orkingMemory瀵硅薄錛屽啀鎵цfireAllRules()鏂規(guī)硶銆?br /> WorkingMemory 浠h〃浜嗕笌rulebase閾炬帴鐨剆ession浼?xì)璇濆Q屼篃鍙互鐪嬩綔鏄伐浣滃唴瀛樼┖闂淬傚鏋滀綘瑕佸悜鍐呭瓨涓彃鍏ヤ竴涓璞″彲浠ヨ皟鐢╥nsert()鏂規(guī)硶,鍚岀悊錛屾洿鏂頒竴涓璞′嬌鐢╱pdate()鏂規(guī)硶銆俉orkingMemory榪樻湁涓涓猻etGlobal()鏂規(guī)硶錛岀敤鏉ヨ緗鍒欏唴鍙互寮曠敤鐨勫璞?鐩稿綋浜庤鍒欑殑鍏ㄥ眬鍙橀噺)銆?br />
3.灝忔妧宸?/strong>
鍙互涓嬈℃妸鎵鏈夌殑rule鏂囦歡閮借澆鍏ュ唴瀛樹腑瀛樻斁錛岃繖鏍峰氨涓嶇敤姣忔鎵ц閮借鍙栨枃浠躲?br /> 濡傛灉瑙勫垯鏂囦歡琚慨鏀癸紝涔熷彲浠ョ敤榪囦竴涓柟娉曟潵鍒ゆ柇鏄惁闇瑕侀噸鏂拌澆鍏ule鏂囦歡
姣斿錛氭牴鎹枃浠剁殑鏈鍚庝慨鏀規(guī)椂闂達(dá)紝涓庡唴瀛樹腑瀵瑰簲瀵硅薄鐨勬椂闂村仛姣旇緝
public boolean hasChange(List<RuleFile> ruleFileList){
for(RuleFile ruleFile:ruleFileList){
if(!ruleFile.getLastModifyTime().equals(ruleFileMap.get(ruleFile.getFileName()).getLastModifyTime())){
return true;
}
}
return false;
}
娉細(xì)鍏蜂綋鐨刪elloWorld 璇瘋http://www.ibm.com/developerworks/cn/java/j-drools/#listing12錛屾瘮鎴戣寰楀ソ澶氫簡銆?br />
]]>
鍐欏湪鍓嶉潰鐨勮瘽錛歴pring鐨勭洃鍚簨浠舵ā鍨嬪簲璇ユ槸瑙傚療鑰呮ā寮忋傛湰浜洪」鐩噷鐨勫簲鐢ㄥ湪process鏂規(guī)硶鎸夋棩鏈熷悓姝ユ煇涓簱鐨勬暟鎹紝鍦ㄦ柟娉曟渶鍚巔ublish涓涓猠vent浜嬩歡錛岃繖涓簨浠剁敤浜庡悗緇悓姝ヨ繃鏉ョ殑鏁版嵁澶勭悊銆備簨浠跺鐞嗛噰鐢ㄤ簡spring鐨勭洃鍚ā鍨?榪欐牱鍙互鍋氬埌process鏂規(guī)硶涓巈vent鍙互寮傛鍒嗙鎵ц銆傦紙娉細(xì)榪欎釜浜嬩歡妯″瀷緙虹渷浣跨敤SyncTaskExecutor鏉ユ墽琛宭istener鐨勬敞鍐宔vent錛屾墍鏈夎listener娉ㄥ唽鐨別vent浜嬩歡涓?/span>鍚屾鎵ц鐨勶級銆?/p>
褰撶劧錛宻pring鐨勮繖涓満鍒惰繕鏈夊緢澶氬簲鐢ㄧ殑鍦烘櫙錛屽氨涓嶄竴涓鍒椾婦浜嗐?/p>
ApplicationEvent
浜嬩歡鎶借薄綾伙紝閲岄潰鍙湁涓涓瀯閫犲嚱鏁板拰涓涓猼imestamp銆?/p>
ApplicationListener
鐩戝惉鎺ュ彛錛岄噷闈㈠彧鏈変竴涓猳nApplicationEvent鏂規(guī)硶銆傞渶瑕佺敤鎴瘋嚜宸辯紪鍐橝pplicationListener鐨勫疄鐜般?/p>
ApplicationContext
spring涓婁笅鏂?鍏秔ublishEvent鏂規(guī)硶鐢ㄤ簬閫氱煡鐩戝惉鍣?ApplicationListener鐨勫疄鐜?娉ㄥ唽event鏃墮棿.
void publishEvent(ApplicationEvent event)
Notify all listeners registered with this application of an application event.
婧愮爜瑙h錛?br />
1.浣滀負(fù)ApplicationContext鐨勫疄鐜癆bstractApplicationContext.java鐨勬垚鍛樺彉閲?a name="181">applicationListeners錛屾槸涓涓狝rrayList,淇濆瓨浜嗘墍鏈夌殑ApplicationListener
2.鍒╃敤ApplicationEventMulticaster鎺ュ彛閲岀殑鏂規(guī)硶鏉ュ畬鎴愭敞鍐岀洃鍚?a class="r">addApplicationListener,縐婚櫎鐩戝惉removeApplicationListener錛?/a>removeAllListeners錛屼互鍙婇氱煡鐩戝惉娉ㄥ唽浜嬩歡event錛?/a>multicastEvent(ApplicationEvent event);
涓婇潰璇村埌鐨刾ublishEvent鏂規(guī)硶鍗充嬌鐢ㄤ簡multicastEvent鏂規(guī)硶
SimpleApplicationEventMultucaster浣滀負(fù)ApplicationEventMulticaster鐨勪竴涓疄鐜幫紝鎻愪緵浜唌ulticastEvent鐨勫疄鐜頒唬鐮侊紝鍏跺疄灝辨槸榪唬鎵鏈夌殑鐩戝惉鍣紝鐢⊿yncTaskExecutor鍚屾鎵цlistener鐨刼nApplicationEvent
public void multicastEvent(final ApplicationEvent event) {
for (Iterator it = getApplicationListeners().iterator(); it
final ApplicationListener listener = (ApplicationListener) it
getTaskExecutor().execute(new Runnable() {
listener.onApplicationEvent(event);
}
});
}
3.娉ㄦ剰浜嬮」錛氳嚜宸辯紪鍐橝pplicationListener鐨勫疄鐜版椂錛岃娉ㄦ剰涓嶅悓鐨勭洃鍚櫒澶勭悊涓嶅悓鐨勪簨浠訛紙澶嶅啓onApplicationEvent錛夈傚師鍥犲氨鏄?a name="181">multicastEvent鐨勬墽琛屽師鐞嗐傚畠鏄凱浠f墽琛屾墍鏈夌殑鐩戝惉鍣?/a>onApplicationEvent
榪欓噷鏄?/a>ApplicationEventMulticaster鐨勭被鍒嗗竷鍥?/a>
abstract public class AbstractApplicationEventMulticaster implements ApplicationEventMulticaster(Code)(Java Doc)
public interface ApplicationEventMulticaster (Code)(Java Doc)
public class SimpleApplicationEventMulticaster extends
榪欓噷鏄疉pplicationContext鐨勭被鍒嗗竷鍥?br />
public class DefaultResourceLoader implements ResourceLoader(Code)(Java Doc)
public interface ResourceLoader (Code)(Java Doc)
abstract public class AbstractApplicationContext extends
DefaultResourceLoader implements
ConfigurableApplicationContext,DisposableBean(Code)(Java Doc)
public interface ConfigurableApplicationContext extends ApplicationContext,Lifecycle(Code)(Java Doc)
public interface DisposableBean (Code)(Java Doc)
public class GenericApplicationContext extends AbstractApplicationContext implements BeanDefinitionRegistry(Code)(Java Doc)
public interface BeanDefinitionRegistry (Code)(Java Doc)
abstract public class AbstractRefreshableApplicationContext extends
涓嬮潰鏄痵pring鑷韓鐨勪簨浠跺簲鐢?br />
1) ContextRefreshedEvent錛氬綋ApplicationContext鍒濆鍖栨垨鑰呭埛鏂版椂瑙﹀彂璇ヤ簨浠躲?br />
2) ContextClosedEvent錛氬綋ApplicationContext琚叧闂椂瑙﹀彂璇ヤ簨浠躲傚鍣ㄨ鍏抽棴鏃訛紝鍏剁鐞嗙殑鎵鏈夊崟渚婤ean閮借閿姣併?br />
3) RequestHandleEvent錛氬湪Web搴旂敤涓紝褰撲竴涓猦ttp璇鋒眰錛坮equest錛夌粨鏉熻Е鍙戣浜嬩歡銆?br />
4) ContestStartedEvent錛氬綋瀹瑰櫒璋冪敤ConfigurableApplicationContext鐨凷tart()鏂規(guī)硶寮濮?閲嶆柊寮濮嬪鍣ㄦ椂瑙﹀彂璇ヤ簨浠躲?br />
5) ContestStopedEvent錛氬綋瀹瑰櫒璋冪敤ConfigurableApplicationContext鐨凷top()鏂規(guī)硶鍋滄瀹瑰櫒鏃惰Е鍙戣浜嬩歡銆?
1.瀹炰綋map.xml涓厤緗?
涓婚敭鑾峰彇鏂瑰紡閰嶇疆,mysql
<selectKey resultClass="java.lang.Integer" keyProperty="id">
select LAST_INSERT_ID()
</selectKey>
鍔ㄦ佹嫾鎺here鏉′歡
<dynamic prepend="where">
<isNotNull>
plateId=#value#
</isNotNull>
</dynamic>
2.config閰嶇疆
typeAlias 瀹氫箟綾誨瀷鍒悕
<typeAlias alias="Item" type="com.tudou.tudoupromotion.entity.Item"/>
typeHandler 鑷畾涔夌被鍨嬭漿鎹?br />
姣斿錛屽皢鏁版嵁搴撲腑鐨?錛?錛?鏍煎紡鐨勬暟鎹漿鎹負(fù)java 鏋氫婦
<typeHandler
javaType="com.tudou.tudoupromotion.entity.Plate"
callback="com.tudou.tudoupromotion.ext.ibatis.PlateHandler"/>
綰跨▼緙撳瓨絳夐厤緗?/p>
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="false"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="true"
/>
cacheModelsEnabled="true" 鏄惁鍚姩緙撳瓨鏈哄埗
enhancementEnabled="true" 鏄惁閽堝POJO鍚姩瀛楄妭鐮佸寮烘満鍒朵互鎻愬崌getter/setter鐨勮皟鐢ㄦ晥鑳介伩鍏嶄嬌鐢╦avaReflect鎵甯︽潵鐨勬ц兘寮閿銆傚悓鏃禠azy Loading甯︽潵鏋佸ぇ鐨勬ц兘鎻愬崌銆?br />
maxRequests鏈澶у茍鍙戣姹傛暟(Statement鏁?
maxTransactions鏈澶у茍鍙戜簨鍔℃暟
maxSessions鏈澶ession鏁幫紝鍗沖綋鍓嶆渶澶у厑璁哥殑騫跺彂SqlMapCliect鏁癿axSessions璁懼畾蹇呴』鐣屼簬
maxTransactions鍜宮axRequests涔嬮棿.鍗?nbsp;
maxTransactions>maxSessions>maxRequests
鍏堜笅杞絚ouchdb瀹夎鏂囦歡錛氱増鏈負(fù)0.9.1
http://couchdb.apache.org/downloads.html
1寮濮嬪畨瑁呬緷璧栧寘
sudo apt-get build-dep couchdb
sudo apt-get install libmozjs-dev libicu-dev libcurl4-gnutls-dev libtool
2.瑙e帇緙?/p>
tar -zxvf apache-couchdb-0.9.1.tar.gz
3.寮濮嬪畨瑁?/p>
cd apache-couchdb-0.9.1
./configure
make
sudo make install
4.鍚姩couchdb
sudo couchdb
5.璁塊棶:http://127.0.0.1:5984/_utils/
鍚姩鎶ラ敊錛?/p>
$ bin/couchdb
Apache CouchDB 0.9.0a691361-incubating (LogLevel=info) is starting.
{"init terminating in do_boot",{{badmatch,{error,shutdown}},[{couch_server_sup,start_server,1},
{erl_eval,do_apply,5},{erl_eval,exprs,5},{init,start_it,1},{init,start_em,1}]}}
Crash dump was written to: erl_crash.dump
init terminating in do_boot ()
鏌ヤ簡涓涓嬪畼鏂箇iki:
鍘熸潵鏄畨瑁呮枃浠跺す鐨勬潈闄愰棶棰?br />
瑙e喅鍔炴硶錛?br />
sudo adduser couchdb
chown -R couchdb:couchdb /usr/local/etc/couchdb
chown -R couchdb:couchdb /usr/local/var/lib/couchdb
chown -R couchdb:couchdb /usr/local/var/log/couchdb
chown -R couchdb:couchdb /usr/local/var/run
chmod -R 0770 /usr/local/etc/couchdb
chmod -R 0770 /usr/local/var/lib/couchdb
chmod -R 0770 /usr/local/var/log/couchdb
chmod -R 0770 /usr/local/var/run
鍐嶆鍚姩錛岀湅鍒版榪庣晫闈紝鎵鏈夌殑testsuite run success,澶у姛鍛婃垚錛?/pre>
鏂囩珷鏉ユ簮:http://guming.blogbus.com/logs/45898514.html
]]>