Search in sources :

Example 6 with PropertyIndexRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord in project neo4j-mobile-android by neo4j-contrib.

the class LegacyPropertyIndexStoreReader method readPropertyIndexStore.

public Iterable<PropertyIndexRecord> readPropertyIndexStore() throws IOException {
    FileChannel fileChannel = new RandomAccessFile(fileName, "r").getChannel();
    int recordLength = 9;
    int endHeaderSize = UTF8.encode(FROM_VERSION).length;
    long recordCount = (fileChannel.size() - endHeaderSize) / recordLength;
    LinkedList<PropertyIndexRecord> records = new LinkedList<PropertyIndexRecord>();
    ByteBuffer buffer = ByteBuffer.allocateDirect(recordLength);
    for (int id = 0; id <= recordCount; id++) {
        buffer.position(0);
        fileChannel.read(buffer);
        buffer.flip();
        long inUseByte = buffer.get();
        boolean inUse = inUseByte == Record.IN_USE.byteValue();
        if (inUse) {
            PropertyIndexRecord record = new PropertyIndexRecord(id);
            record.setInUse(inUse);
            record.setPropertyCount(buffer.getInt());
            record.setKeyBlockId(buffer.getInt());
            records.add(record);
        }
    }
    fileChannel.close();
    return records;
}
Also used : RandomAccessFile(java.io.RandomAccessFile) FileChannel(java.nio.channels.FileChannel) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList)

Example 7 with PropertyIndexRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method createPropertyIndex.

@Override
public void createPropertyIndex(String key, int id) {
    PropertyIndexRecord record = new PropertyIndexRecord(id);
    record.setInUse(true);
    record.setCreated();
    PropertyIndexStore propIndexStore = getPropertyStore().getIndexStore();
    int keyBlockId = propIndexStore.nextKeyBlockId();
    record.setKeyBlockId(keyBlockId);
    Collection<DynamicRecord> keyRecords = propIndexStore.allocateKeyRecords(keyBlockId, encodeString(key));
    for (DynamicRecord keyRecord : keyRecords) {
        record.addKeyRecord(keyRecord);
    }
    addPropertyIndexRecord(record);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) PropertyIndexStore(org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)

Example 8 with PropertyIndexRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method loadIndex.

@Override
public String loadIndex(int id) {
    PropertyIndexStore indexStore = getPropertyStore().getIndexStore();
    PropertyIndexRecord index = getPropertyIndexRecord(id);
    if (index == null) {
        index = indexStore.getRecord(id);
    }
    if (index.isLight()) {
        indexStore.makeHeavy(index);
    }
    return indexStore.getStringFor(index);
}
Also used : PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) PropertyIndexStore(org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)

Example 9 with PropertyIndexRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method doRollback.

@Override
public void doRollback() throws XAException {
    if (committed) {
        throw new XAException("Cannot rollback partialy commited " + "transaction[" + getIdentifier() + "]. Recover and " + "commit");
    }
    try {
        for (RelationshipTypeRecord record : relTypeRecords.values()) {
            if (record.isCreated()) {
                getRelationshipTypeStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getTypeRecords()) {
                    if (dynamicRecord.isCreated()) {
                        getRelationshipTypeStore().freeBlockId((int) dynamicRecord.getId());
                    }
                }
            }
            removeRelationshipTypeFromCache(record.getId());
        }
        for (NodeRecord record : nodeRecords.values()) {
            if (record.isCreated()) {
                getNodeStore().freeId(record.getId());
            }
            removeNodeFromCache(record.getId());
        }
        for (RelationshipRecord record : relRecords.values()) {
            if (record.isCreated()) {
                getRelationshipStore().freeId(record.getId());
            }
            removeRelationshipFromCache(record.getId());
        }
        for (PropertyIndexRecord record : propIndexRecords.values()) {
            if (record.isCreated()) {
                getPropertyStore().getIndexStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getKeyRecords()) {
                    if (dynamicRecord.isCreated()) {
                        getPropertyStore().getIndexStore().freeBlockId((int) dynamicRecord.getId());
                    }
                }
            }
        }
        for (PropertyRecord record : propertyRecords.values()) {
            if (record.getNodeId() != -1) {
                removeNodeFromCache(record.getNodeId());
            } else if (record.getRelId() != -1) {
                removeRelationshipFromCache(record.getRelId());
            }
            if (record.isCreated()) {
                getPropertyStore().freeId(record.getId());
                for (PropertyBlock block : record.getPropertyBlocks()) {
                    for (DynamicRecord dynamicRecord : block.getValueRecords()) {
                        if (dynamicRecord.isCreated()) {
                            if (dynamicRecord.getType() == PropertyType.STRING.intValue()) {
                                getPropertyStore().freeStringBlockId(dynamicRecord.getId());
                            } else if (dynamicRecord.getType() == PropertyType.ARRAY.intValue()) {
                                getPropertyStore().freeArrayBlockId(dynamicRecord.getId());
                            } else {
                                throw new InvalidRecordException("Unknown type on " + dynamicRecord);
                            }
                        }
                    }
                }
            }
        }
    } finally {
        nodeRecords.clear();
        propertyRecords.clear();
        relRecords.clear();
        relTypeRecords.clear();
        propIndexRecords.clear();
        nodeCommands.clear();
        propCommands.clear();
        propIndexCommands.clear();
        relCommands.clear();
        relTypeCommands.clear();
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) XAException(javax.transaction.xa.XAException) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 10 with PropertyIndexRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord in project neo4j-mobile-android by neo4j-contrib.

the class ReadTransaction method loadIndex.

@Override
public String loadIndex(int id) {
    PropertyIndexStore indexStore = getPropertyStore().getIndexStore();
    PropertyIndexRecord index = indexStore.getRecord(id);
    if (index.isLight()) {
        indexStore.makeHeavy(index);
    }
    return indexStore.getStringFor(index);
}
Also used : PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) PropertyIndexStore(org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)

Aggregations

PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)14 PropertyIndexStore (org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)8 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)7 XAException (javax.transaction.xa.XAException)4 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)4 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)4 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)4 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 LinkedList (java.util.LinkedList)1 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)1