use of org.h2.value.CompareMode in project h2database by h2database.
the class PageStore method addMeta.
/**
* Add the meta data of an index.
*
* @param index the index to add
* @param session the session
*/
public void addMeta(PageIndex index, Session session) {
Table table = index.getTable();
if (SysProperties.CHECK) {
if (!table.isTemporary()) {
// the Database lock before we take the PageStore lock
synchronized (database) {
synchronized (this) {
database.verifyMetaLocked(session);
}
}
}
}
synchronized (this) {
int type = index instanceof PageDataIndex ? META_TYPE_DATA_INDEX : META_TYPE_BTREE_INDEX;
IndexColumn[] columns = index.getIndexColumns();
StatementBuilder buff = new StatementBuilder();
for (IndexColumn col : columns) {
buff.appendExceptFirst(",");
int id = col.column.getColumnId();
buff.append(id);
int sortType = col.sortType;
if (sortType != 0) {
buff.append('/');
buff.append(sortType);
}
}
String columnList = buff.toString();
CompareMode mode = table.getCompareMode();
String options = mode.getName() + "," + mode.getStrength() + ",";
if (table.isTemporary()) {
options += "temp";
}
options += ",";
if (index instanceof PageDelegateIndex) {
options += "d";
}
options += "," + mode.isBinaryUnsigned();
Row row = metaTable.getTemplateRow();
row.setValue(0, ValueInt.get(index.getId()));
row.setValue(1, ValueInt.get(type));
row.setValue(2, ValueInt.get(table.getId()));
row.setValue(3, ValueInt.get(index.getRootPageId()));
row.setValue(4, ValueString.get(options));
row.setValue(5, ValueString.get(columnList));
row.setKey(index.getId() + 1);
metaIndex.add(session, row);
}
}
use of org.h2.value.CompareMode in project h2database by h2database.
the class MVSecondaryIndex method addBufferedRows.
@Override
public void addBufferedRows(List<String> bufferNames) {
ArrayList<String> mapNames = new ArrayList<>(bufferNames);
CompareMode compareMode = database.getCompareMode();
int buffersCount = bufferNames.size();
Queue<Source> queue = new PriorityQueue<>(buffersCount, new Source.Comparator(compareMode));
for (String bufferName : bufferNames) {
Iterator<ValueArray> iter = openMap(bufferName).keyIterator(null);
if (iter.hasNext()) {
queue.add(new Source(iter));
}
}
try {
while (!queue.isEmpty()) {
Source s = queue.remove();
ValueArray rowData = s.next();
if (indexType.isUnique()) {
Value[] array = rowData.getList();
// don't change the original value
array = array.clone();
array[keyColumns - 1] = ValueLong.MIN;
ValueArray unique = ValueArray.get(array);
SearchRow row = convertToSearchRow(rowData);
if (!mayHaveNullDuplicates(row)) {
requireUnique(row, dataMap, unique);
}
}
dataMap.putCommitted(rowData, ValueNull.INSTANCE);
if (s.hasNext()) {
queue.offer(s);
}
}
} finally {
for (String tempMapName : mapNames) {
MVMap<ValueArray, Value> map = openMap(tempMapName);
map.getStore().removeMap(map);
}
}
}
use of org.h2.value.CompareMode in project h2database by h2database.
the class TestValueHashMap method testRandomized.
private void testRandomized() {
ValueHashMap<Value> map = ValueHashMap.newInstance();
HashMap<Value, Value> hash = new HashMap<>();
Random random = new Random(1);
Comparator<Value> vc = new Comparator<Value>() {
@Override
public int compare(Value v1, Value v2) {
return v1.compareTo(v2, compareMode);
}
};
for (int i = 0; i < 10000; i++) {
int op = random.nextInt(10);
Value key = ValueInt.get(random.nextInt(100));
Value value = ValueInt.get(random.nextInt(100));
switch(op) {
case 0:
map.put(key, value);
hash.put(key, value);
break;
case 1:
map.remove(key);
hash.remove(key);
break;
case 2:
Value v1 = map.get(key);
Value v2 = hash.get(key);
assertTrue(v1 == null ? v2 == null : v1.equals(v2));
break;
case 3:
{
ArrayList<Value> a1 = map.keys();
ArrayList<Value> a2 = new ArrayList<>(hash.keySet());
assertEquals(a1.size(), a2.size());
Collections.sort(a1, vc);
Collections.sort(a2, vc);
for (int j = 0; j < a1.size(); j++) {
assertTrue(a1.get(j).equals(a2.get(j)));
}
break;
}
case 4:
ArrayList<Value> a1 = map.values();
ArrayList<Value> a2 = new ArrayList<>(hash.values());
assertEquals(a1.size(), a2.size());
Collections.sort(a1, vc);
Collections.sort(a2, vc);
for (int j = 0; j < a1.size(); j++) {
assertTrue(a1.get(j).equals(a2.get(j)));
}
break;
default:
}
}
}
use of org.h2.value.CompareMode in project h2database by h2database.
the class TestDataPage method testValue.
private void testValue(Value v) {
Data data = Data.create(null, 1024);
data.checkCapacity((int) v.getPrecision());
data.writeValue(v);
data.writeInt(123);
data.reset();
Value v2 = data.readValue();
assertEquals(v.getType(), v2.getType());
assertEquals(0, v.compareTo(v2, compareMode));
assertEquals(123, data.readInt());
}
use of org.h2.value.CompareMode in project h2database by h2database.
the class JdbcResultSet method patchCurrentRow.
private void patchCurrentRow(Value[] row) {
boolean changed = false;
Value[] current = result.currentRow();
CompareMode mode = conn.getCompareMode();
for (int i = 0; i < row.length; i++) {
if (row[i].compareTo(current[i], mode) != 0) {
changed = true;
break;
}
}
if (patchedRows == null) {
patchedRows = new HashMap<>();
}
Integer rowId = result.getRowId();
if (!changed) {
patchedRows.remove(rowId);
} else {
patchedRows.put(rowId, row);
}
}
Aggregations