锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
#1 Transaction Propagation Behavior
Required:Excute within a current tx, create a new one if none exists.
Supports: Excute within a current tx, execute without a tx if none exsits.
Mandatory: Excute within a current tx, throw an exception if none exists.
Requires New: Create a new tx and excute within the tx, suspend the current tx if one exists.
Not Supported: Excute without a tx, suspend the current tx if none exsits.
Never: Excute without a tx, throw an exception if a tx exsits.
#2 Transaction Isolation Level[1]
#2.1 Concurrent Problem
Dirty Reads: 鑴忚錛堣剰鏁版嵁鎸囧凡鏇存柊錛岃繕娌℃彁浜ょ殑鏁版嵁錛夈備簨鍔1璇誨彇鍒頒簨鍔2涓殑鑴忔暟鎹?/FONT>
Unrepeatable Reads: 涓嶅彲閲嶅璇匯備簨鍔1媯绱㈠埌鏌愯鍚庯紝浜嬪姟T2鏇存柊騫舵彁浜や簡璇ヨ錛岃嫢浜嬪姟T2鍐嶆媯绱㈣琛岋紝鍒欎細鐪嬪埌涓嶄竴鏍風殑緇撴灉銆?/FONT>
Phantom Reads: 铏氳銆備簨鍔1媯绱㈠埌絎﹀悎鏌愭潯浠剁殑琛岄泦鍚庯紝浜嬪姟T2鎻掑叆騫舵彁浜や簡婊¤凍璇ユ潯浠剁殑鏂拌錛岃嫢浜嬪姟T2鍐嶆鎸夎鏉′歡媯绱紝鍒欎細鐪嬪埌浠ュ墠涓嶅瓨鍦ㄧ殑琛屸淧hantom鈥濄?/FONT>
#2.2 Isolation Level
+---------------+-------+------------------+-----------+
|Isolation Level|Phantom|Unrepeatable Reads|Dirty Reads|
+---------------+-------+------------------+-----------+
|Read Uncommited| Y | Y | Y |
+---------------+-------+------------------+-----------+
|Read Commited | Y | Y | N |
+---------------+-------+------------------+-----------+
|Repeatable Read| Y | N | N |
+---------------+-------+------------------+-----------+
|Serializable | N | N | N |
+---------------+-------+------------------+-----------+
#3 Timeout
#4 ReadOnly Transaction
鍙浜嬪姟淇濊瘉浜嗗鏉℃煡璇QL鐨勫湪浜嬪姟綰у埆鐨勮涓鑷存с侸DBC鍜屾暟鎹簱浼氬鍙浜嬪姟鍋氫竴浜涗紭鍖栥?/FONT>
[1] C.J.Date, An Introduction to Database Systems 7th.
#0
MXML浼樼偣錛氫嬌鐢ㄦ柟渚匡紝XML浠g爜綆媧佹槗鎳?BR>緙虹偣錛氫簨浠躲佸嚱鏁般佺晫闈㈡弿娣峰湪涓璧楓傜▼搴忚妯″ぇ浜嗛毦浜庡紑鍙戠淮鎶ゃ?/FONT>
#1
Cairngorm妗嗘灦鏄痠terationtwo鎺ㄥ嚭鐨勫彿縐板熀浜嶫EE Best Practice鐨凢lex紼嬪簭寮鍙戠殑light-weight framework銆?鎭?light-weight榪欎釜璇嶈繕鐪熸槸嫻佽鍛?銆傜洰鍓嶆渶鏂扮増鏈負0.99銆?/FONT>
Cairngorm鐨勭粨鏋勫涓嬶細
org
鈹斺攢nevis
鈹斺攢cairngorm
鈹溾攢application
鈹?nbsp; CairngormApplication.as
鈹?BR> 鈹溾攢business
鈹?nbsp; Responder.as
鈹?nbsp; ServiceLocator.as
鈹?BR> 鈹溾攢commands
鈹?nbsp; Command.as
鈹?nbsp; SequenceCommand.as
鈹?BR> 鈹溾攢control
鈹?nbsp; Event.as
鈹?nbsp; EventBroadcaster.as
鈹?nbsp; FrontController.as
鈹?BR> 鈹溾攢model
鈹?nbsp; ModelLocator.as
鈹?BR> 鈹溾攢view
鈹?nbsp; ViewHelper.as
鈹?nbsp; ViewLocator.as
鈹?BR> 鈹斺攢vo
ValueObject.as
#2
涓嬮潰緇欏ぇ瀹剁畝鍗曚粙緇岰airngorm鐨勫疄鐜版濊礬銆?/FONT>
#2.1
Command/FrontController灝咵vent涓嶸iwe鍒嗙銆?BR>FrontController瀹炵幇Singleton妯″紡(浠ヤ笅綆鍐欎負SP)銆傛墍鏈夎嚜瀹氫箟鐨凜ommand鍦ㄨ鍦‵rontController鏋勯犲嚱鏁頒腑瀹炰緥鍖栧茍浠ュ叧鑱旀暟緇勭殑鏂瑰紡娉ㄥ唽FrontController#addCommand(eventType:String, commandInstance:Command)銆侲ventBroadcaster瀹炵幇SP銆侲vent綾葷殑緇撴瀯涓簕type:eventType, data:eventData}銆傛垜浠氳繃EventBroadcaster#broadcastEvent(eventType:String, eventData:Object)鍙戝竷Event銆侲vent鍙戝竷鍚?涓巈ventType瀵瑰簲鐨刢ommand instance鎵цCommand#execute(event:Event)銆?/FONT>
BTW錛氬湪Cairngorm鐨勬簮鐮佷腑錛宔ventType銆乧ommandName銆乪ventName娣風敤錛屾垜緇熶竴鐢╡ventType銆?/FONT>
#2.2
ServiceLocator灝哛emote Service澹版槑涓嶸iew鍒嗙銆?BR>ServiceLocator瀹炵幇SP銆傚湪Cairngorm鐨刣emo涓紝鍙堥氳繃Delegate瀵硅薄瑙i櫎Command/Responder鍜孲erviceLocator涔嬮棿鐨勪緷璧栥傝繖涓狣elegate鍋氱殑浜嬫儏鍏跺疄鎰忎箟涓嶅ぇ錛屽氨鏄皟鐢⊿erviceLocator涓殑Method錛岃緗帿涓猂esponder涓虹浉搴旇繙紼嬫柟娉曠殑handler銆備釜浜鴻寰楁棤璋撳湴澧炲姞浜嗕唬鐮侀噺錛岃屼笖Delegate瀵硅薄涔熸病瀹炵幇SP錛屼篃灝辨槸璇存垜浠瘡嬈¤皟鐢ㄤ竴嬈emote Service涓殑Method錛岄兘瑕乶ew涓涓狣elegate瀵硅薄錛屽疄鍦ㄦ氮璐廣?/FONT>
#2.3
ViewLocator/ViewHelper灝哣iew錛圡XML錛変腑澶規潅鐨刦unction涓嶸iew鍒嗙銆?BR>ViewHelper鏈夌偣鎰忔濓紝褰撲竴涓猇iewHelper鍦ㄦ煇涓狹XML欏甸潰涓0鏄庢椂錛屽<view:LoginViewHelper id="loginViewHelper" />
#2.4
ModelLocator鏄竴涓猰arker interface錛岀▼搴忎腑Model鍙互鏀懼湪鏌愪釜ModelLocator鏂逛究璋冪敤銆?/FONT>
#2.5
ValueObject涔熸槸涓涓猰arker interface, 鍩烘湰涓嶉渶瑕併?/FONT>
#3
Cairngorm.99緇欐垜浠紑鍙慒lex紼嬪簭鎻愪緵浜嗗緢涓嶉敊鐨勬灦鏋勬ā寮?M/V/C/Remote涔嬮棿鍙互鍋氬埌瀹屽叏瑙f瀯銆備絾鍦ㄥ疄闄呭紑鍙戞椂娌℃湁蹇呰姝繪墸,浠g爜緇撴瀯娓呮櫚鏈夋椿鍔涘氨濂姐?/FONT>
#0
涔﹀拰鏂囨。涓婂啓鐨勯兘涓嶆槸鐗規竻妤氱殑銆傝嚜宸辮涓嬫潵銆?/FONT>
#1 Using a PK association
#1.1 POJO with XDolclet annotation
public class Customer {
/**
* @return Returns the shoppingCart.
* @hibernate.many-to-one cascade="delete" column="shopping_cart_id"
* unique="true" foreign-key="FK_SHOPPING_CART__CUSTOMER"
*/
public ShoppingCart getShoppingCart() {
return shoppingCart;
}
}
public class ShoppingCart {
/**
* @return Returns the customer.
* @hibernate.one-to-one property-ref="shoppingCart"
*/
public Customer getCustomer() {
return customer;
}
}
property-ref="shoppingCart" 鍛婅瘔Hibernate ShoppingCart#customer鍜孋ustomer#shoppingCart鏄弽鍚戠殑鍏崇郴銆傛墍浠ibernate鐭ラ亾濡備綍浠嶴hoppingCart#getCustomer涓绱㈠埌鐩稿簲鐨刢ustomer瀵硅薄銆傚彇鍑烘煇涓狢ustomer瀵硅薄鏃訛紝Hibernate浼氱敓鎴怐EBUG SQL:324 - 3涓殑SQL璇彞銆?/FONT>
#1.2 HBM
Customer.hbm.xml
<many-to-one
name="shoppingCart"
class="ShoppingCart"
cascade="delete"
outer-join="auto"
foreign-key="FK_SHOPPING_CART__CUSTOMER"
column="shopping_cart_id"
/>
ShoppingCart.hbm.xml
<one-to-one
name="customer"
class="Customer"
cascade="none"
outer-join="auto"
constrained="false"
property-ref="shoppingCart"
/>
#1.3 SCHEMA SQL
create table CUSTOMER (
ID bigint generated by default as identity (start with 1),
SHOPPING_CART_ID bigint,
primary key (ID)
)
create table SHOPPING_CART (
ID bigint generated by default as identity (start with 1)
primary key (ID)
)
alter table CUSTOMER
add constraint FK_SHOPPING_CART__CUSTOMER
foreign key (SHOPPING_CART_ID)
references SHOPPING_CART
#1.4 Query SQL
DEBUG SQL:324 - 1
select customer0_.ID as ID, customer0_.SHOPPING_CART_ID as SHOPPING2_3_, customer0_.USERNAME as USERNAME3_, customer0_.PWD as PWD3_
from CUSTOMER customer0_
where customer0_.USERNAME=? and customer0_.PWD=?
DEBUG SQL:324 - 2
select shoppingca0_.ID as ID0_, shoppingca0_.TOTAL as TOTAL8_0_
from SHOPPING_CART shoppingca0_
where shoppingca0_.ID=?
DEBUG SQL:324 - 3
select customer0_.ID as ID1_, customer0_.SHOPPING_CART_ID as SHOPPING2_3_1_, customer0_.USERNAME as USERNAME3_1_, customer0_.PWD as PWD3_1_, shoppingca1_.ID as ID0_, shoppingca1_.TOTAL as TOTAL8_0_
from
CUSTOMER customer0_
left outer join
SHOPPING_CART shoppingca1_
on customer0_.SHOPPING_CART_ID=shoppingca1_.ID
where customer0_.SHOPPING_CART_ID=?
#2 Using a FK association
#2.1 POJO with XDolclet annotation
public class Customer {
/**
* @return Returns the shoppingCart.
* @hibernate.one-to-one cascade="delete"
*/
public ShoppingCart getShoppingCart() {
return shoppingCart;
}
}
public class ShoppingCart {
/**
* @return Returns the id.
* @hibernate.id generator-class="foreign"
* @hibernate.generator-param name="property" value="customer"
*/
public Long getId() {
return id();
}
/**
* @return Returns the customer.
* @hibernate.one-to-one constrained="true" foreign-key="FK_CUSTOMER__SHOPPING_CART"
*/
public Customer getCustomer() {
return customer;
}
}
constrained="true" 鍛婅瘔Hibernate ShoppingCart鐨凱K榪樺簲璇ユ槸涓涓狥K錛岃繖涓狥K寮曠敤Customer鐨凱K銆傝繕闇瑕佸鍋氫竴鐐瑰伐浣滐紝澹版槑ShoppingCart鐨凱K鐢熸垚絳栫暐鏄痜oreign錛屽搴擲hoppingCart#customer銆傝繖鍜屼笂闈竴鍙ヨ瘽涓嶆槸涓涓剰鎬濆槢錛孎T~~
#2.2 HBM
Customer.hbm.xml
<one-to-one
name="shoppingCart"
class="ShoppingCart"
cascade="delete"
outer-join="auto"
constrained="false"
/>
ShoppingCart.hbm.xml
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="foreign">
<param name="property">customer</param>
</generator>
</id>
<one-to-one
name="customer"
class="Customer"
cascade="none"
outer-join="auto"
constrained="true"
/>
#2.3 SCHEMA SQL
create table CUSTOMER (
ID bigint generated by default as identity (start with 1),
primary key (ID)
)
create table SHOPPING_CART (
ID bigint not null,
TOTAL integer,
primary key (ID)
)
alter table SHOPPING_CART
add constraint FK_CUSTOMER__SHOPPING_CART
foreign key (ID)
references CUSTOMER
#2.4 Query SQL
DEBUG SQL:324 -
select customer0_.ID as ID, customer0_.USERNAME as USERNAME3_, customer0_.PWD as PWD3_
from CUSTOMER customer0_
where customer0_.USERNAME=? and customer0_.PWD=?
DEBUG SQL:324 -
select shoppingca0_.ID as ID0_, shoppingca0_.TOTAL as TOTAL8_0_
from SHOPPING_CART shoppingca0_
where shoppingca0_.ID=?
榪欎釜鈥滅湡姝b濈殑one-to-one鐨勫ソ澶勬槸灝戞潯鍏寵仈SQL璇彞錛岀湅鍒頒簡鍚楋紵
Welcome to the ACM "Hello World" project. Everyone has seen the Hello World program used as a first exposure to a new language or environment. We are attempting to collect examples for as many languages and related programming environments (shells etc.) as possible.
Aproximate number of examples:204 <----wow~~~
This page has been accessed 33274 times.
Last updated: January 20, 2005
鐪嬬湅C鐨勶紝緇忓吀HelloWorld
#include <stdio.h>
main()
{
for(;;)
{
printf ("Hello World!\n");
}
}
榪欎篃鏄疕elloWolrd錛燂紒
a 1986 entry from Bruce Holloway:
#include "stdio.h"
#define e 3
#define g (e/e)
#define h ((g+e)/2)
#define f (e-g-h)
#define j (e*e-g)
#define k (j-h)
#define l(x) tab2[x]/h
#define m(n,a) ((n&(a))==(a))
long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };
main(m1,s) char *s; {
int a,b,c,d,o[k],n=(int)s;
if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
else switch(m1-=h){
case f:
a=(b=(c=(d=g)<<g)<'<g)<<g;
return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
case h:
for(a=f;a
return(o[b-g]%n+k-h);
default:
if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
}
}
鏇劇粡鏈鐭殑HelloWorld錛?A href="mailto:Jari.Arkko@lmf.eua.ericsson.se">Jari.Arkko@lmf.eua.ericsson.se錛?BR>jar.1.c
char*_="Hello world.\n";
ln -s /dev/tty jar.1.o
cc -c jar.1.c
鐜板湪鏈鐭殑HelloWorld 錛圝yrki Holopainen錛?BR>";main(){puts("Hello World!");}char*C=".c
char*_=__FILE__;
If we were to execute the following code
Hibernate would issue two SQL statements:
- an INSERT to create the record for c
- an UPDATE to create the link from p to c
Hibernate: insert into PARENT values ( )
Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_ from CHILD children0_ where children0_.MY_PARENT_ID=?
- Hibernate: insert into CHILD (NAME) values (?)
- Hibernate: update CHILD set MY_PARENT_ID=? where CHILD_ID=?
This is not only inefficient, but also violates any NOT NULL constraint on the
MY_PARENT_ID column.
**********1
The underlying cause is that the link (the foreign key parent_id) from p to c is not considered part of the state of the Child object and is therefore not created in the INSERT. So the solution is to make the link part of the Child mapping.
**********1
**********2
Now that the Child entity is managing the state of the link, we tell the collection not to update the link. We use the inverse attribute.
**********2
The following code would be used to add a new Child
And now, only one SQL INSERT would be issued!
To tighten things up a bit, we could create an addChild() method of Parent.
Now, the code to add a Child looks like
=========================================================================================
CONCLUSION:
1.The non-inverse(inverse="false") side is responsible to save the in-memory representation (object) to the database .
--- you should save the child: session.save(c);
2.Changes made only to the inverse end of the association are not persisted.
--- you needn't update the parent: //session.update(p);
Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_, children0_.MY_PARENT_ID as MY_PAREN3_0_ from CHILD children0_ where children0_.MY_PARENT_ID=?
Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_, children0_.MY_PARENT_ID as MY_PAREN3_0_ from CHILD children0_ where children0_.MY_PARENT_ID=?
Hibernate: insert into CHILD (NAME, MY_PARENT_ID) values (?, ?)