Search in sources :

Example 1 with RelationshipTypeRecord

use of org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord 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 RelationshipTypeRecord

use of org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord 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 RelationshipTypeRecord

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

the class WriteTransaction method doPrepare.

@Override
protected void doPrepare() throws XAException {
    if (committed) {
        throw new XAException("Cannot prepare committed transaction[" + getIdentifier() + "]");
    }
    if (prepared) {
        throw new XAException("Cannot prepare prepared transaction[" + getIdentifier() + "]");
    }
    // generate records then write to logical log via addCommand method
    prepared = true;
    for (RelationshipTypeRecord record : relTypeRecords.values()) {
        Command.RelationshipTypeCommand command = new Command.RelationshipTypeCommand(neoStore.getRelationshipTypeStore(), record);
        relTypeCommands.add(command);
        addCommand(command);
    }
    for (NodeRecord record : nodeRecords.values()) {
        if (!record.inUse() && record.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
            throw new InvalidRecordException("Node record " + record + " still has relationships");
        }
        Command.NodeCommand command = new Command.NodeCommand(neoStore.getNodeStore(), record);
        nodeCommands.add(command);
        if (!record.inUse()) {
            removeNodeFromCache(record.getId());
        }
        addCommand(command);
    }
    for (RelationshipRecord record : relRecords.values()) {
        Command.RelationshipCommand command = new Command.RelationshipCommand(neoStore.getRelationshipStore(), record);
        relCommands.add(command);
        if (!record.inUse()) {
            removeRelationshipFromCache(record.getId());
        }
        addCommand(command);
    }
    for (PropertyIndexRecord record : propIndexRecords.values()) {
        Command.PropertyIndexCommand command = new Command.PropertyIndexCommand(neoStore.getPropertyStore().getIndexStore(), record);
        propIndexCommands.add(command);
        addCommand(command);
    }
    for (PropertyRecord record : propertyRecords.values()) {
        Command.PropertyCommand command = new Command.PropertyCommand(neoStore.getPropertyStore(), record);
        propCommands.add(command);
        addCommand(command);
    }
}
Also used : XAException(javax.transaction.xa.XAException) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 4 with RelationshipTypeRecord

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

the class LegacyRelationshipTypeStoreReader method readRelationshipTypes.

public Iterable<RelationshipTypeRecord> readRelationshipTypes() throws IOException {
    FileChannel fileChannel = new RandomAccessFile(fileName, "r").getChannel();
    int recordLength = 5;
    int endHeaderSize = UTF8.encode(FROM_VERSION).length;
    long recordCount = (fileChannel.size() - endHeaderSize) / recordLength;
    LinkedList<RelationshipTypeRecord> records = new LinkedList<RelationshipTypeRecord>();
    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) {
            RelationshipTypeRecord record = new RelationshipTypeRecord(id);
            record.setInUse(inUse);
            record.setTypeBlock(buffer.getInt());
            records.add(record);
        }
    }
    fileChannel.close();
    return records;
}
Also used : RandomAccessFile(java.io.RandomAccessFile) FileChannel(java.nio.channels.FileChannel) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList)

Example 5 with RelationshipTypeRecord

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

the class DumpLogicalLog method readRelationshipTypeCommand.

static XaCommand readRelationshipTypeCommand(ReadableByteChannel byteChannel, ByteBuffer buffer) throws IOException {
    // id+in_use(byte)+type_blockId(int)+nr_type_records(int)
    buffer.clear();
    buffer.limit(13);
    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);
    }
    RelationshipTypeRecord record = new RelationshipTypeRecord(id);
    record.setInUse(inUse);
    record.setTypeBlock(buffer.getInt());
    int nrTypeRecords = buffer.getInt();
    for (int i = 0; i < nrTypeRecords; i++) {
        DynamicRecord dr = readDynamicRecord(byteChannel, buffer);
        if (dr == null) {
            return null;
        }
        record.addTypeRecord(dr);
    }
    return new Command(record);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) IOException(java.io.IOException) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)

Aggregations

RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)10 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 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)4 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)4 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 RelationshipTypeStore (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeStore)2 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