Last active
August 29, 2015 14:27
-
-
Save mmacfadden/cd4f432af79a5626dd94 to your computer and use it in GitHub Desktop.
Shows a issue with Orient DB 2.1 and named parameters and arrays with booleans.
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 java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal; | |
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 OrientBooleanListNamedParameterTest { | |
public static void main(String[] args) { | |
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:test"); | |
ODatabaseRecordThreadLocal.INSTANCE.set(db); | |
db.create(); | |
db.getMetadata().getSchema().createClass("test"); | |
ODocument doc = new ODocument("test"); | |
doc.field("id", 1); | |
doc.field("boolean", false); | |
doc.field("integerList", Collections.EMPTY_LIST); | |
doc.field("booleanList", Collections.EMPTY_LIST); | |
db.save(doc); | |
System.out.println(doc.toJSON()); | |
OCommandSQL updateCommand = new OCommandSQL("UPDATE test SET boolean = :boolean, booleanList = :booleanList, integerList = :integerList WHERE id = 1"); | |
Map<String, Object> params = new HashMap<String, Object>(); | |
// This works. | |
params.put("boolean", true); | |
// This works | |
List<Object> integerList = new ArrayList<>(); | |
integerList.add(1); | |
params.put("integerList", integerList); | |
// This does not. | |
List<Object> booleanList = new ArrayList<>(); | |
booleanList.add(true); | |
params.put("booleanList", booleanList); | |
db.command(updateCommand).execute(params); | |
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("SELECT * FROM test WHERE id = 1"); | |
List<ODocument> queryResult = db.command(query).execute(params); | |
System.out.println(queryResult.get(0).toJSON()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment