Search in sources :

Example 1 with DynamicRecord

use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.

the class BatchInserterImpl method createNewRelationshipType.

private int createNewRelationshipType(String name) {
    RelationshipTypeStore typeStore = getRelationshipTypeStore();
    int id = (int) typeStore.nextId();
    RelationshipTypeRecord record = new RelationshipTypeRecord(id);
    record.setInUse(true);
    record.setCreated();
    int typeBlockId = (int) typeStore.nextBlockId();
    record.setTypeBlock(typeBlockId);
    int length = name.length();
    char[] chars = new char[length];
    name.getChars(0, length, chars, 0);
    Collection<DynamicRecord> typeRecords = typeStore.allocateTypeNameRecords(typeBlockId, chars);
    for (DynamicRecord typeRecord : typeRecords) {
        record.addTypeRecord(typeRecord);
    }
    typeStore.updateRecord(record);
    typeHolder.addRelationshipType(name, id);
    return id;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) RelationshipTypeStore(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeStore)

Example 2 with DynamicRecord

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

the class BatchInserterImpl method createNewRelationshipType.

private int createNewRelationshipType(String name) {
    RelationshipTypeStore typeStore = getRelationshipTypeStore();
    int id = (int) typeStore.nextId();
    RelationshipTypeRecord record = new RelationshipTypeRecord(id);
    record.setInUse(true);
    record.setCreated();
    int typeBlockId = (int) typeStore.nextBlockId();
    record.setTypeBlock(typeBlockId);
    Collection<DynamicRecord> typeRecords = typeStore.allocateTypeNameRecords(typeBlockId, encodeString(name));
    for (DynamicRecord typeRecord : typeRecords) {
        record.addTypeRecord(typeRecord);
    }
    typeStore.updateRecord(record);
    typeHolder.addRelationshipType(name, id);
    return id;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) RelationshipTypeStore(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeStore)

Example 3 with DynamicRecord

use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.

the class DumpLogicalLog method readPropertyIndexCommand.

static XaCommand readPropertyIndexCommand(ReadableByteChannel byteChannel, ByteBuffer buffer) throws IOException {
    // id+in_use(byte)+count(int)+key_blockId(int)+nr_key_records(int)
    buffer.clear();
    buffer.limit(17);
    if (byteChannel.read(buffer) != buffer.limit()) {
        return null;
    }
    buffer.flip();
    int id = buffer.getInt();
    byte inUseFlag = buffer.get();
    boolean inUse = false;
    if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) {
        inUse = true;
    } else if (inUseFlag != Record.NOT_IN_USE.byteValue()) {
        throw new IOException("Illegal in use flag: " + inUseFlag);
    }
    PropertyIndexRecord record = new PropertyIndexRecord(id);
    record.setInUse(inUse);
    record.setPropertyCount(buffer.getInt());
    record.setKeyBlockId(buffer.getInt());
    int nrKeyRecords = buffer.getInt();
    for (int i = 0; i < nrKeyRecords; i++) {
        DynamicRecord dr = readDynamicRecord(byteChannel, buffer);
        if (dr == null) {
            return null;
        }
        record.addKeyRecord(dr);
    }
    return new Command(record);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) IOException(java.io.IOException)

Example 4 with DynamicRecord

use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.

the class Command method readDynamicRecord.

static DynamicRecord readDynamicRecord(ReadableByteChannel byteChannel, ByteBuffer buffer) throws IOException {
    // id+type+in_use(byte)+prev_block(long)+nr_of_bytes(int)+next_block(long)
    buffer.clear();
    buffer.limit(13);
    if (byteChannel.read(buffer) != buffer.limit()) {
        return null;
    }
    buffer.flip();
    long id = buffer.getLong();
    int type = buffer.getInt();
    byte inUseFlag = buffer.get();
    boolean inUse = false;
    if (inUseFlag == Record.IN_USE.byteValue()) {
        inUse = true;
        buffer.clear();
        buffer.limit(20);
        if (byteChannel.read(buffer) != buffer.limit()) {
            return null;
        }
        buffer.flip();
    } else if (inUseFlag != Record.NOT_IN_USE.byteValue()) {
        throw new IOException("Illegal in use flag: " + inUseFlag);
    }
    DynamicRecord record = new DynamicRecord(id);
    record.setInUse(inUse, type);
    if (inUse) {
        record.setPrevBlock(buffer.getLong());
        int nrOfBytes = buffer.getInt();
        record.setNextBlock(buffer.getLong());
        buffer.clear();
        buffer.limit(nrOfBytes);
        if (byteChannel.read(buffer) != buffer.limit()) {
            return null;
        }
        buffer.flip();
        byte[] data = new byte[nrOfBytes];
        buffer.get(data);
        record.setData(data);
    }
    return record;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) IOException(java.io.IOException)

Example 5 with DynamicRecord

use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.

the class WriteTransaction method relChangeProperty.

void relChangeProperty(long relId, long propertyId, Object value) {
    RelationshipRecord relRecord = getRelationshipRecord(relId);
    if (relRecord == null) {
        relRecord = getRelationshipStore().getRecord(relId);
    }
    if (!relRecord.inUse()) {
        throw new IllegalStateException("Property change on relationship[" + relId + "] illegal since it has been deleted.");
    }
    PropertyRecord propertyRecord = getPropertyRecord(propertyId);
    if (propertyRecord == null) {
        propertyRecord = getPropertyStore().getRecord(propertyId);
        addPropertyRecord(propertyRecord);
    }
    if (!propertyRecord.inUse()) {
        throw new IllegalStateException("Unable to change property[" + propertyId + "] since it is deleted.");
    }
    propertyRecord.setRelId(relId);
    if (propertyRecord.isLight()) {
        getPropertyStore().makeHeavy(propertyRecord);
    }
    propertyRecord.setChanged();
    if (propertyRecord.getType() == PropertyType.STRING) {
        for (DynamicRecord record : propertyRecord.getValueRecords()) {
            if (record.inUse()) {
                record.setInUse(false, PropertyType.STRING.intValue());
            }
        }
    } else if (propertyRecord.getType() == PropertyType.ARRAY) {
        for (DynamicRecord record : propertyRecord.getValueRecords()) {
            if (record.inUse()) {
                record.setInUse(false, PropertyType.ARRAY.intValue());
            }
        }
    }
    getPropertyStore().encodeValue(propertyRecord, value);
    addPropertyRecord(propertyRecord);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

Aggregations

DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)30 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)15 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)7 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)7 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)7 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)6 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)6 IOException (java.io.IOException)5 PropertyIndexStore (org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)4 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)3 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 XAException (javax.transaction.xa.XAException)2 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)2 PropertyStore (org.neo4j.kernel.impl.nioneo.store.PropertyStore)2 RelationshipTypeStore (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeStore)2 PropertyType (org.neo4j.kernel.impl.nioneo.store.PropertyType)1