Skip to content

Commit f24132c

Browse files
authored
Merge pull request #7 from nmalygin-com/ci-test
improve isolation levels
2 parents f788a84 + 2d5f46b commit f24132c

File tree

12 files changed

+266
-27
lines changed

12 files changed

+266
-27
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ List<String> titles = queries
6666

6767
```java
6868
List<String> titles = queries
69-
.query("SELECT title FROM books WHERE title LIKE ?",
70-
new StringArgument("Clean%"))
69+
.query("SELECT title FROM books WHERE title = ? OR title = ?",
70+
new StringArgument("Clean Code"),
71+
new StringArgument("Code Complete"))
7172
.executeWith(new ColumnToListRsh<>(new StringColumn("title")));
7273
```
7374

@@ -82,10 +83,9 @@ define the query and then set the parameter values).
8283
#### Building a query
8384

8485
```java
85-
Query titlesQuery = queries.query("SELECT title FROM books ");
86-
titlesQuery.append("WHERE title LIKE ? ", new StringArgument("Clean%"));
87-
titlesQuery.append("LIMIT ?", new IntArgument(10));
88-
List<String> titles = titlesQuery
86+
List<String> titles = queries.query("SELECT title FROM books ")
87+
.append("WHERE title LIKE ? ", new StringArgument("Clean%"))
88+
.append("LIMIT ?", new IntArgument(10))
8989
.executeWith(new ColumnToListRsh<>(new StringColumn("title")));
9090
```
9191

@@ -177,7 +177,7 @@ try (Transaction transaction = transactions.transaction()) {
177177
#### Setting the transaction isolation level
178178

179179
```java
180-
try (Transaction transaction = transactions.transaction(1)) {
180+
try (Transaction transaction = transactions.transaction(new ReadCommitted())) {
181181
// some code
182182
}
183183
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SOFTWARE.
2929

3030
<groupId>com.nmalygin</groupId>
3131
<artifactId>superb-jdbc</artifactId>
32-
<version>0.0.5-SNAPSHOT</version>
32+
<version>0.0.5</version>
3333
<packaging>jar</packaging>
3434

3535
<name>Superb JDBC</name>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Nikolai Malygin
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.nmalygin.superb.jdbc.api;
26+
27+
import java.sql.Connection;
28+
import java.sql.SQLException;
29+
30+
/**
31+
* Represents an isolation level of a transaction.
32+
*
33+
* @author Nikolai Malygin
34+
*/
35+
public interface IsolationLevel {
36+
37+
/**
38+
* Apply the isolation level for the connection.
39+
*
40+
* @param connection JDBC Connection
41+
* @throws SQLException SQLException
42+
*/
43+
void applyTo(Connection connection) throws SQLException;
44+
}

src/main/java/com/nmalygin/superb/jdbc/api/Transactions.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,9 @@ public interface Transactions {
3939
Transaction transaction() throws SQLException;
4040

4141
/**
42-
*
4342
* @param isolationLevel the transaction isolation level.
44-
* Level one of the following {@code Connection} constants:
45-
* {@code Connection.TRANSACTION_READ_UNCOMMITTED},
46-
* {@code Connection.TRANSACTION_READ_COMMITTED},
47-
* {@code Connection.TRANSACTION_REPEATABLE_READ}, or
48-
* {@code Connection.TRANSACTION_SERIALIZABLE}.
4943
* @return New transaction with the isolationLevel
5044
* @throws SQLException SQLException
5145
*/
52-
Transaction transaction(int isolationLevel) throws SQLException;
46+
Transaction transaction(IsolationLevel isolationLevel) throws SQLException;
5347
}

src/main/java/com/nmalygin/superb/jdbc/api/handlers/ColumnToListRsh.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
* @author Nikolai Malygin
3939
*/
40-
public class ColumnToListRsh<T> implements ResultSetHandler<List<T>> {
40+
public final class ColumnToListRsh<T> implements ResultSetHandler<List<T>> {
4141

4242
private final Column<T> column;
4343

src/main/java/com/nmalygin/superb/jdbc/api/handlers/columns/StringColumn.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* @author Nikolai Malygin
3434
*/
35-
public class StringColumn implements Column<String> {
35+
public final class StringColumn implements Column<String> {
3636

3737
private final String name;
3838

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Nikolai Malygin
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.nmalygin.superb.jdbc.api.isolation;
26+
27+
import com.nmalygin.superb.jdbc.api.IsolationLevel;
28+
29+
import java.sql.Connection;
30+
import java.sql.SQLException;
31+
32+
/**
33+
* The read committed isolation level
34+
*
35+
* @author Nikolai Malygin
36+
*/
37+
@SuppressWarnings("PMD.AtLeastOneConstructor")
38+
public final class ReadCommitted implements IsolationLevel {
39+
40+
/**
41+
* Apply the isolation level for the connection.
42+
*
43+
* @param connection JDBC Connection
44+
* @throws SQLException SQLException
45+
*/
46+
@Override
47+
public void applyTo(final Connection connection) throws SQLException {
48+
connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Nikolai Malygin
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.nmalygin.superb.jdbc.api.isolation;
26+
27+
import com.nmalygin.superb.jdbc.api.IsolationLevel;
28+
29+
import java.sql.Connection;
30+
import java.sql.SQLException;
31+
32+
/**
33+
* The read uncommitted isolation level
34+
*
35+
* @author Nikolai Malygin
36+
*/
37+
@SuppressWarnings("PMD.AtLeastOneConstructor")
38+
public final class ReadUncommitted implements IsolationLevel {
39+
40+
/**
41+
* Apply the isolation level for the connection.
42+
*
43+
* @param connection JDBC Connection
44+
* @throws SQLException SQLException
45+
*/
46+
@Override
47+
public void applyTo(final Connection connection) throws SQLException {
48+
connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Nikolai Malygin
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.nmalygin.superb.jdbc.api.isolation;
26+
27+
import com.nmalygin.superb.jdbc.api.IsolationLevel;
28+
29+
import java.sql.Connection;
30+
import java.sql.SQLException;
31+
32+
/**
33+
* The repeatable read isolation level
34+
*
35+
* @author Nikolai Malygin
36+
*/
37+
@SuppressWarnings("PMD.AtLeastOneConstructor")
38+
public final class RepeatableRead implements IsolationLevel {
39+
40+
/**
41+
* Apply the isolation level for the connection.
42+
*
43+
* @param connection JDBC Connection
44+
* @throws SQLException SQLException
45+
*/
46+
@Override
47+
public void applyTo(final Connection connection) throws SQLException {
48+
connection.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Nikolai Malygin
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.nmalygin.superb.jdbc.api.isolation;
26+
27+
import com.nmalygin.superb.jdbc.api.IsolationLevel;
28+
29+
import java.sql.Connection;
30+
import java.sql.SQLException;
31+
32+
/**
33+
* The serializable isolation level
34+
*
35+
* @author Nikolai Malygin
36+
*/
37+
@SuppressWarnings("PMD.AtLeastOneConstructor")
38+
public final class Serializable implements IsolationLevel {
39+
40+
/**
41+
* Apply the isolation level for the connection.
42+
*
43+
* @param connection JDBC Connection
44+
* @throws SQLException SQLException
45+
*/
46+
@Override
47+
public void applyTo(final Connection connection) throws SQLException {
48+
connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
49+
}
50+
}

0 commit comments

Comments
 (0)