private int getRowLength(Row row) { int size = 0; for (int i = 0; i < columnCount; i++) { size += data.getValueLen(row.getValue(i)); } return size; }
@Override public void remove(Session session, Row row) { rows.remove(row.getValue(indexColumn)); }
/** * Reserve the page if this is a index root page entry. * * @param logPos the redo log position * @param tableId the table id * @param row the row */ void allocateIfIndexRoot(int logPos, int tableId, Row row) { if (tableId == META_TABLE_ID) { int rootPageId = row.getValue(3).getInt(); if (reservedPages == null) { reservedPages = new HashMap<>(); } reservedPages.put(rootPageId, logPos); } }
private static Object[] convertToObjectList(Row row) { if (row == null) { return null; } int len = row.getColumnCount(); Object[] list = new Object[len]; for (int i = 0; i < len; i++) { list[i] = row.getValue(i).getObject(); } return list; }
private void setWhere(Prepared command, int pos, Row row) { for (int i = 0, len = refColumns.length; i < len; i++) { int idx = refColumns[i].column.getColumnId(); Value v = row.getValue(idx); ArrayList<Parameter> params = command.getParameters(); Parameter param = params.get(pos + i); param.setValue(v); } }
/** * Convert the values if required. Default values are not set (kept as * null). * * @param session the session * @param row the row */ @Override public void validateConvertUpdateSequence(Session session, Row row) { for (int i = 0; i < columns.length; i++) { Value value = row.getValue(i); if (value != null) { // null means use the default value Column column = columns[i]; Value v2 = column.validateConvertUpdateSequence(session, value); if (v2 != value) { row.setValue(i, v2); } } } }
@Override public void add(Session session, Row row) { Value key = row.getValue(indexColumn); ArrayList<Long> positions = rows.get(key); if (positions == null) { positions = New.arrayList(); rows.put(key, positions); } positions.add(row.getKey()); rowCount++; }
@Override public void remove(Session session, Row row) { if (rowCount == 1) { // last row in table reset(); } else { Value key = row.getValue(indexColumn); ArrayList<Long> positions = rows.get(key); if (positions.size() == 1) { // last row with such key rows.remove(key); } else { positions.remove(row.getKey()); } rowCount--; } }
private int update(Row row) { // if there is no valid primary key, // the statement degenerates to an INSERT if (update == null) { return 0; } ArrayList<Parameter> k = update.getParameters(); for (int i = 0; i < columns.length; i++) { Column col = columns[i]; Value v = row.getValue(col.getColumnId()); Parameter p = k.get(i); p.setValue(v); } for (int i = 0; i < keys.length; i++) { Column col = keys[i]; Value v = row.getValue(col.getColumnId()); if (v == null) { throw DbException.get(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, col.getSQL()); } Parameter p = k.get(columns.length + i); p.setValue(v); } return update.update(); }
/** * Create a search row for this row. * * @param row the row * @return the search row */ private SearchRow getSearchRow(Row row) { SearchRow r = table.getTemplateSimpleRow(columns.length == 1); r.setKeyAndVersion(row); for (Column c : columns) { int idx = c.getColumnId(); r.setValue(idx, row.getValue(idx)); } return r; }
private void removeMeta(Row row) { int id = row.getValue(0).getInt(); PageIndex index = metaObjects.get(id); index.getTable().removeIndex(index); if (index instanceof PageBtreeIndex || index instanceof PageDelegateIndex) { if (index.isTemporary()) { pageStoreSession.removeLocalTempTableIndex(index); } else { index.getSchema().remove(index); } } index.remove(pageStoreSession); metaObjects.remove(id); }
@Override public void add(Session session, Row row) { Value key = row.getValue(indexColumn); Object old = rows.get(key); if (old != null) { // TODO index duplicate key for hash indexes: is this allowed? throw getDuplicateKeyException(key.toString()); } rows.put(key, row.getKey()); }
/** * Validate all values in this row, convert the values if required, and * update the sequence values if required. This call will also set the * default values if required and set the computed column if there are any. * * @param session the session * @param row the row */ public void validateConvertUpdateSequence(Session session, Row row) { for (int i = 0; i < columns.length; i++) { Value value = row.getValue(i); Column column = columns[i]; Value v2; if (column.getComputed()) { // force updating the value value = null; v2 = column.computeValue(session, row); } v2 = column.validateConvertUpdateSequence(session, value); if (v2 != value) { row.setValue(i, v2); } } }
public BitField getObjectIds() { BitField f = new BitField(); Cursor cursor = metaIndex.find(pageStoreSession, null, null); while (cursor.next()) { Row row = cursor.get(); int id = row.getValue(0).getInt(); if (id > 0) { f.set(id); } } return f; }
private void readMetaData() { Cursor cursor = metaIndex.find(pageStoreSession, null, null); // first, create all tables while (cursor.next()) { Row row = cursor.get(); int type = row.getValue(1).getInt(); if (type == META_TYPE_DATA_INDEX) { addMeta(row, pageStoreSession, false); } } // now create all secondary indexes // otherwise the table might not be created yet cursor = metaIndex.find(pageStoreSession, null, null); while (cursor.next()) { Row row = cursor.get(); int type = row.getValue(1).getInt(); if (type != META_TYPE_DATA_INDEX) { addMeta(row, pageStoreSession, false); } } }
@Override public Value getValue(Column column) { if (joinBatch != null) { return joinBatch.getValue(joinFilterId, column); } if (currentSearchRow == null) { return null; } int columnId = column.getColumnId(); if (columnId == -1) { return ValueLong.get(currentSearchRow.getKey()); } if (current == null) { Value v = currentSearchRow.getValue(columnId); if (v != null) { return v; } current = cursor.get(); if (current == null) { return ValueNull.INSTANCE; } } return current.getValue(columnId); }
private void checkRow(Session session, Row oldRow) { SearchRow check = table.getTemplateSimpleRow(false); for (int i = 0, len = columns.length; i < len; i++) { Column refCol = refColumns[i].column; int refIdx = refCol.getColumnId(); Column col = columns[i].column; Value v = col.convert(oldRow.getValue(refIdx)); if (v == ValueNull.INSTANCE) { return; } check.setValue(col.getColumnId(), v); } // exclude the row only for self-referencing constraints Row excluding = (refTable == table) ? oldRow : null; if (existsRow(session, index, check, excluding)) { throw DbException.get(ErrorCode.REFERENTIAL_INTEGRITY_VIOLATED_CHILD_EXISTS_1, getShortDescription(index, check)); } }
private Cursor find(Row row) { if (index == null) { // for the case "in(select ...)", the query might // use an optimization and not create the index // up front createIndex(); } Cursor cursor = index.find(session, row, row); while (cursor.next()) { SearchRow found = cursor.getSearchRow(); boolean ok = true; Database db = session.getDatabase(); for (int i = 0; i < row.getColumnCount(); i++) { if (!db.areEqual(row.getValue(i), found.getValue(i))) { ok = false; break; } } if (ok) { return cursor; } } return null; }
@Override public void remove(Session session, Row row) { if (mvTable.getContainsLargeObject()) { for (int i = 0, len = row.getColumnCount(); i < len; i++) { Value v = row.getValue(i); if (v.isLinkedToTable()) { session.removeAtCommit(v); } } } TransactionMap<Value, Value> map = getMap(session); try { Value old = map.remove(ValueLong.get(row.getKey())); if (old == null) { throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, getSQL() + ": " + row.getKey()); } } catch (IllegalStateException e) { throw mvTable.convertException(e); } }
/** * Append the row to the buffer. * * @param buff the buffer * @param log the undo log */ void append(Data buff, UndoLog log) { int p = buff.length(); buff.writeInt(0); buff.writeInt(operation); buff.writeByte(row.isDeleted() ? (byte) 1 : (byte) 0); buff.writeInt(log.getTableId(table)); buff.writeLong(row.getKey()); buff.writeInt(row.getSessionId()); int count = row.getColumnCount(); buff.writeInt(count); for (int i = 0; i < count; i++) { Value v = row.getValue(i); buff.checkCapacity(buff.getValueLen(v)); buff.writeValue(v); } buff.fillAligned(); buff.setInt(p, (buff.length() - p) / Constants.FILE_BLOCK_SIZE); }