byte h = (byte) (b & 0xF0);
h = (byte) (h >>> 4);
h = (byte) (h & 0x0F);
- rtn.append(HEX_CHARS[(int) h]);
+ rtn.append(HEX_CHARS[h]);
h = (byte) (b & 0x0F);
- rtn.append(HEX_CHARS[(int) h]);
+ rtn.append(HEX_CHARS[h]);
if (formatted == true)
{
* @param table owning table
* @param buffer Buffer containing column definition
* @param offset Offset in the buffer at which the column definition starts
- * @param format Format that the containing database is in
*/
public Column(Table table, ByteBuffer buffer, int offset)
throws IOException
/**
* @param lvalDefinition Column value that points to an LVAL record
- * @param outType optional 1 element array for returning the
- * <code>LONG_VALUE_TYPE_*</code>
* @return The LVAL data
*/
private byte[] readLongValue(byte[] lvalDefinition)
/**
* Decodes "Currency" values.
*
- * @param valueBytes Column value that points to currency data
+ * @param buffer Column value that points to currency data
* @return BigDecimal representing the monetary value
* @throws IOException if the value cannot be parsed
*/
long time = ((Date)value).getTime();
time += getTimeZoneOffset(time);
time += MILLIS_BETWEEN_EPOCH_AND_1900;
- double dTime = ((double)time) / MILLISECONDS_PER_DAY;
+ double dTime = time / MILLISECONDS_PER_DAY;
buffer.putDouble(dTime);
}
}
public String toString() {
StringBuilder rtn = new StringBuilder();
rtn.append("\tName: " + _name);
- rtn.append("\n\tType: 0x" + Integer.toHexString((int)_type.getValue()) +
+ rtn.append("\n\tType: 0x" + Integer.toHexString(_type.getValue()) +
" (" + _type + ")");
rtn.append("\n\tNumber: " + _columnNumber);
rtn.append("\n\tLength: " + _columnLength);
/**
* Returns the current row in this cursor (Column name -> Column value).
- * @param columnNames Only column names in this collection will be returned
*/
public Map<String, Object> getCurrentRow()
throws IOException
public int getFixedSize() {
if(_fixedSize != null) {
return _fixedSize;
- } else {
- throw new IllegalArgumentException("FIX ME");
}
+ throw new IllegalArgumentException("FIX ME");
}
public int getMinSize() {
public int getSQLType() throws SQLException {
if (_sqlType != null) {
return _sqlType;
- } else {
- throw new SQLException("Unsupported data type: " + toString());
}
+ throw new SQLException("Unsupported data type: " + toString());
}
public int getMinScale() {
DataType rtn = DATA_TYPES.get(b);
if (rtn != null) {
return rtn;
- } else {
- throw new IOException("Unrecognized data type: " + b);
}
+ throw new IOException("Unrecognized data type: " + b);
}
public static DataType fromSQLType(int sqlType)
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.ConcurrentModificationException;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
FileChannel channel = openChannel(mdbFile, false);
channel.transferFrom(Channels.newChannel(
Thread.currentThread().getContextClassLoader().getResourceAsStream(
- EMPTY_MDB)), 0, (long) Integer.MAX_VALUE);
+ EMPTY_MDB)), 0, Integer.MAX_VALUE);
return new Database(channel, autoSync);
}
/**
* Create a new entry
* @param values Indexed row values
- * @param page Page number on which the row is stored
- * @param rowNumber Row number at which the row is stored
+ * @param rowId rowId in which the row is stored
+ * @param columns map of columns for this index
*/
private Entry(Object[] values, RowId rowId,
Map<Column, Byte> columns)
byte version = buffer.get();
if (version == CODE_VERSION_4) {
return VERSION_4;
- } else {
- throw new IOException("Unsupported version: " + version);
}
+ throw new IOException("Unsupported version: " + version);
}
private JetFormat(String name) {
page.rewind();
page.position(pageOffset);
_channel.write(page, (((long) pageNumber * (long) getFormat().PAGE_SIZE) +
- (long) pageOffset));
+ pageOffset));
if(_autoSync) {
flush();
}
/**
* Allocates a new page in the database. Data in the page is undefined
- * until it is written in a call to {@link #writePage}.
+ * until it is written in a call to {@link #writePage(ByteBuffer,int)}.
*/
public int allocateNewPage() throws IOException {
// this will force the file to be extended with mostly undefined bytes
}
/**
+ * @param database database which owns this table
* @param tableBuffer Buffer to read the table with
- * @param pageChannel Page channel to get database pages from
- * @param format Format of the database that contains this table
* @param pageNumber Page number of the table definition
- * @param name Table name
+ * @param name Table name
*/
protected Table(Database database, ByteBuffer tableBuffer,
int pageNumber, String name)
}
/**
- * Delete the current row (retrieved by a call to {@link #getNextRow}).
+ * Delete the current row (retrieved by a call to {@link #getNextRow()}).
*/
public void deleteCurrentRow() throws IOException {
_cursor.deleteCurrentRow();
// variable length values so that we have a better chance of fitting it
// all (because "long variable" values can go in separate pages)
short longVariableOffset =
- (short) Column.countNonLongVariableLength(columns);
+ Column.countNonLongVariableLength(columns);
for (Column col : columns) {
int position = buffer.position();
buffer.put(col.getType().getValue());
}
buffer.putShort(columnNumber); //Column Number again
if(col.getType().getHasScalePrecision()) {
- buffer.put((byte) col.getPrecision()); // numeric precision
- buffer.put((byte) col.getScale()); // numeric scale
+ buffer.put(col.getPrecision()); // numeric precision
+ buffer.put(col.getScale()); // numeric scale
} else {
buffer.put((byte) 0x00); //unused
buffer.put((byte) 0x00); //unused
rtn.putShort(getRowStartOffset(i, format), (short)rowStart);
if(i == 0) {
// initial "usage pages" map definition
- rtn.put(rowStart, (byte)UsageMap.MAP_TYPE_REFERENCE);
+ rtn.put(rowStart, UsageMap.MAP_TYPE_REFERENCE);
} else {
// initial "pages with free space" map definition
- rtn.put(rowStart, (byte)UsageMap.MAP_TYPE_INLINE);
+ rtn.put(rowStart, UsageMap.MAP_TYPE_INLINE);
}
rowStart -= usageMapRowLength;
}
}
offset += columnCount * getFormat().SIZE_COLUMN_HEADER;
for (int i = 0; i < columnCount; i++) {
- column = (Column) _columns.get(i);
+ column = _columns.get(i);
short nameLength = tableBuffer.getShort(offset);
offset += 2;
byte[] nameBytes = new byte[nameLength];
tableBuffer.position(offset);
- tableBuffer.get(nameBytes, 0, (int) nameLength);
+ tableBuffer.get(nameBytes, 0, nameLength);
column.setName(getFormat().CHARSET.decode(ByteBuffer.wrap(nameBytes)).toString());
offset += nameLength;
}
*/
ByteBuffer createRow(Object[] rowArray, int maxRowSize) throws IOException {
ByteBuffer buffer = getPageChannel().createPageBuffer();
- buffer.putShort((short) _maxColumnCount);
+ buffer.putShort(_maxColumnCount);
NullMask nullMask = new NullMask(_maxColumnCount);
List<Object> row = new ArrayList<Object>(_columns.size());
for (int i = _maxVarColumnCount - 1; i >= 0; i--) {
buffer.putShort(varColumnOffsets[i]);
}
- buffer.putShort((short) _maxVarColumnCount); //Number of var length columns
+ buffer.putShort(_maxVarColumnCount); //Number of var length columns
}
buffer.put(nullMask.wrap()); //Null mask
// note, the saved value is the last one handed out, so pre-increment
return ++_lastAutoNumber;
}
-
+
+ @Override
public String toString() {
StringBuilder rtn = new StringBuilder();
rtn.append("Type: " + _tableType);
_tableBuffer = tableBuffer;
_tablePageNum = pageNum;
_rowStart = rowStart;
- _tableBuffer.position((int) _rowStart + getFormat().OFFSET_USAGE_MAP_START);
+ _tableBuffer.position(_rowStart + getFormat().OFFSET_USAGE_MAP_START);
_startOffset = _tableBuffer.position();
if (LOG.isDebugEnabled()) {
LOG.debug("Usage map block:\n" + ByteUtil.toHexString(_tableBuffer, _rowStart,
addPageNumber(newPageNumber);
}
}
-
+
+ @Override
public String toString() {
StringBuilder builder = new StringBuilder("page numbers: [");
PageCursor pCursor = cursor();
throw new IOException("Page number " + pageNumber +
" is out of supported range");
}
- int pageIndex = (int)(pageNumber / getMaxPagesPerUsagePage());
+ int pageIndex = (pageNumber / getMaxPagesPerUsagePage());
int mapPageNum = getTableBuffer().getInt(
calculateMapPagePointerOffset(pageIndex));
ByteBuffer mapPageBuffer = null;