/** * Serialize the provided SchemaRule onto the target buffer * * @param schemaRule the SchemaRule to serialize */ public static byte[] serialize( SchemaRule schemaRule ) { if ( schemaRule instanceof StoreIndexDescriptor ) { return serialize( (StoreIndexDescriptor)schemaRule ); } else if ( schemaRule instanceof ConstraintRule ) { return serialize( (ConstraintRule)schemaRule ); } throw new IllegalStateException( "Unknown schema rule type: " + schemaRule.getClass() ); }
private void assertCorrectLength( StoreIndexDescriptor indexRule ) { // GIVEN ByteBuffer buffer = ByteBuffer.wrap( SchemaRuleSerialization.serialize( indexRule ) ); // THEN assertThat( SchemaRuleSerialization.lengthOf( indexRule ), equalTo( buffer.capacity() ) ); }
public List<DynamicRecord> allocateFrom( SchemaRule rule ) { List<DynamicRecord> records = new ArrayList<>(); DynamicRecord record = getRecord( rule.getId(), nextRecord(), CHECK ); DynamicRecordAllocator recordAllocator = new ReusableRecordsCompositeAllocator( singleton( record ), this ); allocateRecordsFromBytes( records, SchemaRuleSerialization.serialize( rule ), recordAllocator ); return records; }
private void assertCorrectLength( ConstraintRule constraintRule ) { // GIVEN ByteBuffer buffer = ByteBuffer.wrap( SchemaRuleSerialization.serialize( constraintRule ) ); // THEN assertThat( SchemaRuleSerialization.lengthOf( constraintRule ), equalTo( buffer.capacity() ) ); }
private static Collection<DynamicRecord> serializeRule( SchemaRule rule, DynamicRecord... records ) { byte[] data = SchemaRuleSerialization.serialize( rule ); DynamicRecordAllocator dynamicRecordAllocator = new ReusableRecordsCompositeAllocator( asList( records ), schemaAllocator ); Collection<DynamicRecord> result = new ArrayList<>(); AbstractDynamicStore.allocateRecordsFromBytes( result, data, dynamicRecordAllocator ); return result; }
private SchemaRule serialiseAndDeserialise( ConstraintRule constraintRule ) throws MalformedSchemaRuleException { ByteBuffer buffer = ByteBuffer.wrap( SchemaRuleSerialization.serialize( constraintRule ) ); return SchemaRuleSerialization.deserialize( constraintRule.getId(), buffer ); }
private SchemaRule serialiseAndDeserialise( StoreIndexDescriptor indexRule ) throws MalformedSchemaRuleException { ByteBuffer buffer = ByteBuffer.wrap( SchemaRuleSerialization.serialize( indexRule ) ); return SchemaRuleSerialization.deserialize( indexRule.getId(), buffer ); }
private SchemaRecord serialize( SchemaRule rule, long id, boolean inUse, boolean created ) { DynamicRecord record = new DynamicRecord( id ); record.setData( SchemaRuleSerialization.serialize( rule ) ); if ( created ) { record.setCreated(); } if ( inUse ) { record.setInUse( true ); } return new SchemaRecord( singletonList( record ) ); }
public static SchemaRuleCommand createIndexRule( IndexProviderDescriptor provider, long id, LabelSchemaDescriptor descriptor ) { SchemaRule rule = IndexDescriptorFactory.forSchema( descriptor, provider ).withId( id ); DynamicRecord record = new DynamicRecord( id ); record.setInUse( true ); record.setCreated(); record.setData( SchemaRuleSerialization.serialize( rule ) ); return new SchemaRuleCommand( Collections.emptyList(), singletonList( record ), rule ); }
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { DynamicRecord schema = new DynamicRecord( next.schema() ); DynamicRecord schemaBefore = schema.clone(); schema.setNextBlock( next.schema() ); // Point to a record that isn't in use. StoreIndexDescriptor rule = indexRule( schema.getId(), label1, key1, DESCRIPTOR ); schema.setData( SchemaRuleSerialization.serialize( rule ) ); tx.createSchema( asList( schemaBefore ), asList( schema ), rule ); } } );
@Test public void storeAndLoad_Big_CompositeMultiTokenSchemaRule() throws Exception { // GIVEN StoreIndexDescriptor indexRule = forSchema( multiToken( IntStream.range( 1, 200 ).toArray(), EntityType.RELATIONSHIP, IntStream.range( 1, 200 ).toArray() ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoad_Big_CompositeSchemaRule() throws Exception { // GIVEN StoreIndexDescriptor indexRule = forSchema( forLabel( 2, IntStream.range( 1, 200 ).toArray() ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoadSchemaRule() throws Exception { // GIVEN StoreIndexDescriptor indexRule = forSchema( forLabel( 1, 4 ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoadCompositeSchemaRule() throws Exception { // GIVEN int[] propertyIds = {4, 5, 6, 7}; StoreIndexDescriptor indexRule = forSchema( forLabel( 2, propertyIds ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoadAnyTokenMultiTokenSchemaRule() throws Exception { // GIVEN int[] propertyIds = {4, 5, 6, 7}; int[] entityTokens = {}; StoreIndexDescriptor indexRule = forSchema( multiToken( entityTokens, EntityType.NODE, propertyIds ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
@Test public void storeAndLoadMultiTokenSchemaRule() throws Exception { // GIVEN int[] propertyIds = {4, 5, 6, 7}; int[] entityTokens = {2, 3, 4}; StoreIndexDescriptor indexRule = forSchema( multiToken( entityTokens, EntityType.RELATIONSHIP, propertyIds ), PROVIDER_DESCRIPTOR ).withId( store.nextId() ); // WHEN StoreIndexDescriptor readIndexRule = (StoreIndexDescriptor) SchemaRuleSerialization.deserialize( indexRule.getId(), wrap( SchemaRuleSerialization.serialize( indexRule ) ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); assertEquals( indexRule.schema(), readIndexRule.schema() ); assertEquals( indexRule, readIndexRule ); assertEquals( indexRule.providerDescriptor(), readIndexRule.providerDescriptor() ); }
/** * Serialize the provided SchemaRule onto the target buffer * * @param schemaRule the SchemaRule to serialize */ public static byte[] serialize( SchemaRule schemaRule ) { if ( schemaRule instanceof StoreIndexDescriptor ) { return serialize( (StoreIndexDescriptor)schemaRule ); } else if ( schemaRule instanceof ConstraintRule ) { return serialize( (ConstraintRule)schemaRule ); } throw new IllegalStateException( "Unknown schema rule type: " + schemaRule.getClass() ); }
public List<DynamicRecord> allocateFrom( SchemaRule rule ) { List<DynamicRecord> records = new ArrayList<>(); DynamicRecord record = getRecord( rule.getId(), nextRecord(), CHECK ); DynamicRecordAllocator recordAllocator = new ReusableRecordsCompositeAllocator( singleton( record ), this ); allocateRecordsFromBytes( records, SchemaRuleSerialization.serialize( rule ), recordAllocator ); return records; }