use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.
the class WriteTransaction method relationshipTypeAdd.
void relationshipTypeAdd(int id, String name) {
RelationshipTypeRecord record = new RelationshipTypeRecord(id);
record.setInUse(true);
record.setCreated();
int blockId = (int) getRelationshipTypeStore().nextBlockId();
record.setTypeBlock(blockId);
int length = name.length();
char[] chars = new char[length];
name.getChars(0, length, chars, 0);
Collection<DynamicRecord> typeNameRecords = getRelationshipTypeStore().allocateTypeNameRecords(blockId, chars);
for (DynamicRecord typeRecord : typeNameRecords) {
record.addTypeRecord(typeRecord);
}
addRelationshipTypeRecord(record);
}
use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.
the class WriteTransaction method doRollback.
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 (DynamicRecord dynamicRecord : record.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();
if (!isRecovered()) {
lockReleaser.rollback();
}
}
}
use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method createRelationshipType.
@Override
public void createRelationshipType(int id, String name) {
RelationshipTypeRecord record = new RelationshipTypeRecord(id);
record.setInUse(true);
record.setCreated();
int blockId = (int) getRelationshipTypeStore().nextBlockId();
record.setTypeBlock(blockId);
// int length = name.length();
// char[] chars = new char[length];
// name.getChars( 0, length, chars, 0 );
Collection<DynamicRecord> typeNameRecords = getRelationshipTypeStore().allocateTypeNameRecords(blockId, encodeString(name));
for (DynamicRecord typeRecord : typeNameRecords) {
record.addTypeRecord(typeRecord);
}
addRelationshipTypeRecord(record);
}
use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord 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);
}
use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method primitiveChangeProperty.
private PropertyData primitiveChangeProperty(PrimitiveRecord primitive, PropertyData propertyData, Object value, boolean isNode) {
assert assertPropertyChain(primitive);
long propertyId = propertyData.getId();
PropertyRecord propertyRecord = getPropertyRecord(propertyId, true, true);
if (!propertyRecord.inUse()) {
throw new IllegalStateException("Unable to change property[" + propertyId + "] since it has been deleted.");
}
if (isNode) {
propertyRecord.setNodeId(primitive.getId());
} else {
propertyRecord.setRelId(primitive.getId());
}
PropertyBlock block = propertyRecord.getPropertyBlock(propertyData.getIndex());
if (block == null) {
throw new IllegalStateException("Property with index[" + propertyData.getIndex() + "] is not present in property[" + propertyId + "]");
}
if (block.isLight()) {
getPropertyStore().makeHeavy(block);
}
propertyRecord.setChanged();
for (DynamicRecord record : block.getValueRecords()) {
assert record.inUse();
record.setInUse(false, block.getType().intValue());
propertyRecord.addDeletedRecord(record);
}
getPropertyStore().encodeValue(block, propertyData.getIndex(), value);
if (propertyRecord.size() > PropertyType.getPayloadSize()) {
propertyRecord.removePropertyBlock(propertyData.getIndex());
/*
* The record should never, ever be above max size. Less obviously, it should
* never remain empty. If removing a property because it won't fit when changing
* it leaves the record empty it means that this block was the last one which
* means that it doesn't fit in an empty record. Where i come from, we call this
* weird.
*
assert propertyRecord.size() <= PropertyType.getPayloadSize() : propertyRecord;
assert propertyRecord.size() > 0 : propertyRecord;
*/
propertyRecord = addPropertyBlockToPrimitive(block, primitive, isNode);
}
assert assertPropertyChain(primitive);
return block.newPropertyData(propertyRecord, value);
}
Aggregations