private static void allocateFromString( Collection<DynamicRecord> target, String[] array, DynamicRecordAllocator recordAllocator ) { byte[][] stringsAsBytes = new byte[array.length][]; int totalBytesRequired = STRING_HEADER_SIZE; // 1b type + 4b array length for ( int i = 0; i < array.length; i++ ) { String string = array[i]; byte[] bytes = PropertyStore.encodeString( string ); stringsAsBytes[i] = bytes; totalBytesRequired += 4/*byte[].length*/ + bytes.length; } ByteBuffer buf = ByteBuffer.allocate( totalBytesRequired ); buf.put( PropertyType.STRING.byteValue() ); buf.putInt( array.length ); for ( byte[] stringAsBytes : stringsAsBytes ) { buf.putInt( stringAsBytes.length ); buf.put( stringAsBytes ); } allocateRecordsFromBytes( target, buf.array(), recordAllocator ); }
@Override public void writeString( String value ) throws IllegalArgumentException { // Try short string first, i.e. inlined in the property block if ( LongerShortString.encode( keyId, value, block, PropertyType.getPayloadSize() ) ) { return; } // Fall back to dynamic string store byte[] encodedString = encodeString( value ); List<DynamicRecord> valueRecords = new ArrayList<>(); allocateStringRecords( valueRecords, encodedString, stringAllocator ); setSingleBlockValue( block, keyId, PropertyType.STRING, Iterables.first( valueRecords ).getId() ); for ( DynamicRecord valueRecord : valueRecords ) { valueRecord.setType( PropertyType.STRING.intValue() ); } block.setValueRecords( valueRecords ); }
byte[] data = PropertyStore.encodeString( name ); if ( data.length > dynamicIds.length * NAME_STORE_BLOCK_SIZE )
public void createToken( String name, long id, RecordAccess<R, Void> recordAccess ) { R record = recordAccess.create( id, null ).forChangingData(); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> nameRecords = store.allocateNameRecords( encodeString( name ) ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); record.addNameRecords( nameRecords ); } }
private int createNewRelationshipType( String name ) { int id = (int) relationshipTypeTokenStore.nextId(); RelationshipTypeTokenRecord record = new RelationshipTypeTokenRecord( id ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> nameRecords = relationshipTypeTokenStore.allocateNameRecords( encodeString( name ) ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); record.addNameRecords( nameRecords ); relationshipTypeTokenStore.updateRecord( record ); tokenHolders.relationshipTypeTokens().addToken( new NamedToken( name, id ) ); return id; }
private int createNewPropertyKeyId( String stringKey ) { int keyId = (int) propertyKeyTokenStore.nextId(); PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = propertyKeyTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); propertyKeyTokenStore.updateRecord( record ); tokenHolders.propertyKeyTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }
private int createNewLabelId( String stringKey ) { int keyId = (int) labelTokenStore.nextId(); LabelTokenRecord record = new LabelTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = labelTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); labelTokenStore.updateRecord( record ); tokenHolders.labelTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }
private GraphDatabaseAPI databaseWithManyPropertyKeys( int propertyKeyCount ) { PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); StoreFactory storeFactory = new StoreFactory( testDirectory.databaseLayout(), Config.defaults(), new DefaultIdGeneratorFactory( fileSystemRule.get() ), pageCache, fileSystemRule.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY ); NeoStores neoStores = storeFactory.openAllNeoStores( true ); PropertyKeyTokenStore store = neoStores.getPropertyKeyTokenStore(); for ( int i = 0; i < propertyKeyCount; i++ ) { PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( (int) store.nextId() ); record.setInUse( true ); Collection<DynamicRecord> nameRecords = store.allocateNameRecords( PropertyStore.encodeString( key( i ) ) ); record.addNameRecords( nameRecords ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); store.updateRecord( record ); } neoStores.close(); return database(); }
private static void allocateFromString( Collection<DynamicRecord> target, String[] array, DynamicRecordAllocator recordAllocator ) { byte[][] stringsAsBytes = new byte[array.length][]; int totalBytesRequired = STRING_HEADER_SIZE; // 1b type + 4b array length for ( int i = 0; i < array.length; i++ ) { String string = array[i]; byte[] bytes = PropertyStore.encodeString( string ); stringsAsBytes[i] = bytes; totalBytesRequired += 4/*byte[].length*/ + bytes.length; } ByteBuffer buf = ByteBuffer.allocate( totalBytesRequired ); buf.put( PropertyType.STRING.byteValue() ); buf.putInt( array.length ); for ( byte[] stringAsBytes : stringsAsBytes ) { buf.putInt( stringAsBytes.length ); buf.put( stringAsBytes ); } allocateRecordsFromBytes( target, buf.array(), recordAllocator ); }
@Override public void writeString( String value ) throws IllegalArgumentException { // Try short string first, i.e. inlined in the property block if ( LongerShortString.encode( keyId, value, block, PropertyType.getPayloadSize() ) ) { return; } // Fall back to dynamic string store byte[] encodedString = encodeString( value ); List<DynamicRecord> valueRecords = new ArrayList<>(); allocateStringRecords( valueRecords, encodedString, stringAllocator ); setSingleBlockValue( block, keyId, PropertyType.STRING, Iterables.first( valueRecords ).getId() ); for ( DynamicRecord valueRecord : valueRecords ) { valueRecord.setType( PropertyType.STRING.intValue() ); } block.setValueRecords( valueRecords ); }
byte[] data = PropertyStore.encodeString( name ); if ( data.length > dynamicIds.length * NAME_STORE_BLOCK_SIZE )
public void createToken( String name, long id, RecordAccess<R, Void> recordAccess ) { R record = recordAccess.create( id, null ).forChangingData(); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> nameRecords = store.allocateNameRecords( encodeString( name ) ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); record.addNameRecords( nameRecords ); } }
private int createNewLabelId( String stringKey ) { int keyId = (int) labelTokenStore.nextId(); LabelTokenRecord record = new LabelTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = labelTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); labelTokenStore.updateRecord( record ); tokenHolders.labelTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }
private int createNewRelationshipType( String name ) { int id = (int) relationshipTypeTokenStore.nextId(); RelationshipTypeTokenRecord record = new RelationshipTypeTokenRecord( id ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> nameRecords = relationshipTypeTokenStore.allocateNameRecords( encodeString( name ) ); record.setNameId( (int) Iterables.first( nameRecords ).getId() ); record.addNameRecords( nameRecords ); relationshipTypeTokenStore.updateRecord( record ); tokenHolders.relationshipTypeTokens().addToken( new NamedToken( name, id ) ); return id; }
private int createNewPropertyKeyId( String stringKey ) { int keyId = (int) propertyKeyTokenStore.nextId(); PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( keyId ); record.setInUse( true ); record.setCreated(); Collection<DynamicRecord> keyRecords = propertyKeyTokenStore.allocateNameRecords( encodeString( stringKey ) ); record.setNameId( (int) Iterables.first( keyRecords ).getId() ); record.addNameRecords( keyRecords ); propertyKeyTokenStore.updateRecord( record ); tokenHolders.propertyKeyTokens().addToken( new NamedToken( stringKey, keyId ) ); return keyId; }