@Test public void testGraphAddPropertyWithNullKey() { try { graphProperties().setProperty( null, "bar" ); fail( "Null key should result in exception." ); } catch ( IllegalArgumentException ignored ) { } }
public synchronized static Map<String, Object> removeAll() { try (Transaction tx = properties.getGraphDatabase().beginTx()) { triggers.clear(); String previous = (String) properties.removeProperty(APOC_TRIGGER); tx.success(); return previous == null ? null : Util.fromJson(previous, Map.class); } catch (Exception e) { return null; } }
private synchronized static Map<String, Object> updateTriggers(String name, Map<String, Object> value) { checkEnabled(); try (Transaction tx = properties.getGraphDatabase().beginTx()) { triggers.clear(); String triggerProperty = (String) properties.getProperty(APOC_TRIGGER, "{}"); triggers.putAll(Util.fromJson(triggerProperty,Map.class)); Map<String,Object> previous = null; if (name != null) { previous = (value == null) ? triggers.remove(name) : triggers.put(name, value); if (value != null || previous != null) { properties.setProperty(APOC_TRIGGER, Util.toJson(triggers)); } } tx.success(); return previous; } }
private synchronized static Map<String, Object> updateCustomData(GraphProperties properties, String name, String type, Map<String, Object> value) { if (name == null || type==null) return null; try (Transaction tx = properties.getGraphDatabase().beginTx()) { Map<String, Map<String, Map<String, Object>>> data = readData(properties); Map<String, Map<String, Object>> procData = data.get(type); Map<String, Object> previous = (value == null) ? procData.remove(name) : procData.put(name, value); if (value != null || previous != null) { properties.setProperty(APOC_CUSTOM, Util.toJson(data)); } tx.success(); return previous; } }
private static Map<String, Map<String,Map<String, Object>>> readData(GraphProperties properties) { try (Transaction tx = properties.getGraphDatabase().beginTx()) { String procedurePropertyData = (String) properties.getProperty(APOC_CUSTOM, "{\"functions\":{},\"procedures\":{}}"); Map result = Util.fromJson(procedurePropertyData, Map.class); tx.success(); return result; } }
@Override public Object get(String key) { return properties.getProperty(key); }
@Override public Object remove(String key) { return properties.removeProperty(key); }
public Map<String, Map<String, Map<String, Object>>> list() { try (Transaction tx = properties.getGraphDatabase().beginTx()) { return readData(properties); } } }
@Override public Iterable<String> getKeys() { return properties.getPropertyKeys(); } }
@Override public boolean hasKey(String key) { return properties.hasProperty(key); }
@Override public Object get(String key, Object defaultValue) { return properties.getProperty(key, defaultValue); }
private void executeTriggers(TransactionData txData, String phase) { if (triggers.containsKey("")) updateTriggers(null,null); GraphDatabaseService db = properties.getGraphDatabase(); Map<String,String> exceptions = new LinkedHashMap<>(); Map<String, Object> params = txDataParams(txData, phase); triggers.forEach((name, data) -> { if( data.get("paused").equals(false)) { if( data.get( "params" ) != null) { params.putAll( (Map<String,Object>) data.get( "params" ) ); } try (Transaction tx = db.beginTx()) { Map<String,Object> selector = (Map<String, Object>) data.get("selector"); if (when(selector, phase)) { params.put("trigger", name); Result result = db.execute((String) data.get("kernelTransaction"), params); Iterators.count(result); result.close(); } tx.success(); } catch(Exception e) { log.warn("Error executing trigger "+name+" in phase "+phase,e); exceptions.put(name, e.getMessage()); } } }); if (!exceptions.isEmpty()) { throw new RuntimeException("Error executing triggers "+exceptions.toString()); } }
@Test public void testGraphAddPropertyWithNullValue() { try { graphProperties().setProperty( "foo", null ); fail( "Null value should result in exception." ); } catch ( IllegalArgumentException ignored ) { } tx.failure(); }
@Override public void set(String key, Object value) { properties.setProperty(key, value); }