@Test public void basicProperties() throws Exception { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); PropertyContainer graphProperties = properties(db); assertThat(graphProperties, inTx(db, not(hasProperty("test")))); Transaction tx = db.beginTx(); graphProperties.setProperty("test", "yo"); assertEquals("yo", graphProperties.getProperty("test")); tx.success(); tx.finish(); 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.finish(); assertThat(graphProperties, inTx(db, not(hasProperty("test")))); assertThat(graphProperties, inTx(db, hasProperty("other").withValue(10))); assertThat(getPropertyKeys(db, graphProperties), containsOnly("other", "new")); tx = db.beginTx(); graphProperties.setProperty("rollback", true); assertEquals(true, graphProperties.getProperty("rollback")); tx.finish(); assertThat(graphProperties, inTx(db, not(hasProperty("rollback")))); db.shutdown(); }
private <T extends Element> void createInternalIndexKey( final String key, final Class<T> elementClass) { final String propertyName = elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX; final PropertyContainer pc = ((GraphDatabaseAPI) this.rawGraph).getKernelData().properties(); try { final String[] keys = (String[]) pc.getProperty(propertyName); final Set<String> temp = new HashSet<String>(Arrays.asList(keys)); temp.add(key); pc.setProperty(propertyName, temp.toArray(new String[temp.size()])); } catch (Exception e) { // no indexed_keys kernel data property pc.setProperty(propertyName, new String[] {key}); } }
public void run(GraphDatabaseService graphDb) { timerOff(MAIN_TIMER); Transaction tx = graphDb.beginTx(); try { this.container = createContainer(graphDb); tx.success(); } finally { tx.finish(); } timerOn(MAIN_TIMER); tx = graphDb.beginTx(); try { int max = getNumberOfIterations(); Object propertyValue = getPropertyValue(); if (getPropertyValue().getClass().isArray()) { int arraySize = Array.getLength(getPropertyValue()); max /= arraySize; } for (int i = 0; i < max; i++) { container.setProperty("my_key", propertyValue); } tx.success(); } finally { tx.finish(); } container = null; }
public boolean addValueToArray(PropertyContainer container, String key, Object value) { Transaction tx = graphDb.beginTx(); try { Collection<Object> values = getPropertyValues(container, key); boolean changed = values.contains(value) ? false : values.add(value); if (changed) { container.setProperty(key, asPropertyValue(values)); } tx.success(); return changed; } finally { tx.finish(); } }
/** * Wraps a single {@link PropertyContainer#setProperty(String, Object)} in a transaction. * * @param container the {@link PropertyContainer}. * @param key the property key. * @param value the property value. */ public void setProperty(PropertyContainer container, String key, Object value) { assertPropertyKeyNotNull(key); if (value == null) { throw new IllegalArgumentException("Value for property '" + key + "' can't be null"); } Transaction tx = graphDb().beginTx(); try { container.setProperty(key, value); tx.success(); } finally { tx.finish(); } }
protected void setProperties(PropertyContainer entity, String propertyJson) throws ShellException { if (propertyJson == null) { return; } try { Map<String, Object> properties = parseJSONMap(propertyJson); for (Map.Entry<String, Object> entry : properties.entrySet()) { entity.setProperty(entry.getKey(), entry.getValue()); } } catch (JSONException e) { throw ShellException.wrapCause(e); } }
public boolean removeValueFromArray(PropertyContainer container, String key, Object value) { Transaction tx = graphDb.beginTx(); try { Collection<Object> values = getPropertyValues(container, key); boolean changed = values.remove(value); if (changed) { if (values.isEmpty()) { container.removeProperty(key); } else { container.setProperty(key, asPropertyValue(values)); } } tx.success(); return changed; } finally { tx.finish(); } }
@Test public void testEquals() { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); PropertyContainer graphProperties = properties(db); Transaction tx = db.beginTx(); try { graphProperties.setProperty("test", "test"); tx.success(); } finally { tx.finish(); } assertEquals(graphProperties, properties(db)); db.shutdown(); db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); assertFalse(graphProperties.equals(properties(db))); db.shutdown(); }
public Object beanToEntity(@NotNull PropertyContainer entity, @NotNull Object bean) { Object value = readBeanValue(bean); if (converter != null && value != null) { value = converter.toNeo4j(value); } boolean updateIndex = false; Object oldValue = null; if (indexMapping != null) { oldValue = entity.getProperty(propertyName, null); updateIndex = !Neo4jUtils.equals(oldValue, value); } if (value != null) { entity.setProperty(propertyName, value); } else { entity.removeProperty(propertyName); } if (updateIndex) { indexMapping.update(entity, oldValue, value); } return value; }
private void setProperties(Map<String, Object> properties, PropertyContainer entity) { for (Map.Entry<String, Object> property : properties.entrySet()) { entity.setProperty(property.getKey(), property.getValue()); } }