MCPcopy Create free account
hub / github.com/apache/devlake / LockTables

Method LockTables

backend/impls/dalgorm/dalgorm_transaction.go:53–88  ·  view source on GitHub ↗
(lockTables dal.LockTables)

Source from the content-addressed store, hash-verified

51}
52
53func (t *DalgormTransaction) LockTables(lockTables dal.LockTables) errors.Error {
54 switch t.Dialect() {
55 case "mysql":
56 // mysql lock all tables at once, each lock would release all previous locks
57 clause := ""
58 for _, lockTable := range lockTables {
59 if clause != "" {
60 clause += ", "
61 }
62 clause += lockTable.TableName()
63 if lockTable.Exclusive {
64 clause += " WRITE"
65 } else {
66 clause += " READ"
67 }
68 }
69 return t.Exec(fmt.Sprintf("LOCK TABLES %s", clause))
70 case "postgres":
71 for _, lockTable := range lockTables {
72 var clause string
73 if lockTable.Exclusive {
74 clause = "EXCLUSIVE"
75 } else {
76 clause = "SHARE"
77 }
78 stmt := fmt.Sprintf("LOCK TABLE %s IN %s MODE;", lockTable.TableName(), clause)
79 err := t.Exec(stmt)
80 if err != nil {
81 return err
82 }
83 }
84 return nil
85 default:
86 panic(fmt.Errorf("unknown dialect %s", t.Dialect()))
87 }
88}
89
90func (t *DalgormTransaction) UnlockTables() errors.Error {
91 switch t.Dialect() {

Callers

nothing calls this directly

Calls 3

DialectMethod · 0.65
TableNameMethod · 0.65
ExecMethod · 0.65

Tested by

no test coverage detected