public static <Type extends Element> void setIndexedProperty(Graph database, Type entity, String propertyName, Object newValue) {
Object oldValue = entity.getProperty(propertyName);
entity.setProperty(propertyName, newValue);
if(database instanceof IndexableGraph) {
IndexableGraph indexable = (IndexableGraph) database;
IndexNames indexName = IndexNames.forElement(entity);
Index<Type> index = (Index<Type>) indexable.getIndex(indexName.getIndexName(), indexName.getIndexed());
if(oldValue!=null) {
index.remove(propertyName, oldValue, entity);
}
if(newValue!=null) {
index.put(propertyName, newValue, entity);