Refine search
Object currentValue = entity.getProperty( key, null ); if ( currentValue != null && currentValue.getClass().isArray() ) entity.setProperty( key, value ); tx.success();
private void getAllProperties( PropertyContainer entity ) { for ( String key : entity.getPropertyKeys() ) { entity.getProperty( key ); } } };
@Override protected boolean matchesSafely( PropertyContainer propertyContainer, Description mismatchDescription ) { if ( !propertyContainer.hasProperty( propertyName ) ) { mismatchDescription.appendText( String.format( "found property container with property keys: %s", Iterables.asSet( propertyContainer.getPropertyKeys() ) ) ); return false; } return true; }
private void ensureHasOnlyTheseProperties( PropertyContainer entity, Set<String> propertiesThatShouldExist ) { for ( String entityPropertyKey : entity.getPropertyKeys() ) { if ( !propertiesThatShouldExist.contains( entityPropertyKey ) ) { entity.removeProperty( entityPropertyKey ); } } }
static PropertyContainer container( Map<String, Object> values ) { PropertyContainer container = mock( PropertyContainer.class ); when( container.getPropertyKeys() ).thenReturn( values.keySet() ); when( container.getAllProperties() ).thenReturn( values ); for ( Map.Entry<String, Object> entry : values.entrySet() ) { when( container.getProperty( entry.getKey(), null ) ).thenReturn( entry.getValue() ); } return container; } }
private EphemeralFileSystemAbstraction produceUncleanStore( EphemeralFileSystemAbstraction fileSystem, File storeDir ) { GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem( fileSystem ).newImpermanentDatabase( storeDir ); Transaction tx = db.beginTx(); Node node = db.createNode(); node.setProperty( "name", "Something" ); properties( (GraphDatabaseAPI) db ).setProperty( "prop", "Some value" ); tx.success(); tx.close(); EphemeralFileSystemAbstraction snapshot = fileSystem.snapshot(); db.shutdown(); return snapshot; } }
private static <T extends PropertyContainer> void populateKeyIndices(final GraphDatabaseService rawGraphDB, final AutoIndexer<T> rawAutoIndexer, final Iterable<T> rawElements, final Class elementClass) { if (!rawAutoIndexer.isEnabled()) return; final Set<String> properties = rawAutoIndexer.getAutoIndexedProperties(); Transaction tx = rawGraphDB.beginTx(); final PropertyContainer kernel = ((InternalAbstractGraphDatabase) rawGraphDB).getNodeManager().getGraphProperties(); kernel.setProperty(elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX, properties.toArray(new String[properties.size()])); int count = 0; for (final PropertyContainer pc : rawElements) { for (final String property : properties) { if (!pc.hasProperty(property)) continue; pc.setProperty(property, pc.getProperty(property)); count++; if (count >= 10000) { count = 0; tx.success(); tx.finish(); tx = rawGraphDB.beginTx(); } } } tx.success(); tx.finish(); }
graphProperties.setProperty( "test", "yo" ); assertEquals( "yo", graphProperties.getProperty( "test" ) ); tx.success(); tx.close(); assertThat( graphProperties, inTx( db, hasProperty( "test" ).withValue( "yo" ) ) ); tx = db.beginTx(); assertNull( graphProperties.removeProperty( "something non existent" ) ); assertEquals( "yo", graphProperties.removeProperty( "test" ) ); assertNull( graphProperties.getProperty( "test", null ) ); graphProperties.setProperty( "other", 10 ); assertEquals( 10, graphProperties.getProperty( "other" ) ); graphProperties.setProperty( "new", "third" ); tx.success(); tx.close(); assertThat( graphProperties, inTx( db, not( hasProperty( "test" ) ) ) ); graphProperties.setProperty( "rollback", true ); assertEquals( true, graphProperties.getProperty( "rollback" ) ); tx.close(); assertThat( graphProperties, inTx( db, not( hasProperty( "rollback" ) ) ) );
@Test public void getNonExistentGraphPropertyWithDefaultValue() { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); PropertyContainer graphProperties = properties( db ); Transaction tx = db.beginTx(); assertEquals( "default", graphProperties.getProperty( "test", "default" ) ); tx.success(); tx.close(); db.shutdown(); }
@Override public void clearGraph() { GraphDatabaseServiceCleaner.cleanDatabaseContent( db ); try ( Transaction tx = db.beginTx() ) { PropertyContainer graphProperties = graphProperties(); for ( String key : graphProperties.getPropertyKeys() ) { graphProperties.removeProperty( key ); } tx.success(); } }
container.setProperty( entry.getKey(), entry.getValue() ); tx.success(); try ( Transaction tx = db.beginTx() ) listedProperties = lookupPropertyContainer( containerId ).getAllProperties(); tx.success();
@Override protected boolean matchesSafely(PropertyContainer item, Description mismatchDescription) { Object property; try (Transaction tx = item.getGraphDatabase().beginTx()) { property = item.getProperty(key, null); tx.success(); } if (property == null) { mismatchDescription.appendText("property ").appendValue(key).appendText(" not present"); return false; } if (value instanceof Matcher<?>) { Matcher<?> matcher = (Matcher<?>) value; if (!matcher.matches(property)) { matcher.describeMismatch(property, mismatchDescription); return false; } return true; } if (!property.equals(value)) { mismatchDescription.appendText("property ").appendValue(key).appendText("has value").appendValue(property); return false; } return true; }
private void collectProps(Collection<String> fields, PropertyContainer pc, Reporter reporter, String[] row, int offset, String delimiter) { for (String field : fields) { if (pc.hasProperty(field)) { row[offset] = FormatUtils.toString(pc.getProperty(field)); reporter.update(0,0,1); } else { row[offset] = ""; } offset++; } }
@Test public void testEquals() { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); PropertyContainer graphProperties = properties( db ); try ( Transaction tx = db.beginTx() ) { graphProperties.setProperty( "test", "test" ); tx.success(); } assertEquals( graphProperties, properties( db ) ); db.shutdown(); db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); assertNotEquals( graphProperties, properties( db ) ); db.shutdown(); }
@Override Object perform( GraphDatabaseService graphDb ) { return entity.getProperty( key ); } };
public static void combineProperties(Map.Entry<String, Object> prop, PropertyContainer target) { if (!target.hasProperty(prop.getKey())) target.setProperty(prop.getKey(), prop.getValue()); else { Set<Object> values = new LinkedHashSet<>(); if (target.getProperty(prop.getKey()).getClass().isArray()) values.addAll(new ArrayBackedList(target.getProperty(prop.getKey()))); else values.add(target.getProperty(prop.getKey())); if (prop.getValue().getClass().isArray()) values.addAll(new ArrayBackedList(prop.getValue())); else values.add(prop.getValue()); Object array = createPropertyValueFromSet(values); target.setProperty(prop.getKey(), array); } }
/** * Make properties boolean */ @Procedure(mode = Mode.WRITE) @Description("apoc.refactor.normalizeAsBoolean(entity, propertyKey, true_values, false_values) normalize/convert a property to be boolean") public void normalizeAsBoolean( @Name("entity") Object entity, @Name("propertyKey") String propertyKey, @Name("true_values") List<Object> trueValues, @Name("false_values") List<Object> falseValues) { if (entity instanceof PropertyContainer) { PropertyContainer pc = (PropertyContainer) entity; Object value = pc.getProperty(propertyKey, null); if (value != null) { boolean isTrue = trueValues.contains(value); boolean isFalse = falseValues.contains(value); if (isTrue && !isFalse) { pc.setProperty(propertyKey, true); } if (!isTrue && isFalse) { pc.setProperty(propertyKey, false); } if (!isTrue && !isFalse) { pc.removeProperty(propertyKey); } } } }
@Override Void perform( GraphDatabaseService graphDb ) { entity.setProperty( key, value ); return null; } };
public static String removeConfigProperty( final String key, final PropertyContainer container ) { final String pkey = CONFIG_PROPERTY_PREFIX + key; String old = null; if ( container.hasProperty( pkey ) ) { old = (String) container.getProperty( pkey ); container.removeProperty( pkey ); } return old; }
@Override public boolean isEmpty() { return !entity.getPropertyKeys() .iterator() .hasNext(); }