Mercurial > gemma
annotate pkg/imports/misc.go @ 2660:2b4b9fa9812c
Simplified code.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 14 Mar 2019 18:26:00 +0100 |
parents | 00b0a7b2225a |
children | 542d3441c2d8 |
rev | line source |
---|---|
1785
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
1 // SPDX-License-Identifier: AGPL-3.0-or-later |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
2 // License-Filename: LICENSES/AGPL-3.0.txt |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 // Copyright (C) 2018 by via donau |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
5 // – Österreichische Wasserstraßen-Gesellschaft mbH |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 // Software engineering by Intevation GmbH |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 // |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 // Author(s): |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 package imports |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
12 |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
13 import ( |
2659
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
14 "context" |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
15 "database/sql" |
1785
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 "fmt" |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 "strings" |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
18 ) |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 type stringCounter map[string]int |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
22 func (sc stringCounter) String() string { |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
23 var b strings.Builder |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
24 for t, c := range sc { |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
25 if b.Len() > 0 { |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
26 b.WriteString(", ") |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
27 } |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
28 b.WriteString(fmt.Sprintf("%s: %d", t, c)) |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
29 } |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 return b.String() |
614c6c766691
Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 } |
2659
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
32 |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
33 func Savepoint( |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
34 tx *sql.Tx, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
35 ctx context.Context, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
36 name string, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
37 ) error { |
2660
2b4b9fa9812c
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2659
diff
changeset
|
38 _, err := tx.ExecContext(ctx, "SAVEPOINT "+name) |
2b4b9fa9812c
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2659
diff
changeset
|
39 return err |
2659
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
40 } |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
41 |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
42 func RollbackToSavepoint( |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
43 tx *sql.Tx, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
44 ctx context.Context, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
45 name string, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
46 ) error { |
2660
2b4b9fa9812c
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2659
diff
changeset
|
47 _, err := tx.ExecContext(ctx, "ROLLBACK TO SAVEPOINT "+name) |
2b4b9fa9812c
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2659
diff
changeset
|
48 return err |
2659
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
49 } |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
50 |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
51 func ReleaseSavepoint( |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
52 tx *sql.Tx, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
53 ctx context.Context, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
54 name string, |
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
55 ) error { |
2660
2b4b9fa9812c
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2659
diff
changeset
|
56 _, err := tx.ExecContext(ctx, "RELEASE SAVEPOINT "+name) |
2b4b9fa9812c
Simplified code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2659
diff
changeset
|
57 return err |
2659
00b0a7b2225a
Waterway area import: do not fail if INSERT of one item fails
Tom Gottfried <tom@intevation.de>
parents:
1785
diff
changeset
|
58 } |