提交 e3246873 authored 作者: Sergi Vladykin's avatar Sergi Vladykin

Changed methods visibility in Data

上级 cc401fdd
...@@ -377,7 +377,7 @@ public class PageBtreeIndex extends PageIndex { ...@@ -377,7 +377,7 @@ public class PageBtreeIndex extends PageIndex {
* @return the number of bytes * @return the number of bytes
*/ */
int getRowSize(Data dummy, SearchRow row, boolean onlyPosition) { int getRowSize(Data dummy, SearchRow row, boolean onlyPosition) {
int rowsize = dummy.getVarLongLen(row.getKey()); int rowsize = Data.getVarLongLen(row.getKey());
if (!onlyPosition) { if (!onlyPosition) {
for (Column col : columns) { for (Column col : columns) {
Value v = row.getValue(col.getColumnId()); Value v = row.getValue(col.getColumnId());
......
...@@ -154,7 +154,7 @@ public class PageDataLeaf extends PageData { ...@@ -154,7 +154,7 @@ public class PageDataLeaf extends PageData {
int rowLength = getRowLength(row); int rowLength = getRowLength(row);
int pageSize = index.getPageStore().getPageSize(); int pageSize = index.getPageStore().getPageSize();
int last = entryCount == 0 ? pageSize : offsets[entryCount - 1]; int last = entryCount == 0 ? pageSize : offsets[entryCount - 1];
int keyOffsetPairLen = 2 + data.getVarLongLen(row.getKey()); int keyOffsetPairLen = 2 + Data.getVarLongLen(row.getKey());
if (entryCount > 0 && last - rowLength < start + keyOffsetPairLen) { if (entryCount > 0 && last - rowLength < start + keyOffsetPairLen) {
int x = findInsertionPoint(row.getKey()); int x = findInsertionPoint(row.getKey());
if (entryCount > 1) { if (entryCount > 1) {
...@@ -271,7 +271,7 @@ public class PageDataLeaf extends PageData { ...@@ -271,7 +271,7 @@ public class PageDataLeaf extends PageData {
firstOverflowPageId = 0; firstOverflowPageId = 0;
overflowRowSize = 0; overflowRowSize = 0;
rowRef = null; rowRef = null;
int keyOffsetPairLen = 2 + data.getVarLongLen(keys[i]); int keyOffsetPairLen = 2 + Data.getVarLongLen(keys[i]);
int[] newOffsets = new int[entryCount]; int[] newOffsets = new int[entryCount];
long[] newKeys = new long[entryCount]; long[] newKeys = new long[entryCount];
Row[] newRows = new Row[entryCount]; Row[] newRows = new Row[entryCount];
......
...@@ -131,12 +131,12 @@ public class PageDataNode extends PageData { ...@@ -131,12 +131,12 @@ public class PageDataNode extends PageData {
keys = newKeys; keys = newKeys;
childPageIds = newChildPageIds; childPageIds = newChildPageIds;
entryCount++; entryCount++;
length += 4 + data.getVarLongLen(key); length += 4 + Data.getVarLongLen(key);
} }
int addRowTry(Row row) { int addRowTry(Row row) {
index.getPageStore().logUndo(this, data); index.getPageStore().logUndo(this, data);
int keyOffsetPairLen = 4 + data.getVarLongLen(row.getKey()); int keyOffsetPairLen = 4 + Data.getVarLongLen(row.getKey());
while (true) { while (true) {
int x = find(row.getKey()); int x = find(row.getKey());
PageData page = index.getPage(childPageIds[x], getPos()); PageData page = index.getPage(childPageIds[x], getPos());
...@@ -213,7 +213,7 @@ public class PageDataNode extends PageData { ...@@ -213,7 +213,7 @@ public class PageDataNode extends PageData {
entryCount = 1; entryCount = 1;
childPageIds = new int[] { page1.getPos(), page2.getPos() }; childPageIds = new int[] { page1.getPos(), page2.getPos() };
keys = new long[] { pivot }; keys = new long[] { pivot };
length += 4 + data.getVarLongLen(pivot); length += 4 + Data.getVarLongLen(pivot);
check(); check();
} }
...@@ -362,7 +362,7 @@ public class PageDataNode extends PageData { ...@@ -362,7 +362,7 @@ public class PageDataNode extends PageData {
changeCount = index.getPageStore().getChangeCount(); changeCount = index.getPageStore().getChangeCount();
entryCount--; entryCount--;
int removedKeyIndex = i < keys.length ? i : i - 1; int removedKeyIndex = i < keys.length ? i : i - 1;
length -= 4 + data.getVarLongLen(keys[removedKeyIndex]); length -= 4 + Data.getVarLongLen(keys[removedKeyIndex]);
if (entryCount < 0) { if (entryCount < 0) {
DbException.throwInternalError(); DbException.throwInternalError();
} }
......
...@@ -80,7 +80,7 @@ public class Data { ...@@ -80,7 +80,7 @@ public class Data {
/** /**
* The data itself. * The data itself.
*/ */
private byte[] data; protected byte[] data;
/** /**
* The current write or read position. * The current write or read position.
...@@ -92,7 +92,7 @@ public class Data { ...@@ -92,7 +92,7 @@ public class Data {
*/ */
private final DataHandler handler; private final DataHandler handler;
private Data(DataHandler handler, byte[] data) { protected Data(DataHandler handler, byte[] data) {
this.handler = handler; this.handler = handler;
this.data = data; this.data = data;
} }
...@@ -146,12 +146,12 @@ public class Data { ...@@ -146,12 +146,12 @@ public class Data {
* @param s the value * @param s the value
* @return the length * @return the length
*/ */
public int getStringLen(String s) { public static int getStringLen(String s) {
int len = s.length(); int len = s.length();
return getStringWithoutLengthLen(s, len) + getVarIntLen(len); return getStringWithoutLengthLen(s, len) + getVarIntLen(len);
} }
private int getStringWithoutLengthLen(String s, int len) { public static int getStringWithoutLengthLen(String s, int len) {
int plus = 0; int plus = 0;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
char c = s.charAt(i); char c = s.charAt(i);
...@@ -299,6 +299,15 @@ public class Data { ...@@ -299,6 +299,15 @@ public class Data {
pos += len; pos += len;
} }
/**
* Append a number of bytes to this buffer.
*
* @param buff the data
*/
public void write(byte[] buff) {
write(buff, 0, buff.length);
}
/** /**
* Copy a number of bytes to the given buffer from the current position. The * Copy a number of bytes to the given buffer from the current position. The
* current position is incremented accordingly. * current position is incremented accordingly.
...@@ -312,6 +321,16 @@ public class Data { ...@@ -312,6 +321,16 @@ public class Data {
pos += len; pos += len;
} }
/**
* Copy a number of bytes to the given buffer from the current position. The
* current position is incremented accordingly.
*
* @param buff the output buffer
*/
public void read(byte[] buff) {
read(buff, 0, buff.length);
}
/** /**
* Append one single byte. * Append one single byte.
* *
...@@ -326,7 +345,7 @@ public class Data { ...@@ -326,7 +345,7 @@ public class Data {
* *
* @return the value * @return the value
*/ */
public int readByte() { public byte readByte() {
return data[pos++]; return data[pos++];
} }
...@@ -563,9 +582,9 @@ public class Data { ...@@ -563,9 +582,9 @@ public class Data {
DbException.throwInternalError("type=" + v.getType()); DbException.throwInternalError("type=" + v.getType());
} }
if (SysProperties.CHECK2) { if (SysProperties.CHECK2) {
if (pos - start != getValueLen(v)) { if (pos - start != getValueLen(v, handler)) {
throw DbException throw DbException
.throwInternalError("value size error: got " + (pos - start) + " expected " + getValueLen(v)); .throwInternalError("value size error: got " + (pos - start) + " expected " + getValueLen(v, handler));
} }
} }
} }
...@@ -596,9 +615,9 @@ public class Data { ...@@ -596,9 +615,9 @@ public class Data {
case Value.LONG: case Value.LONG:
return ValueLong.get(readVarLong()); return ValueLong.get(readVarLong());
case Value.BYTE: case Value.BYTE:
return ValueByte.get((byte) readByte()); return ValueByte.get(readByte());
case Value.SHORT: case Value.SHORT:
return ValueShort.get((short) readShortInt()); return ValueShort.get(readShortInt());
case DECIMAL_0_1: case DECIMAL_0_1:
return (ValueDecimal) ValueDecimal.ZERO; return (ValueDecimal) ValueDecimal.ZERO;
case DECIMAL_0_1 + 1: case DECIMAL_0_1 + 1:
...@@ -724,10 +743,21 @@ public class Data { ...@@ -724,10 +743,21 @@ public class Data {
* @return the number of bytes required to store this value * @return the number of bytes required to store this value
*/ */
public int getValueLen(Value v) { public int getValueLen(Value v) {
return getValueLen2(v) + TEST_OFFSET; return getValueLen(v, handler);
}
/**
* Calculate the number of bytes required to encode the given value.
*
* @param v the value
* @param handler the data handler for lobs
* @return the number of bytes required to store this value
*/
public static int getValueLen(Value v, DataHandler handler) {
return getValueLen2(v, handler) + TEST_OFFSET;
} }
private int getValueLen2(Value v) { private static int getValueLen2(Value v, DataHandler handler) {
if (v == ValueNull.INSTANCE) { if (v == ValueNull.INSTANCE) {
return 1; return 1;
} }
...@@ -868,7 +898,7 @@ public class Data { ...@@ -868,7 +898,7 @@ public class Data {
Value[] list = ((ValueArray) v).getList(); Value[] list = ((ValueArray) v).getList();
int len = 1 + getVarIntLen(list.length); int len = 1 + getVarIntLen(list.length);
for (Value x : list) { for (Value x : list) {
len += getValueLen(x); len += getValueLen(x, handler);
} }
return len; return len;
} }
...@@ -904,9 +934,9 @@ public class Data { ...@@ -904,9 +934,9 @@ public class Data {
* *
* @return the value * @return the value
*/ */
public int readShortInt() { public short readShortInt() {
byte[] buff = data; byte[] buff = data;
return ((buff[pos++] & 0xff) << 8) + (buff[pos++] & 0xff); return (short) (((buff[pos++] & 0xff) << 8) + (buff[pos++] & 0xff));
} }
/** /**
...@@ -929,7 +959,7 @@ public class Data { ...@@ -929,7 +959,7 @@ public class Data {
* @param x the value * @param x the value
* @return the len * @return the len
*/ */
private int getVarIntLen(int x) { public static int getVarIntLen(int x) {
if ((x & (-1 << 7)) == 0) { if ((x & (-1 << 7)) == 0) {
return 1; return 1;
} else if ((x & (-1 << 14)) == 0) { } else if ((x & (-1 << 14)) == 0) {
...@@ -995,7 +1025,7 @@ public class Data { ...@@ -995,7 +1025,7 @@ public class Data {
* @param x the value * @param x the value
* @return the len * @return the len
*/ */
public int getVarLongLen(long x) { public static int getVarLongLen(long x) {
int i = 1; int i = 1;
while (true) { while (true) {
x >>>= 7; x >>>= 7;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论