提交 f2afe926 authored 作者: noelgrandin's avatar noelgrandin

Make fields final where appropriate.

Found by UCDetector, which seems to have gotten smarter recently.
上级 e5692ca7
......@@ -30,9 +30,9 @@ import org.h2.value.ValueBoolean;
public class ExpressionColumn extends Expression {
private final Database database;
private String schemaName;
private String tableAlias;
private String columnName;
private final String schemaName;
private final String tableAlias;
private final String columnName;
private ColumnResolver columnResolver;
private int queryLevel;
private Column column;
......@@ -41,6 +41,9 @@ public class ExpressionColumn extends Expression {
public ExpressionColumn(Database database, Column column) {
this.database = database;
this.column = column;
this.schemaName = null;
this.tableAlias = null;
this.columnName = null;
}
public ExpressionColumn(Database database, String schemaName, String tableAlias, String columnName) {
......
......@@ -20,7 +20,7 @@ import org.h2.value.ValueArray;
*/
public class ExpressionList extends Expression {
private Expression[] list;
private final Expression[] list;
public ExpressionList(Expression[] list) {
this.list = list;
......
......@@ -30,7 +30,7 @@ public class JavaAggregate extends Expression {
private final UserAggregate userAggregate;
private final Select select;
private Expression[] args;
private final Expression[] args;
private int[] argTypes;
private int dataType;
private Connection userConnection;
......
......@@ -26,7 +26,7 @@ public class JavaFunction extends Expression implements FunctionCall {
private final FunctionAlias functionAlias;
private final FunctionAlias.JavaMethod javaMethod;
private Expression[] args;
private final Expression[] args;
public JavaFunction(FunctionAlias functionAlias, Expression[] args) {
this.functionAlias = functionAlias;
......
......@@ -73,7 +73,7 @@ public abstract class PageBtree extends Page {
/**
* The estimated memory used by this object.
*/
private int memoryEstimated;
private final int memoryEstimated;
PageBtree(PageBtreeIndex index, int pageId, Data data) {
this.index = index;
......
......@@ -65,7 +65,7 @@ abstract class PageData extends Page {
* The estimated heap memory used by this object, in number of double words
* (4 bytes each).
*/
private int memoryEstimated;
private final int memoryEstimated;
PageData(PageDataIndex index, int pageId, Data data) {
this.index = index;
......
......@@ -42,7 +42,7 @@ public class PageDataIndex extends PageIndex {
private long rowCount;
private HashSet<Row> delta;
private int rowCountDiff;
private HashMap<Integer, Integer> sessionRowCount;
private final HashMap<Integer, Integer> sessionRowCount;
private int mainIndexColumn = -1;
private DbException fastDuplicateKeyException;
......@@ -65,6 +65,8 @@ public class PageDataIndex extends PageIndex {
if (multiVersion) {
sessionRowCount = New.hashMap();
isMultiVersion = true;
} else {
sessionRowCount = null;
}
tableData = table;
this.store = database.getPageStore();
......
......@@ -35,7 +35,7 @@ public class ScanIndex extends BaseIndex {
private ArrayList<Row> rows = New.arrayList();
private final RegularTable tableData;
private int rowCountDiff;
private HashMap<Integer, Integer> sessionRowCount;
private final HashMap<Integer, Integer> sessionRowCount;
private HashSet<Row> delta;
private long rowCount;
......@@ -43,6 +43,8 @@ public class ScanIndex extends BaseIndex {
initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType);
if (database.isMultiVersion()) {
sessionRowCount = New.hashMap();
} else {
sessionRowCount = null;
}
tableData = table;
}
......
......@@ -36,7 +36,7 @@ class TreeNode {
/**
* The row.
*/
Row row;
final Row row;
TreeNode(Row row) {
this.row = row;
......
......@@ -41,10 +41,10 @@ public class ViewIndex extends BaseIndex {
private final SmallLRUCache<IntArray, CostElement> costCache =
SmallLRUCache.newInstance(Constants.VIEW_INDEX_CACHE_SIZE);
private boolean recursive;
private int[] indexMasks;
private final int[] indexMasks;
private String planSQL;
private Query query;
private Session createSession;
private final Session createSession;
public ViewIndex(TableView view, String querySQL, ArrayList<Parameter> originalParameters, boolean recursive) {
initBaseIndex(view, 0, null, null, IndexType.createNonUnique(false));
......@@ -53,6 +53,8 @@ public class ViewIndex extends BaseIndex {
this.originalParameters = originalParameters;
this.recursive = recursive;
columns = new Column[0];
this.createSession = null;
this.indexMasks = null;
}
public ViewIndex(TableView view, ViewIndex index, Session session, int[] masks) {
......
......@@ -67,8 +67,8 @@ public class JdbcConnection extends TraceObject implements Connection {
private static boolean keepOpenStackTrace;
private String url;
private String user;
private final String url;
private final String user;
// ResultSet.HOLD_CURSORS_OVER_COMMIT
private int holdability = 1;
......@@ -83,7 +83,7 @@ public class JdbcConnection extends TraceObject implements Connection {
private String catalog;
private Statement executingStatement;
private final CompareMode compareMode = CompareMode.getInstance(null, 0);
private CloseWatcher watcher;
private final CloseWatcher watcher;
private int queryTimeoutCache = -1;
/**
......@@ -141,6 +141,7 @@ public class JdbcConnection extends TraceObject implements Connection {
this.getQueryTimeout = clone.getQueryTimeout;
this.getReadOnly = clone.getReadOnly;
this.rollback = clone.rollback;
this.watcher = null;
}
/**
......@@ -153,6 +154,7 @@ public class JdbcConnection extends TraceObject implements Connection {
setTrace(trace, TraceObject.CONNECTION, id);
this.user = user;
this.url = url;
this.watcher = null;
}
private void closeOld() {
......
......@@ -20,9 +20,9 @@ public class JdbcXid extends TraceObject implements Xid {
private static final String PREFIX = "XID";
private int formatId;
private byte[] branchQualifier;
private byte[] globalTransactionId;
private final int formatId;
private final byte[] branchQualifier;
private final byte[] globalTransactionId;
JdbcXid(JdbcDataSourceFactory factory, int id, String tid) {
setTrace(factory.getTrace(), TraceObject.XID, id);
......
......@@ -18,52 +18,52 @@ public class ResultColumn {
/**
* The column alias.
*/
String alias;
final String alias;
/**
* The schema name or null.
*/
String schemaName;
final String schemaName;
/**
* The table name or null.
*/
String tableName;
final String tableName;
/**
* The column name or null.
*/
String columnName;
final String columnName;
/**
* The value type of this column.
*/
int columnType;
final int columnType;
/**
* The precision.
*/
long precision;
final long precision;
/**
* The scale.
*/
int scale;
final int scale;
/**
* The expected display size.
*/
int displaySize;
final int displaySize;
/**
* True if this is an autoincrement column.
*/
boolean autoIncrement;
final boolean autoIncrement;
/**
* True if this column is nullable.
*/
int nullable;
final int nullable;
/**
* Read an object from the given transfer object.
......
......@@ -28,7 +28,8 @@ public class RowList {
private FileStore file;
private Data rowBuff;
private ArrayList<Value> lobs;
private int memory, maxMemory;
private final int maxMemory;
private int memory;
private boolean written;
private boolean readUncached;
......@@ -41,6 +42,8 @@ public class RowList {
this.session = session;
if (session.getDatabase().isPersistent()) {
maxMemory = session.getDatabase().getMaxOperationMemory();
} else {
maxMemory = 0;
}
}
......
......@@ -17,7 +17,7 @@ public class SimpleRow implements SearchRow {
private long key;
private int version;
private Value[] data;
private final Value[] data;
private int memory;
public SimpleRow(Value[] data) {
......
......@@ -26,8 +26,8 @@ public class AES implements BlockCipher {
private static final int[] RT1 = new int[256];
private static final int[] RT2 = new int[256];
private static final int[] RT3 = new int[256];
private int[] encKey = new int[44];
private int[] decKey = new int[44];
private final int[] encKey = new int[44];
private final int[] decKey = new int[44];
private static int rot8(int x) {
return (x >>> 8) | (x << 24);
......
......@@ -44,7 +44,7 @@ import org.h2.value.ValueLobDb;
*/
public class TcpServerThread implements Runnable {
protected Transfer transfer;
protected final Transfer transfer;
private final TcpServer server;
private Session session;
private boolean stop;
......
......@@ -19,18 +19,18 @@ class DbColumn {
/**
* The column name.
*/
String name;
final String name;
/**
* The quoted table name.
*/
String quotedName;
final String quotedName;
/**
* The data type name (including precision and the NOT NULL flag if
* applicable).
*/
String dataType;
final String dataType;
DbColumn(DbContents contents, ResultSet rs) throws SQLException {
name = rs.getString("COLUMN_NAME");
......
......@@ -21,22 +21,22 @@ public class DbTableOrView {
/**
* The schema this table belongs to.
*/
DbSchema schema;
final DbSchema schema;
/**
* The table name.
*/
String name;
final String name;
/**
* The quoted table name.
*/
String quotedName;
final String quotedName;
/**
* True if this represents a view.
*/
boolean isView;
final boolean isView;
/**
* The column list.
......
......@@ -69,7 +69,7 @@ public class WebApp {
/**
* The web server.
*/
protected WebServer server;
protected final WebServer server;
/**
* The session.
......
......@@ -36,7 +36,7 @@ class WebSession {
/**
* The session attribute map.
*/
HashMap<String, Object> map = New.hashMap();
final HashMap<String, Object> map = New.hashMap();
/**
* The current locale.
......
......@@ -35,7 +35,7 @@ import org.h2.util.Utils;
class WebThread extends WebApp implements Runnable {
protected OutputStream output;
protected Socket socket;
protected final Socket socket;
private final Thread thread;
private InputStream input;
private int headerBytes;
......
......@@ -106,7 +106,7 @@ public class MetaTable extends Table {
private final int type;
private final int indexColumn;
private MetaIndex metaIndex;
private final MetaIndex metaIndex;
/**
* Create a new metadata table.
......@@ -515,6 +515,7 @@ public class MetaTable extends Table {
if (indexColumnName == null) {
indexColumn = -1;
metaIndex = null;
} else {
indexColumn = getColumn(indexColumnName).getColumnId();
IndexColumn[] indexCols = IndexColumn.wrap(new Column[] { cols[indexColumn] });
......
......@@ -58,7 +58,7 @@ public class RegularTable extends TableBase {
private final ArrayList<Index> indexes = New.arrayList();
private long lastModificationId;
private boolean containsLargeObject;
private PageDataIndex mainIndex;
private final PageDataIndex mainIndex;
private int changesSinceAnalyze;
private int nextAnalyze;
private Column rowIdColumn;
......@@ -86,6 +86,7 @@ public class RegularTable extends TableBase {
data.create, data.session);
scanIndex = mainIndex;
} else {
mainIndex = null;
scanIndex = new ScanIndex(this, data.id, IndexColumn.wrap(getColumns()), IndexType.createScan(data.persistData));
}
indexes.add(scanIndex);
......
......@@ -107,7 +107,7 @@ public class Recover extends Tool implements DataHandler {
/**
* The count per page type.
*/
int[] pageTypeCount = new int[Page.TYPE_STREAM_DATA + 2];
final int[] pageTypeCount = new int[Page.TYPE_STREAM_DATA + 2];
/**
* The number of free pages.
......
......@@ -28,13 +28,14 @@ import org.h2.util.Utils;
*/
public class Server extends Tool implements Runnable, ShutdownHandler {
private Service service;
private final Service service;
private Server web, tcp, pg;
private ShutdownHandler shutdownHandler;
private boolean started;
public Server() {
// nothing to do
this.service = null;
}
/**
......
......@@ -26,7 +26,7 @@ import org.h2.util.Utils;
*/
public class DbUpgrade {
private static boolean upgradeClassesPresent;
private static final boolean upgradeClassesPresent;
private static boolean scriptInTempDir;
private static boolean deleteOldDb;
......
......@@ -33,9 +33,9 @@ import org.h2.message.DbException;
public class Permutations<T> {
private final T[] in;
private T[] out;
private final T[] out;
private final int n, m;
private int[] index;
private final int[] index;
private boolean hasNext = true;
private Permutations(T[] in, T[] out, int m) {
......
......@@ -33,12 +33,12 @@ public class SourceCompiler {
/**
* The class name to source code map.
*/
HashMap<String, String> sources = New.hashMap();
final HashMap<String, String> sources = New.hashMap();
/**
* The class name to byte code map.
*/
HashMap<String, Class<?>> compiled = New.hashMap();
final HashMap<String, Class<?>> compiled = New.hashMap();
private final String compileDir = Utils.getProperty("java.io.tmpdir", ".");
......
......@@ -36,15 +36,17 @@ public class CompareMode {
private static CompareMode lastUsed;
private static boolean canUseICU4J;
private static final boolean canUseICU4J;
static {
boolean b = false;
try {
Class.forName("com.ibm.icu.text.Collator");
canUseICU4J = true;
b = true;
} catch (Exception e) {
// ignore
}
canUseICU4J = b;
}
private final String name;
......
......@@ -38,8 +38,8 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
private int hash;
private LobStorage lobStorage;
private long lobId;
private byte[] hmac;
private final long lobId;
private final byte[] hmac;
private byte[] small;
......@@ -60,6 +60,8 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
this.type = type;
this.small = small;
this.precision = precision;
this.lobId = 0;
this.hmac = null;
}
/**
......
......@@ -14,8 +14,8 @@ import java.util.HashMap;
*/
public class HtmlConverter {
private static HashMap<String, Character> charMap = new HashMap<String, Character>();
private static HashMap<Character, String> codeMap = new HashMap<Character, String>();
private static final HashMap<String, Character> charMap = new HashMap<String, Character>();
private static final HashMap<Character, String> codeMap = new HashMap<Character, String>();
private static final String[] CHARS = { "quot:34", "amp:38", "lt:60", "gt:62", "nbsp:160", "iexcl:161", "cent:162",
"pound:163", "curren:164", "yen:165", "brvbar:166", "sect:167", "uml:168", "copy:169", "ordf:170",
......
......@@ -19,7 +19,7 @@ public class Page {
/**
* The file name.
*/
String fileName;
final String fileName;
/**
* The title of the page.
......
......@@ -25,7 +25,7 @@ public class Word {
/**
* The pages map.
*/
HashMap<Page, Weight> pages = new HashMap<Page, Weight>();
final HashMap<Page, Weight> pages = new HashMap<Page, Weight>();
private ArrayList<Weight> weightList;
......
......@@ -24,20 +24,22 @@ public class FtpData extends Thread {
private final InetAddress address;
private ServerSocket serverSocket;
private volatile Socket socket;
private boolean active;
private int port;
private final boolean active;
private final int port;
FtpData(FtpServer server, InetAddress address, ServerSocket serverSocket) {
this.server = server;
this.address = address;
this.serverSocket = serverSocket;
this.port = 0;
this.active = false;
}
FtpData(FtpServer server, InetAddress address, int port) {
this.server = server;
this.address = address;
this.port = port;
active = true;
this.active = true;
}
public void run() {
......
......@@ -29,7 +29,7 @@ public class Chunk {
/**
* The chunk id.
*/
int id;
final int id;
/**
* The start position within the file.
......
......@@ -14,7 +14,7 @@ public class CursorPos {
/**
* The current page.
*/
public Page page;
public final Page page;
/**
* The current index.
......@@ -24,7 +24,7 @@ public class CursorPos {
/**
* The position in the parent page, if any.
*/
public CursorPos parent;
public final CursorPos parent;
public CursorPos(Page page, int index, CursorPos parent) {
this.page = page;
......
......@@ -14,7 +14,7 @@ import org.h2.util.New;
*/
public class MVStoreBuilder {
private HashMap<String, Object> config = New.hashMap();
private final HashMap<String, Object> config = New.hashMap();
/**
* Use the following file name. If the file does not exist, it is
......
......@@ -272,12 +272,12 @@ public class StreamStore {
*/
static class Stream extends InputStream {
private StreamStore store;
private final StreamStore store;
private byte[] oneByteBuffer;
private ByteBuffer idBuffer;
private ByteArrayInputStream buffer;
private long skip;
private long length;
private final long length;
private long pos;
Stream(StreamStore store, byte[] id) {
......
......@@ -55,7 +55,7 @@ class Operation implements Token {
DIVIDE("/"),
MOD("%");
private String name;
private final String name;
Type(String name) {
this.name = name;
......
......@@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicLong;
public class StatementLogger {
public static boolean logStatements;
private static PrintWriter out = new PrintWriter(System.out);
private static final PrintWriter out = new PrintWriter(System.out);
private static final AtomicLong SELECT_COUNT = new AtomicLong();
private static final AtomicLong CREATE_COUNT = new AtomicLong();
private static final AtomicLong INSERT_COUNT = new AtomicLong();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论