Last active
August 29, 2015 14:27
-
-
Save mmacfadden/162b60acf9593c13fa45 to your computer and use it in GitHub Desktop.
Demonstrates an issue with Orient DB Increment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.testng.Assert.assertEquals; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.testng.annotations.Test; | |
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; | |
import com.orientechnologies.orient.core.record.impl.ODocument; | |
import com.orientechnologies.orient.core.sql.OCommandSQL; | |
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; | |
public class OrientDBIncrementTest { | |
@Test | |
public void testIncrement() throws Exception { | |
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLUpdateIncmrementTest"); | |
db.create(); | |
db.command(new OCommandSQL("CREATE class test")).execute(); | |
final ODocument test = new ODocument("test"); | |
test.field("id", "id1"); | |
test.field("count", 20); | |
Map<String, Integer> nestedCound = new HashMap<String, Integer>(); | |
nestedCound.put("nestedCount", 10); | |
test.field("map", nestedCound); | |
db.save(test); | |
ODocument queried = (ODocument) db.query(new OSQLSynchQuery<Object>("SELECT FROM test WHERE id = \"id1\"")).get(0);; | |
// Works in 2.1 | |
db.command(new OCommandSQL("UPDATE test INCREMENT count = 2")).execute(); | |
queried.reload(); | |
assertEquals(queried.field("count"), 22); | |
// Works in 2.1 | |
db.command(new OCommandSQL("UPDATE test INCREMENT `map.nestedCount` = 5")).execute(); | |
queried.reload(); | |
assertEquals(queried.field("map.nestedCount"), 15); | |
// Does not work in 2.1 | |
db.command(new OCommandSQL("UPDATE test INCREMENT map.nestedCount = 5")).execute(); | |
queried.reload(); | |
assertEquals(queried.field("map.nestedCount"), 20); | |
db.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment