private Field getField( String name, String value, FieldTypeName fieldType){ Field field = null; switch ( fieldType ) { case BOOLEAN: field = new BooleanField( name, Boolean.parseBoolean( value ) ); break; case DOUBLE: field = new DoubleField( name, Double.parseDouble( value ) ); break; case FLOAT: field = new FloatField( name, Float.parseFloat( value ) ); break; case INTEGER: field = new IntegerField( name, Integer.parseInt( value ) ); break; case LONG: field = new LongField( name, Long.parseLong( value ) ); break; case STRING: field = new StringField( name, value ); break; case UUID: field = new UUIDField( name, UUID.fromString( value ) ); break; } return field; }
@Test public void testDelete() throws ConnectionException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version = UUIDGenerator.newTimeUUID(); UniqueValue stored = new UniqueValueImpl( field, entityId, version ); //strategy.write( scope, stored ).execute(); BatchStatement batch = strategy.writeCQL( scope, stored, -1); session.execute(batch); //strategy.delete( scope, stored ).execute(); BatchStatement deleteBatch = strategy.deleteCQL(scope, stored); session.execute(deleteBatch); UniqueValueSet fields = strategy.load( scope, entityId.getType(), Collections.<Field>singleton( field ) ); UniqueValue nullExpected = fields.getValue( field.getName() ); Assert.assertNull( nullExpected ); Iterator<UniqueValue> allFieldsWritten = strategy.getAllUniqueFields( scope, entityId ); assertFalse("No entries left", allFieldsWritten.hasNext() ); }
@Override public Field fromComposite( final CompositeParser composite ) { final String typeString = composite.readString(); final String name = composite.readString(); final String value = composite.readString(); final FieldTypeName fieldType = FieldTypeName.valueOf( typeString ); switch ( fieldType ) { case BOOLEAN: return new BooleanField( name, Boolean.parseBoolean( value ) ); case DOUBLE: return new DoubleField( name, Double.parseDouble( value ) ); case FLOAT: return new FloatField( name, Float.parseFloat( value ) ); case INTEGER: return new IntegerField( name, Integer.parseInt( value ) ); case LONG: return new LongField( name, Long.parseLong( value ) ); case STRING: return new StringField( name, value ); case UUID: return new UUIDField( name, UUID.fromString( value ) ); default: throw new RuntimeException( "Unknown unique field type" ); } }
IntegerField field = new IntegerField( "count", 5 ); Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version = UUIDGenerator.newTimeUUID(); UniqueValue retrieved = fields.getValue( field.getName() ); UniqueValue nullExpected = fields.getValue( field.getName() ); Assert.assertNull( nullExpected );
@Test public void intField() { doTest( new IntegerField( "test", 9, true ) ); }
IntegerField intField = new IntegerField( "long", 1 ); LongField longField = new LongField( "int", 1l ); StringField stringField = new StringField( "name", "test" ); Field<Integer> intFieldReturned = returned.getEntity().get().getField( intField.getName() );
processedField = new IntegerField( fieldName, (Integer)value, unique );
/** * Test that inserting multiple versions of the same entity UUID result in the latest version being returned. * * @throws ConnectionException * @throws InterruptedException */ @Test public void testMultipleVersionsSameEntity() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version1 = UUIDGenerator.newTimeUUID(); UUID version2 = UUIDGenerator.newTimeUUID(); UniqueValue stored1 = new UniqueValueImpl( field, entityId1, version1 ); UniqueValue stored2 = new UniqueValueImpl( field, entityId1, version2 ); session.execute(strategy.writeCQL( scope, stored1, -1 )); session.execute(strategy.writeCQL( scope, stored2, -1 )); // load descending to get the older version of entity for this unique value UniqueValueSet fields = strategy.load( scope, ConsistencyLevel.LOCAL_QUORUM, entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); Assert.assertNotNull( retrieved ); assertEquals( stored2, retrieved ); }
break; case INTEGER: field = new IntegerField( name, Integer.parseInt( value ) ); break; case LONG:
@Test public void testBasicOperation() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version = UUIDGenerator.newTimeUUID(); UniqueValue stored = new UniqueValueImpl( field, entityId, version ); //strategy.write( scope, stored ).execute(); BatchStatement batch = strategy.writeCQL(scope, stored, -1); session.execute(batch); UniqueValueSet fields = strategy.load( scope, entityId.getType(), Collections.<Field>singleton( field ) ); UniqueValue retrieved = fields.getValue( field.getName() ); Assert.assertNotNull( retrieved ); assertEquals( stored, retrieved ); Iterator<UniqueValue> allFieldsWritten = strategy.getAllUniqueFields( scope, entityId ); assertTrue(allFieldsWritten.hasNext()); //test this interface. In most cases, we won't know the field name, so we want them all UniqueValue allFieldsValue = allFieldsWritten.next(); Assert.assertNotNull( allFieldsValue ); assertEquals( field, allFieldsValue.getField() ); assertEquals(version, allFieldsValue.getEntityVersion()); assertFalse(allFieldsWritten.hasNext()); }
@Test public void testIntegerField() { testSingleField( new IntegerField( "Name", 100 ), ( field, entityField ) -> assertEquals( field.getValue(), entityField.get( IndexingUtils.FIELD_LONG ) ) ); }
new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId2 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); entityId1.getType(), Collections.<Field>singleton( field ), true); retrieved = fields.getValue( field.getName() ); entityId1.getType(), Collections.<Field>singleton( field ), true); retrieved = fields.getValue( field.getName() );
@Test public void testIntegerFieldSubObject() { testNestedField( new IntegerField( "name", 100 ), ( field, entityField ) -> assertEquals( field.getValue(), entityField.get( IndexingUtils.FIELD_LONG ) ) ); }
@Test public void testDuplicateEntitiesDescending() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId2 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId3 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version1 = UUIDGenerator.newTimeUUID(); UUID version2 = UUIDGenerator.newTimeUUID(); UUID version3 = UUIDGenerator.newTimeUUID(); UniqueValue stored1 = new UniqueValueImpl( field, entityId3, version1 ); UniqueValue stored2 = new UniqueValueImpl( field, entityId2, version2 ); UniqueValue stored3 = new UniqueValueImpl( field, entityId1, version3 ); session.execute(strategy.writeCQL( scope, stored1, -1 )); session.execute(strategy.writeCQL( scope, stored2, -1 )); session.execute(strategy.writeCQL( scope, stored3, -1 )); // load descending to get the older version of entity for this unique value UniqueValueSet fields = strategy.load( scope, ConsistencyLevel.LOCAL_QUORUM, entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); assertEquals( stored3, retrieved ); }
@Test public void testIntegerFieldSubObjectArray() { testNestedFieldArraySubObject( new IntegerField( "name", 100 ), ( field, entityField ) -> assertEquals( field.getValue(), entityField.get( IndexingUtils.FIELD_LONG ) ) ); }
@Test public void testDuplicateEntitiesAscending() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId2 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId3 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version1 = UUIDGenerator.newTimeUUID(); UUID version2 = UUIDGenerator.newTimeUUID(); UUID version3 = UUIDGenerator.newTimeUUID(); UniqueValue stored1 = new UniqueValueImpl( field, entityId1, version1 ); UniqueValue stored2 = new UniqueValueImpl( field, entityId2, version2 ); UniqueValue stored3 = new UniqueValueImpl( field, entityId3, version3 ); session.execute(strategy.writeCQL( scope, stored1, -1 )); session.execute(strategy.writeCQL( scope, stored2, -1 )); session.execute(strategy.writeCQL( scope, stored3, -1 )); // load descending to get the older version of entity for this unique value UniqueValueSet fields = strategy.load( scope, ConsistencyLevel.LOCAL_QUORUM, entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); assertEquals( stored1, retrieved ); }
entity.setField( new IntegerField( fieldName, (Integer)value ));
@Test public void testMixedDuplicates() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId2 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId3 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version1 = UUIDGenerator.newTimeUUID(); UUID version2 = UUIDGenerator.newTimeUUID(); UUID version3 = UUIDGenerator.newTimeUUID(); UUID version4 = UUIDGenerator.newTimeUUID(); UUID version5 = UUIDGenerator.newTimeUUID(); UniqueValue stored1 = new UniqueValueImpl( field, entityId1, version5 ); UniqueValue stored2 = new UniqueValueImpl( field, entityId2, version4 ); UniqueValue stored3 = new UniqueValueImpl( field, entityId1, version3 ); UniqueValue stored4 = new UniqueValueImpl( field, entityId3, version2 ); UniqueValue stored5 = new UniqueValueImpl( field, entityId3, version1 ); session.execute(strategy.writeCQL( scope, stored1, -1 )); session.execute(strategy.writeCQL( scope, stored2, -1 )); session.execute(strategy.writeCQL( scope, stored3, -1 )); session.execute(strategy.writeCQL( scope, stored4, -1 )); session.execute(strategy.writeCQL( scope, stored5, -1 )); // load descending to get the older version of entity for this unique value UniqueValueSet fields = strategy.load( scope, ConsistencyLevel.LOCAL_QUORUM, entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); assertEquals( stored1, retrieved ); }
entity.setField( new IntegerField( "counter", 0 ) ); newEntity.setField( new IntegerField( "counter", i ) );
IntegerField intField = new IntegerField( "long", 1 ); LongField longField = new LongField( "int", 1l ); StringField stringField = new StringField( "name", "test" ); Field<Integer> intFieldReturned = entity.getField( intField.getName() );