提交 91926786 authored 作者: Thomas Mueller's avatar Thomas Mueller

Formatting / javadocs

上级 d95318e6
......@@ -4718,7 +4718,7 @@ public class Parser {
}
throw DbException.getInvalidValueException("BINARY_COLLATION", name);
}
private RunScriptCommand parseRunScript() {
RunScriptCommand command = new RunScriptCommand(session);
read("FROM");
......
......@@ -1273,8 +1273,8 @@ public class Select extends Query {
return false;
}
public SortOrder prepareOrder() {
public SortOrder getSortOrder() {
return sort;
}
}
......@@ -203,7 +203,7 @@ public class SetTypes {
* The type of a SET BINARY_COLLATION statement.
*/
public static final int BINARY_COLLATION = 38;
private static final ArrayList<String> TYPES = New.arrayList();
private SetTypes() {
......
......@@ -112,12 +112,12 @@ public class Mode {
* The function LOG() uses base 10 instead of E.
*/
public boolean logIsLogBase10;
/**
* SERIAL and BIGSERIAL columns are not automatically primary keys.
*/
public boolean serialColumnIsNotPK;
/**
* Swap the parameters of the CONVERT function.
*/
......
......@@ -242,7 +242,7 @@ public class Function extends Expression implements FunctionCall {
// 2 or 3 arguments
addFunction("LOCATE", LOCATE, VAR_ARGS, Value.INT);
// alias for MSSQLServer
addFunction("CHARINDEX", LOCATE, VAR_ARGS, Value.INT);
addFunction("CHARINDEX", LOCATE, VAR_ARGS, Value.INT);
// same as LOCATE with 2 arguments
addFunction("POSITION", LOCATE, 2, Value.INT);
addFunction("INSTR", INSTR, VAR_ARGS, Value.INT);
......
......@@ -124,6 +124,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
*
* @param masks the search mask
* @param rowCount the number of rows in the index
* @param sortOrder the sort order
* @return the estimated cost
*/
protected long getCostRangeIndex(int[] masks, long rowCount, SortOrder sortOrder) {
......@@ -163,8 +164,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
break;
}
}
// If the query ORDER BY clause matches the ordering of this index, it will be cheaper
// than another index, so adjust the cost accordingly.
// if the ORDER BY clause matches the ordering of this index,
// it will be cheaper than another index, so adjust the cost accordingly
if (sortOrder != null) {
int[] columnIndexes = new int[ indexColumns.length ];
int[] columnSortTypes = new int[ indexColumns.length ];
......@@ -187,7 +188,9 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
coveringCount++;
}
if (sortOrderMatches) {
// "coveringCount" makes sure that when we have two or more covering indexes, we choose the one that covers more
// "coveringCount" makes sure that when we have two
// or more covering indexes, we choose the one
// that covers more
cost -= coveringCount;
}
}
......
......@@ -80,6 +80,7 @@ public interface Index extends SchemaObject {
* @param session the session
* @param masks per-column comparison bit masks, null means 'always false',
* see constants in IndexCondition
* @param sortOrder the sort order
* @return the estimated cost
*/
double getCost(Session session, int[] masks, SortOrder sortOrder);
......
......@@ -45,7 +45,7 @@ public class Chunk {
* The total number of pages in this chunk.
*/
int pageCount;
/**
* The number of pages still alive.
*/
......
......@@ -352,7 +352,7 @@ public class DataUtils {
file, src.remaining(), pos, e);
}
}
/**
* Convert the length to a length code 0..31. 31 means more than 1 MB.
*
......
......@@ -1176,7 +1176,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
this.keyType = keyType;
return this;
}
public DataType getKeyType() {
return keyType;
}
......
......@@ -868,7 +868,7 @@ public class MVStore {
} else {
meta.put("root." + m.getId(), String.valueOf(Integer.MAX_VALUE));
}
}
}
Set<Chunk> removedChunks = applyFreedPages(storeVersion, time);
ByteBuffer buff;
if (writeBuffer != null) {
......@@ -947,15 +947,15 @@ public class MVStore {
writeFileHeader();
shrinkFileIfPossible(1);
}
for (MVMap<?, ?> m : changed) {
Page p = m.getRoot();
if (p.getTotalCount() > 0) {
p.writeEnd();
}
}
meta.getRoot().writeEnd();
meta.getRoot().writeEnd();
// some pages might have been changed in the meantime (in the newest version)
unsavedPageCount = Math.max(0, unsavedPageCount - currentUnsavedPageCount);
currentStoreVersion = -1;
......@@ -1297,7 +1297,7 @@ public class MVStore {
}
registerFreePage(version, c.id, DataUtils.getPageMaxLength(pos), 1);
}
private void registerFreePage(long version, int chunkId, long maxLengthLive, int pageCount) {
synchronized (freedPages) {
HashMap<Integer, Chunk>freed = freedPages.get(version);
......@@ -1736,7 +1736,7 @@ public class MVStore {
}
store(true);
}
public boolean isReadOnly() {
return readOnly;
}
......
......@@ -852,7 +852,7 @@ public class Page {
}
return write(chunk, buff);
}
/**
* Unlink the children recursively after all data is written.
*/
......
......@@ -218,7 +218,7 @@ public class MVPrimaryIndex extends BaseIndex {
return new MVStoreCursor(session, Collections.<Value>emptyList().iterator(), 0);
}
long key = first ? map.firstKey().getLong() : map.lastKey().getLong();
MVStoreCursor cursor = new MVStoreCursor(session,
MVStoreCursor cursor = new MVStoreCursor(session,
Arrays.asList((Value) ValueLong.get(key)).iterator(), key);
cursor.next();
return cursor;
......
......@@ -520,7 +520,7 @@ public class MVTable extends TableBase {
rowCount = 0;
changesSinceAnalyze = 0;
}
@Override
public void addRow(Session session, Row row) {
lastModificationId = database.getNextModificationDataId();
......@@ -701,7 +701,7 @@ public class MVTable extends TableBase {
public String toString() {
return getSQL();
}
public boolean isMVStore() {
return true;
}
......
......@@ -147,7 +147,7 @@ public class MVTableEngine implements TableEngine {
public Store(Database db, MVStore store) {
this.db = db;
this.store = store;
this.transactionStore = new TransactionStore(store,
this.transactionStore = new TransactionStore(store,
new ValueDataType(null, null, null));
}
......
......@@ -75,7 +75,7 @@ public class TransactionStore {
public TransactionStore(MVStore store) {
this(store, new ObjectDataType());
}
/**
* Create a new transaction store.
*
......@@ -92,7 +92,7 @@ public class TransactionStore {
ArrayType valueType = new ArrayType(new DataType[]{
new ObjectDataType(), new ObjectDataType(), keyType
});
MVMapConcurrent.Builder<long[], Object[]> builder =
MVMapConcurrent.Builder<long[], Object[]> builder =
new MVMapConcurrent.Builder<long[], Object[]>().
valueType(valueType);
// TODO escape other map names, to avoid conflicts
......@@ -129,7 +129,7 @@ public class TransactionStore {
/**
* Get the list of currently open transactions that have pending writes.
*
*
* @return the list of transactions
*/
public synchronized List<Transaction> getOpenTransactions() {
......@@ -158,8 +158,8 @@ public class TransactionStore {
int status = Transaction.STATUS_OPEN;
return new Transaction(this, transactionId, status, null, 0);
}
void storeTransaction(Transaction t) {
private void storeTransaction(Transaction t) {
long transactionId = t.getId();
if (openTransactions.containsKey(transactionId)) {
return;
......@@ -185,10 +185,10 @@ public class TransactionStore {
openTransactions.put(t.getId(), v);
store.commit();
}
/**
* Log an entry.
*
*
* @param t the transaction
* @param logId the log id
* @param opType the operation type
......@@ -345,7 +345,7 @@ public class TransactionStore {
* The transaction store.
*/
final TransactionStore store;
/**
* The version of the store at the time the transaction was started.
*/
......@@ -454,7 +454,7 @@ public class TransactionStore {
*/
public <K, V> TransactionMap<K, V> openMap(String name, long readVersion) {
checkOpen();
return new TransactionMap<K, V>(this, name, new ObjectDataType(),
return new TransactionMap<K, V>(this, name, new ObjectDataType(),
new ObjectDataType(), readVersion);
}
......@@ -569,7 +569,7 @@ public class TransactionStore {
*/
private final MVMap<K, Object[]> mapRead;
TransactionMap(Transaction transaction, String name, DataType keyType,
TransactionMap(Transaction transaction, String name, DataType keyType,
DataType valueType, long readVersion) {
this.transaction = transaction;
ArrayType arrayType = new ArrayType(new DataType[] {
......@@ -811,7 +811,13 @@ public class TransactionStore {
public V getLatest(K key) {
return get(key, mapWrite);
}
/**
* Whether the map contains the key.
*
* @param key the key
* @return true if the map contains an entry for this key
*/
public boolean containsKey(K key) {
return get(key) != null;
}
......@@ -855,50 +861,102 @@ public class TransactionStore {
}
}
/**
* Rename the map.
*
* @param newMapName the new map name
*/
public void renameMap(String newMapName) {
// TODO rename maps transactionally
mapWrite.renameMap(newMapName);
}
/**
* Check whether this map is closed.
*
* @return true if closed
*/
public boolean isClosed() {
return mapWrite.isClosed();
}
/**
* Remove the map.
*/
public void removeMap() {
// TODO remove in a transaction
mapWrite.removeMap();
}
/**
* Clear the map.
*/
public void clear() {
// TODO truncate transactionally
mapWrite.clear();
}
/**
* Get the first key.
*
* @return the first key, or null if empty
*/
public K firstKey() {
// TODO transactional firstKey
return mapRead.firstKey();
}
/**
* Get the last key.
*
* @return the last key, or null if empty
*/
public K lastKey() {
// TODO transactional lastKey
return mapRead.lastKey();
}
/**
* Iterate over all keys.
*
* @param from the first key to return
* @return the iterator
*/
public Iterator<K> keyIterator(K from) {
// TODO transactional keyIterator
return mapRead.keyIterator(from);
}
/**
* Get the smallest key that is larger or equal to this key.
*
* @param key the key (may not be null)
* @return the result
*/
public K ceilingKey(K key) {
// TODO transactional ceilingKey
return mapRead.ceilingKey(key);
}
/**
* Get the smallest key that is larger than the given key, or null if no
* such key exists.
*
* @param key the key (may not be null)
* @return the result
*/
public K higherKey(K key) {
// TODO transactional higherKey
return mapRead.higherKey(key);
}
/**
* Get the largest key that is smaller than the given key, or null if no
* such key exists.
*
* @param key the key (may not be null)
* @return the result
*/
public K lowerKey(K key) {
// TODO Auto-generated method stub
return mapRead.lowerKey(key);
......@@ -909,7 +967,7 @@ public class TransactionStore {
}
}
/**
* A data type that contains an array of objects with the specified data
* types.
......@@ -970,8 +1028,8 @@ public class TransactionStore {
array[i] = t.read(buff);
}
return array;
}
}
}
}
......
......@@ -626,6 +626,7 @@ public abstract class Table extends SchemaObjectBase {
* @param session the session
* @param masks per-column comparison bit masks, null means 'always false',
* see constants in IndexCondition
* @param sortOrder the sort order
* @return the plan item
*/
public PlanItem getBestPlanItem(Session session, int[] masks, SortOrder sortOrder) {
......
......@@ -178,7 +178,7 @@ public class TableFilter implements ColumnResolver {
}
SortOrder sortOrder = null;
if (select != null) {
sortOrder = select.prepareOrder();
sortOrder = select.getSortOrder();
}
item = table.getBestPlanItem(s, masks, sortOrder);
// The more index conditions, the earlier the table.
......
......@@ -35,15 +35,17 @@ public class CompareMode {
public static final String ICU4J = "ICU4J_";
/**
* This constant means that the BINARY columns are sorted as if the bytes were signed.
* This constant means that the BINARY columns are sorted as if the bytes
* were signed.
*/
public static final String SIGNED = "SIGNED";
/**
* This constant means that the BINARY columns are sorted as if the bytes were unsigned.
* This constant means that the BINARY columns are sorted as if the bytes
* were unsigned.
*/
public static final String UNSIGNED = "UNSIGNED";
private static CompareMode lastUsed;
private static final boolean CAN_USE_ICU4J;
......@@ -78,12 +80,13 @@ public class CompareMode {
*
* @param name the collation name or null
* @param strength the collation strength
* @param binaryUnsigned whether to compare binaries as unsigned
* @return the compare mode
*/
public static synchronized CompareMode getInstance(String name, int strength, boolean binaryUnsigned) {
if (lastUsed != null) {
if (StringUtils.equals(lastUsed.name, name) &&
lastUsed.strength == strength &&
lastUsed.strength == strength &&
lastUsed.binaryUnsigned == binaryUnsigned) {
return lastUsed;
}
......@@ -220,7 +223,7 @@ public class CompareMode {
public int getStrength() {
return strength;
}
public boolean isBinaryUnsigned() {
return binaryUnsigned;
}
......
......@@ -606,7 +606,7 @@ public abstract class TestBase {
fail("Expected: " + df.format(expected) + " actual: " + df.format(actual));
}
}
/**
* Check if two values are equal, and if not throw an exception.
*
......
......@@ -836,7 +836,7 @@ public class TestCases extends TestBase {
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
ResultSet rs;
// test the default (SIGNED)
stat.execute("create table bin( x binary(1) );");
stat.execute("insert into bin(x) values (x'09'),(x'0a'),(x'99'),(x'aa');");
......@@ -849,7 +849,7 @@ public class TestCases extends TestBase {
assertEquals("09", rs.getString(1));
rs.next();
assertEquals("0a", rs.getString(1));
// test UNSIGNED mode
stat.execute("drop table bin");
stat.execute("SET BINARY_COLLATION UNSIGNED");
......@@ -864,10 +864,10 @@ public class TestCases extends TestBase {
assertEquals("99", rs.getString(1));
rs.next();
assertEquals("aa", rs.getString(1));
conn.close();
}
private void testPersistentSettings() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
......
......@@ -303,7 +303,7 @@ public class TestCompatibility extends TestBase {
assertEquals("John, Doe", rs.getString(1));
rs.close();
prep.close();
// CONVERT has it's parameters the other way around from the default mode
rs = stat.executeQuery("SELECT CONVERT(INT, '10')");
rs.next();
......
......@@ -882,11 +882,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
deleteDb("functions");
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT TRUNCATE(1.234, 2) FROM dual");
rs.next();
assertEquals(1.23d, rs.getDouble(1));
rs = stat.executeQuery("SELECT CURRENT_TIMESTAMP(), TRUNCATE(CURRENT_TIMESTAMP()) FROM dual");
rs.next();
Calendar c = Calendar.getInstance();
......@@ -897,14 +897,14 @@ public class TestFunctions extends TestBase implements AggregateFunction {
c.set(Calendar.MILLISECOND, 0);
java.util.Date nowDate = c.getTime();
assertEquals(nowDate, rs.getTimestamp(2));
try {
rs = stat.executeQuery("SELECT TRUNCATE('bad', 1) FROM dual");
fail("expected exception");
} catch (SQLException ex) {
// expected
}
// check for passing wrong data type
try {
rs = stat.executeQuery("SELECT TRUNCATE('bad') FROM dual");
......@@ -912,7 +912,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
} catch (SQLException ex) {
// expected
}
// check for too many parameters
try {
rs = stat.executeQuery("SELECT TRUNCATE(1,2,3) FROM dual");
......@@ -920,10 +920,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
} catch (SQLException ex) {
// expected
}
conn.close();
}
private void assertCallResult(String expected, Statement stat, String sql) throws SQLException {
ResultSet rs = stat.executeQuery("CALL " + sql);
rs.next();
......
......@@ -783,12 +783,15 @@ public class TestOptimizations extends TestBase {
conn.close();
}
/** Where there are multiple indices, and we have an ORDER BY, select the index that already has the required ordering. */
/**
* Where there are multiple indices, and we have an ORDER BY, select the
* index that already has the required ordering.
*/
private void testOrderedIndexes() throws SQLException {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE my_table(K1 INT, K2 INT, VAL VARCHAR, PRIMARY KEY(K1,K2))");
stat.execute("CREATE INDEX my_index ON my_table(K1,VAL);");
ResultSet rs = stat.executeQuery("EXPLAIN PLAN FOR SELECT * FROM my_table WHERE K1=7 ORDER BY K1,VAL");
......@@ -796,15 +799,17 @@ public class TestOptimizations extends TestBase {
assertContains(rs.getString(1), "/* PUBLIC.MY_INDEX: K1 = 7 */");
stat.execute("DROP TABLE my_table");
// where we have two covering indexes, make sure we choose the one that covers more
// where we have two covering indexes, make sure
// we choose the one that covers more
stat.execute("CREATE TABLE my_table(K1 INT, K2 INT, VAL VARCHAR)");
stat.execute("CREATE INDEX my_index1 ON my_table(K1,K2);");
stat.execute("CREATE INDEX my_index2 ON my_table(K1,K2,VAL);");
rs = stat.executeQuery("EXPLAIN PLAN FOR SELECT * FROM my_table WHERE K1=7 ORDER BY K1,K2,VAL");
rs.next();
assertContains(rs.getString(1), "/* PUBLIC.MY_INDEX2: K1 = 7 */");
conn.close();
}
}
......@@ -79,9 +79,9 @@ public class TestMVStore extends TestBase {
testIterate();
testCloseTwice();
testSimple();
// longer running tests
testLargerThan2G();
}
......@@ -1360,7 +1360,7 @@ public class TestMVStore extends TestBase {
}
s.close();
}
private void testLargerThan2G() throws IOException {
if (!config.big) {
return;
......
......@@ -42,7 +42,7 @@ public class TestMVTableEngine extends TestBase {
testLocking();
testSimple();
}
private void testSpeed() throws Exception {
String dbName;
for (int i = 0; i < 5; i++) {
......@@ -56,7 +56,7 @@ public class TestMVTableEngine extends TestBase {
// System.out.println(prof.getTop(10));
}
}
private void testSpeed(String dbName) throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
Connection conn;
......
......@@ -78,7 +78,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
testFuzzOperations();
deleteDb("pageStore");
}
private void testDropTempTable() throws SQLException {
deleteDb("pageStoreDropTemp");
Connection c1 = getConnection("pageStoreDropTemp");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论