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

Make some more fields final where appropriate.

Found by UCDetector, which seems to have gotten smarter recently.
上级 38ed19b9
...@@ -15,16 +15,14 @@ import org.h2.util.StringUtils; ...@@ -15,16 +15,14 @@ import org.h2.util.StringUtils;
*/ */
class RuleElement implements Rule { class RuleElement implements Rule {
private boolean keyword; private final boolean keyword;
private final String name; private final String name;
private Rule link; private Rule link;
private final int type; private final int type;
RuleElement(String name, String topic) { RuleElement(String name, String topic) {
this.name = name; this.name = name;
if (name.length() == 1 || name.equals(StringUtils.toUpperEnglish(name))) { this.keyword = name.length() == 1 || name.equals(StringUtils.toUpperEnglish(name));
keyword = true;
}
topic = StringUtils.toLowerEnglish(topic); topic = StringUtils.toLowerEnglish(topic);
this.type = topic.startsWith("function") ? Sentence.FUNCTION : Sentence.KEYWORD; this.type = topic.startsWith("function") ? Sentence.FUNCTION : Sentence.KEYWORD;
} }
......
...@@ -34,22 +34,22 @@ class FullTextSettings { ...@@ -34,22 +34,22 @@ class FullTextSettings {
/** /**
* The set of words not to index (stop words). * The set of words not to index (stop words).
*/ */
private HashSet<String> ignoreList = New.hashSet(); private final HashSet<String> ignoreList = New.hashSet();
/** /**
* The set of words / terms. * The set of words / terms.
*/ */
private HashMap<String, Integer> words = New.hashMap(); private final HashMap<String, Integer> words = New.hashMap();
/** /**
* The set of indexes in this database. * The set of indexes in this database.
*/ */
private HashMap<Integer, IndexInfo> indexes = New.hashMap(); private final HashMap<Integer, IndexInfo> indexes = New.hashMap();
/** /**
* The prepared statement cache. * The prepared statement cache.
*/ */
private SoftHashMap<Connection, SoftHashMap<String, PreparedStatement>> cache = private final SoftHashMap<Connection, SoftHashMap<String, PreparedStatement>> cache =
new SoftHashMap<Connection, SoftHashMap<String, PreparedStatement>>(); new SoftHashMap<Connection, SoftHashMap<String, PreparedStatement>>();
/** /**
......
...@@ -33,7 +33,7 @@ public class PageBtreeIndex extends PageIndex { ...@@ -33,7 +33,7 @@ public class PageBtreeIndex extends PageIndex {
private final PageStore store; private final PageStore store;
private final RegularTable tableData; private final RegularTable tableData;
private boolean needRebuild; private final boolean needRebuild;
private long rowCount; private long rowCount;
private int memoryPerPage; private int memoryPerPage;
private int memoryCount; private int memoryCount;
...@@ -55,7 +55,6 @@ public class PageBtreeIndex extends PageIndex { ...@@ -55,7 +55,6 @@ public class PageBtreeIndex extends PageIndex {
if (create) { if (create) {
// new index // new index
rootPageId = store.allocatePage(); rootPageId = store.allocatePage();
needRebuild = true;
// TODO currently the head position is stored in the log // TODO currently the head position is stored in the log
// it should not for new tables, otherwise redo of other operations // it should not for new tables, otherwise redo of other operations
// must ensure this page is not used for other things // must ensure this page is not used for other things
...@@ -67,10 +66,8 @@ public class PageBtreeIndex extends PageIndex { ...@@ -67,10 +66,8 @@ public class PageBtreeIndex extends PageIndex {
rootPageId = store.getRootPageId(id); rootPageId = store.getRootPageId(id);
PageBtree root = getPage(rootPageId); PageBtree root = getPage(rootPageId);
rowCount = root.getRowCount(); rowCount = root.getRowCount();
if (rowCount == 0 && store.isRecoveryRunning()) {
needRebuild = true;
}
} }
this.needRebuild = create || (rowCount == 0 && store.isRecoveryRunning());
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
trace.debug("opened {0} rows: {1}", getName() , rowCount); trace.debug("opened {0} rows: {1}", getName() , rowCount);
} }
......
...@@ -34,7 +34,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -34,7 +34,7 @@ public class JdbcStatement extends TraceObject implements Statement {
protected int updateCount; protected int updateCount;
protected final int resultSetType; protected final int resultSetType;
protected final int resultSetConcurrency; protected final int resultSetConcurrency;
protected boolean closedByResultSet; protected final boolean closedByResultSet;
private CommandInterface executingCommand; private CommandInterface executingCommand;
private int lastExecutedCommandType; private int lastExecutedCommandType;
private ArrayList<String> batchCommands; private ArrayList<String> batchCommands;
......
...@@ -45,7 +45,7 @@ public class FileStore { ...@@ -45,7 +45,7 @@ public class FileStore {
* The callback object is responsible to check access rights, and free up * The callback object is responsible to check access rights, and free up
* disk space if required. * disk space if required.
*/ */
private DataHandler handler; private final DataHandler handler;
private FileChannel file; private FileChannel file;
private long filePos; private long filePos;
...@@ -53,7 +53,7 @@ public class FileStore { ...@@ -53,7 +53,7 @@ public class FileStore {
private Reference<?> autoDeleteReference; private Reference<?> autoDeleteReference;
private boolean checkedWriting = true; private boolean checkedWriting = true;
private final String mode; private final String mode;
private TempFileDeleter tempFileDeleter; private final TempFileDeleter tempFileDeleter;
private java.nio.channels.FileLock lock; private java.nio.channels.FileLock lock;
/** /**
...@@ -68,6 +68,8 @@ public class FileStore { ...@@ -68,6 +68,8 @@ public class FileStore {
this.name = name; this.name = name;
if (handler != null) { if (handler != null) {
tempFileDeleter = handler.getTempFileDeleter(); tempFileDeleter = handler.getTempFileDeleter();
} else {
tempFileDeleter = null;
} }
try { try {
boolean exists = FileUtils.exists(name); boolean exists = FileUtils.exists(name);
......
...@@ -21,7 +21,7 @@ public class FileStoreInputStream extends InputStream { ...@@ -21,7 +21,7 @@ public class FileStoreInputStream extends InputStream {
private FileStore store; private FileStore store;
private final Data page; private final Data page;
private int remainingInBuffer; private int remainingInBuffer;
private CompressTool compress; private final CompressTool compress;
private boolean endOfFile; private boolean endOfFile;
private final boolean alwaysClose; private final boolean alwaysClose;
...@@ -30,6 +30,8 @@ public class FileStoreInputStream extends InputStream { ...@@ -30,6 +30,8 @@ public class FileStoreInputStream extends InputStream {
this.alwaysClose = alwaysClose; this.alwaysClose = alwaysClose;
if (compression) { if (compression) {
compress = CompressTool.getInstance(); compress = CompressTool.getInstance();
} else {
compress = null;
} }
page = Data.create(handler, Constants.FILE_BLOCK_SIZE); page = Data.create(handler, Constants.FILE_BLOCK_SIZE);
try { try {
......
...@@ -16,15 +16,18 @@ import org.h2.tools.CompressTool; ...@@ -16,15 +16,18 @@ import org.h2.tools.CompressTool;
public class FileStoreOutputStream extends OutputStream { public class FileStoreOutputStream extends OutputStream {
private FileStore store; private FileStore store;
private final Data page; private final Data page;
private String compressionAlgorithm; private final String compressionAlgorithm;
private CompressTool compress; private final CompressTool compress;
private byte[] buffer = { 0 }; private final byte[] buffer = { 0 };
public FileStoreOutputStream(FileStore store, DataHandler handler, String compressionAlgorithm) { public FileStoreOutputStream(FileStore store, DataHandler handler, String compressionAlgorithm) {
this.store = store; this.store = store;
if (compressionAlgorithm != null) { if (compressionAlgorithm != null) {
compress = CompressTool.getInstance(); this.compress = CompressTool.getInstance();
this.compressionAlgorithm = compressionAlgorithm; this.compressionAlgorithm = compressionAlgorithm;
} else {
this.compress = null;
this.compressionAlgorithm = null;
} }
page = Data.create(handler, Constants.FILE_BLOCK_SIZE); page = Data.create(handler, Constants.FILE_BLOCK_SIZE);
} }
......
...@@ -150,7 +150,7 @@ public class BuildBase { ...@@ -150,7 +150,7 @@ public class BuildBase {
/** /**
* The output stream (System.out). * The output stream (System.out).
*/ */
protected PrintStream sysOut = System.out; protected final PrintStream sysOut = System.out;
/** /**
* If output should be disabled. * If output should be disabled.
......
...@@ -129,7 +129,7 @@ public class MVStore { ...@@ -129,7 +129,7 @@ public class MVStore {
* split in 16 segments. The stack move distance is 2% of the expected * split in 16 segments. The stack move distance is 2% of the expected
* number of entries. * number of entries.
*/ */
private CacheLongKeyLIRS<Page> cache; private final CacheLongKeyLIRS<Page> cache;
private int lastChunkId; private int lastChunkId;
private final HashMap<Integer, Chunk> chunks = New.hashMap(); private final HashMap<Integer, Chunk> chunks = New.hashMap();
...@@ -184,6 +184,8 @@ public class MVStore { ...@@ -184,6 +184,8 @@ public class MVStore {
int mb = s == null ? 16 : Integer.parseInt(s.toString()); int mb = s == null ? 16 : Integer.parseInt(s.toString());
cache = CacheLongKeyLIRS.newInstance( cache = CacheLongKeyLIRS.newInstance(
mb * 1024 * 1024, 2048, 16, mb * 1024 * 1024 / 2048 * 2 / 100); mb * 1024 * 1024, 2048, 16, mb * 1024 * 1024 / 2048 * 2 / 100);
} else {
cache = null;
} }
} }
......
...@@ -35,7 +35,7 @@ public class GenerateModels { ...@@ -35,7 +35,7 @@ public class GenerateModels {
/** /**
* The output stream where this tool writes to. * The output stream where this tool writes to.
*/ */
protected PrintStream out = System.out; protected final PrintStream out = System.out;
public static void main(String... args) throws SQLException { public static void main(String... args) throws SQLException {
new GenerateModels().runTool(args); new GenerateModels().runTool(args);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论