增加悲观锁选项

This commit is contained in:
sunsc 2015-06-30 16:45:12 +08:00
parent 632a86f56a
commit f549b458b8
2 changed files with 10 additions and 7 deletions

View File

@ -29,6 +29,7 @@ type Session struct {
IsCommitedOrRollbacked bool
TransType string
IsAutoClose bool
LockRead bool //set sad lock for accepting ro read dirty data
// Automatically reset the statement after operations that execute a SQL
// query such as Count(), Find(), Get(), ...
@ -1001,6 +1002,10 @@ func (session *Session) Get(bean interface{}) (bool, error) {
if session.Statement.RawSQL == "" {
sqlStr, args = session.Statement.genGetSql(bean)
//加入悲观锁 FOR oracle & pg & mysql
if session.LockRead {
sqlStr += " FOR UPDATE "
}
} else {
sqlStr = session.Statement.RawSQL
args = session.Statement.RawParams

View File

@ -1241,8 +1241,6 @@ func (statement *Statement) genSelectSql(columnStr string) string {
a = fmt.Sprintf("SELECT %v FROM (SELECT %v,ROWNUM RN FROM (%v) at WHERE ROWNUM <= %d) aat WHERE RN > %d", columnStr, columnStr, a, statement.Start+statement.LimitN, statement.Start)
}
}
//在事务中强制性加入排他锁,不开事务则不起作用 FOR oracle & pg & mysql
a += " FOR UPDATE "
return a
}