comparison src/main/java/nl/cwi/monetdb/jdbc/MonetSavepoint.java @ 295:003ae6d881db

Add "final" keyword to method arguments and local variables where possible. It discovered some bugs in the MonetStatement constructor (changed the argument instead of object variable) which are fixed now. See also https://en.wikipedia.org/wiki/Final_(Java)
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 01 Aug 2019 20:18:43 +0200 (2019-08-01)
parents 92e882feea95
children c5efd6e661e5
comparison
equal deleted inserted replaced
294:894abb249de1 295:003ae6d881db
7 */ 7 */
8 8
9 package nl.cwi.monetdb.jdbc; 9 package nl.cwi.monetdb.jdbc;
10 10
11 import java.sql.SQLException; 11 import java.sql.SQLException;
12 import java.sql.Savepoint;
13 import java.util.concurrent.atomic.AtomicInteger; 12 import java.util.concurrent.atomic.AtomicInteger;
14 13
15 /** 14 /**
16 * The representation of a savepoint, which is a point within the current 15 * The representation of a savepoint, which is a point within the current
17 * transaction that can be referenced from the Connection.rollback method. 16 * transaction that can be referenced from the Connection.rollback method.
30 * is determined by the server, which makes this a light implementation. 29 * is determined by the server, which makes this a light implementation.
31 * 30 *
32 * @author Fabian Groffen 31 * @author Fabian Groffen
33 * @version 1.0 32 * @version 1.0
34 */ 33 */
35 public final class MonetSavepoint implements Savepoint { 34 public final class MonetSavepoint implements java.sql.Savepoint {
36 /** The id of the last created Savepoint */ 35 /** The id of the last created Savepoint */
37 private static AtomicInteger highestId = new AtomicInteger(0); 36 private static final AtomicInteger highestId = new AtomicInteger(0);
38 37
39 /** The name of this Savepoint */ 38 /** The name of this Savepoint */
40 private final String name; 39 private final String name;
41 /** The id of this Savepoint */ 40 /** The id of this Savepoint */
42 private final int id; 41 private final int id;
43 42
44 /** 43 /**
45 * Creates a named MonetSavepoint object 44 * Creates a named MonetSavepoint object
46 */ 45 */
47 public MonetSavepoint(String name) throws IllegalArgumentException { 46 public MonetSavepoint(final String name) throws IllegalArgumentException {
48 if (name == null || name.isEmpty()) 47 if (name == null || name.isEmpty())
49 throw new IllegalArgumentException("missing savepoint name string"); 48 throw new IllegalArgumentException("missing savepoint name string");
50 49
51 this.id = getNextId(); 50 this.id = getNextId();
52 this.name = name; 51 this.name = name;
98 * difference that this method will always return the id, regardless of 97 * difference that this method will always return the id, regardless of
99 * whether it is named or not. 98 * whether it is named or not.
100 * 99 *
101 * @return the numeric ID of this savepoint 100 * @return the numeric ID of this savepoint
102 */ 101 */
103 int getId() { 102 final int getId() {
104 return id; 103 return id;
105 } 104 }
106 105
107 /** 106 /**
108 * Returns the constructed internal name to use when referencing this save point to the 107 * Returns the constructed internal name to use when referencing this save point to the
109 * MonetDB database. The returned value is guaranteed to be unique and consists of 108 * MonetDB database. The returned value is guaranteed to be unique and consists of
110 * a prefix string and a sequence number. 109 * a prefix string and a sequence number.
111 * 110 *
112 * @return the unique savepoint name 111 * @return the unique savepoint name
113 */ 112 */
114 String getName() { 113 final String getName() {
115 return "MonetDBSP" + id; 114 return "MonetDBSP" + id;
116 } 115 }
117 116
118 117
119 /** 118 /**
124 * difference of 1. 123 * difference of 1.
125 * 124 *
126 * @return the next int which is guaranteed to be higher than the one 125 * @return the next int which is guaranteed to be higher than the one
127 * at the last call to this method. 126 * at the last call to this method.
128 */ 127 */
129 private static int getNextId() { 128 private static final int getNextId() {
130 return highestId.incrementAndGet(); 129 return highestId.incrementAndGet();
131 } 130 }
132 131
133 /** 132 /**
134 * Returns the highest id returned by getNextId(). This method is also 133 * Returns the highest id returned by getNextId(). This method is also