@Before public void prepareDatabase() throws Exception { String dbUrl = "memory:test"; ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl); String username = "******"; String password = "******"; if (db.exists()) { db.activateOnCurrentThread(); db.open(username, password); db.drop(); } db.create(); createSchemaDB(db); if (!new File("./src/test/resources/file.pdf").exists()) OLogManager.instance() .warn( this, "TEST IS NOT RUNNING UNDER distributed folder, attachment will be not loaded!"); loadDB(db, 20); Properties info = new Properties(); info.put("user", username); info.put("password", password); conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:" + dbUrl, info); }
@Test public void testExceptionManagement() { // issue #5244 OLiveCommandExecutorSQLFactory.init(); ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:ONonBlockingQueryTest"); db.activateOnCurrentThread(); db.create(); db.getMetadata().getSchema().createClass("test"); MyResultListener listener = new MyResultListener(); try { db.command(new OCommandSQL("insert into test set name = 'foo', surname = 'bar'")).execute(); db.query(new OSQLNonBlockingQuery<Object>("select from test bla blu", listener)); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Assert.assertEquals(listener.finished, true); listener = new MyResultListener(); db.query(new OSQLNonBlockingQuery<Object>("select from test", listener)); } finally { db.close(); } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Assert.assertEquals(listener.numResults, 1); }
@Test public void testLiveInsert() { OLiveCommandExecutorSQLFactory.init(); ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OLiveQueryTest"); db.activateOnCurrentThread(); db.create(); db.registerHook(new OLiveQueryHook(db)); try { db.getMetadata().getSchema().createClass("test"); db.getMetadata().getSchema().createClass("test2"); MyLiveQueryListener listener = new MyLiveQueryListener(); db.query(new OLiveQuery<ODocument>("live select from test", listener)); db.command(new OCommandSQL("insert into test set name = 'foo', surname = 'bar'")).execute(); db.command(new OCommandSQL("insert into test set name = 'foo', surname = 'baz'")).execute(); db.command(new OCommandSQL("insert into test2 set name = 'foo'")); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Assert.assertEquals(listener.ops.size(), 2); for (ORecordOperation doc : listener.ops) { Assert.assertEquals(doc.type, ORecordOperation.CREATED); Assert.assertEquals(((ODocument) doc.record).field("name"), "foo"); } } finally { db.drop(); } }
@Test public static void main(String[] args) { database = new ODatabaseDocumentTx("local:/tmp/secmask/secmask"); if (database.exists()) database.open("admin", "admin"); else { database.create(); create(); } // insert(); query(); }
@SuppressWarnings("unchecked") @Test public void test1() { db = new ODatabaseDocumentTx( "local:C:/work/dev/orientechnologies/orientdb/temp/danny/library/library"); try { db.create(); master = db.getMetadata().getSchema().createClass("Master"); master.createProperty("type", OType.STRING); master.createProperty("master", OType.LONG); dependents = db.getMetadata().getSchema().createClass("Dependents"); dependents.createProperty("type", OType.STRING); dependents.createProperty("dependents", OType.EMBEDDEDLIST, master); db.close(); db.open("admin", "admin"); dependents = db.getMetadata().getSchema().getClass("Dependents"); master = db.getMetadata().getSchema().getClass("Master"); // CREATE NEW DOC new ODocument(db, "Dependents") .field( "dependents", new ODocument[] { new ODocument(db, "Master") .field("mastertype", "Title") .field("master", 4151788013272153098L) }) .save(); db.close(); db.open("admin", "admin"); // LOAD IT AND CHECK THE LONG VALUE for (ODocument doc : db.browseClass("Dependents")) { System.out.println(doc); for (ODocument emb : (Iterable<ODocument>) doc.field("dependents")) Assert.assertEquals(emb.field("master"), 4151788013272153098L); } db.close(); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testUpdateContent() throws Exception { final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLUpdateTestContent"); db.create(); try { db.command(new OCommandSQL("CREATE class V")).execute(); db.command(new OCommandSQL("insert into V (name) values ('bar')")).execute(); db.command(new OCommandSQL("UPDATE V content {\"value\":\"foo\"}")).execute(); Iterable result = db.query(new OSQLSynchQuery<Object>("select from V")); ODocument doc = (ODocument) result.iterator().next(); assertEquals(doc.field("value"), "foo"); } finally { db.close(); } }
@Before public void setuUp() throws Exception { spwanServer(); baseDocumentTx = new ODatabaseDocumentTx( "plocal:" + buildDir.getAbsolutePath() + "/baseUniqueIndexCrashRestore"); if (baseDocumentTx.exists()) { baseDocumentTx.open("admin", "admin"); baseDocumentTx.drop(); } baseDocumentTx.create(); testDocumentTx = new ODatabaseDocumentTx("remote:localhost:3500/testUniqueIndexCrashRestore"); testDocumentTx.open("admin", "admin"); }
@Test public void testUpdateMergeWithIndex() { final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLUpdateTestMergeWithIndex"); db.create(); try { db.command(new OCommandSQL("CREATE CLASS i_have_a_list ")).execute(); db.command(new OCommandSQL("CREATE PROPERTY i_have_a_list.id STRING")).execute(); db.command(new OCommandSQL("CREATE INDEX i_have_a_list.id ON i_have_a_list (id) UNIQUE")) .execute(); db.command(new OCommandSQL("CREATE PROPERTY i_have_a_list.types EMBEDDEDLIST STRING")) .execute(); db.command( new OCommandSQL( "CREATE INDEX i_have_a_list.types ON i_have_a_list (types) NOTUNIQUE")) .execute(); db.command( new OCommandSQL( "INSERT INTO i_have_a_list CONTENT {\"id\": \"the_id\", \"types\": [\"aaa\", \"bbb\"]}")) .execute(); Iterable result = db.query(new OSQLSynchQuery<Object>("SELECT * FROM i_have_a_list WHERE types = 'aaa'")); assertTrue(result.iterator().hasNext()); db.command( new OCommandSQL( "UPDATE i_have_a_list CONTENT {\"id\": \"the_id\", \"types\": [\"ccc\", \"bbb\"]} WHERE id = 'the_id'")) .execute(); result = db.query(new OSQLSynchQuery<Object>("SELECT * FROM i_have_a_list WHERE types = 'ccc'")); assertTrue(result.iterator().hasNext()); result = db.query(new OSQLSynchQuery<Object>("SELECT * FROM i_have_a_list WHERE types = 'aaa'")); assertFalse(result.iterator().hasNext()); } finally { db.close(); } }
public ODatabaseDocumentTx createNewResource( final String iDatabaseName, final String... iAdditionalArgs) { if (iAdditionalArgs.length < 2) throw new OSecurityAccessException("Username and/or password missed"); final String path = OServerMain.server().getStoragePath(iDatabaseName); final ODatabaseDocumentTx db = new ODatabaseDocumentTx(path); if (path.startsWith(OEngineMemory.NAME)) { // CREATE AND PUT IN THE MEMORY MAPTABLE TO AVOID // LOCKING // (IT'S // THREAD SAFE) db.create(); OServerMain.server().getMemoryDatabases().put(iDatabaseName, db); } else db.open(iAdditionalArgs[0], iAdditionalArgs[1]); return db; }
@Test public void testUpsertSetPut() throws Exception { final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLUpdateUpsertSetPut"); db.create(); try { db.command(new OCommandSQL("CREATE CLASS test")).execute(); db.command(new OCommandSQL("CREATE PROPERTY test.id integer")).execute(); db.command(new OCommandSQL("CREATE PROPERTY test.addField EMBEDDEDSET string")).execute(); db.command( new OCommandSQL("UPDATE test SET id = 1 ADD addField=\"xxxx\" UPSERT WHERE id = 1")) .execute(); Iterable result = db.query(new OSQLSynchQuery<Object>("select from test")); ODocument doc = (ODocument) result.iterator().next(); Set<?> set = doc.field("addField"); assertEquals(set.size(), 1); } finally { db.close(); } }
@Test public void testNamedParamsSyntax() { // issue #4470 String className = getClass().getSimpleName() + "_NamedParamsSyntax"; final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + className); db.create(); try { db.command(new OCommandSQL("create class " + className)).execute(); Map<String, Object> params = new HashMap<String, Object>(); params.put("name", "foo"); params.put("full_name", "foo"); params.put("html_url", "foo"); params.put("description", "foo"); params.put("git_url", "foo"); params.put("ssh_url", "foo"); params.put("clone_url", "foo"); params.put("svn_url", "foo"); OCommandSQL sql1 = new OCommandSQL( "update " + className + " SET name = :name, full_name = :full_name, html_url = :html_url, description = :description, " + "git_url = :git_url, ssh_url = :ssh_url, clone_url = :clone_url, svn_url = :svn_url" + "UPSERT WHERE full_name = :full_name"); db.command(sql1).execute(params); OCommandSQL sql2 = new OCommandSQL( "update " + className + " SET name = :name, html_url = :html_url, description = :description, " + "git_url = :git_url, ssh_url = :ssh_url, clone_url = :clone_url, svn_url = :svn_url" + "UPSERT WHERE full_name = :full_name"); db.command(sql2).execute(params); } finally { db.close(); } }
@BeforeClass public void beforeClass() { buildDirectory = System.getProperty("buildDirectory"); if (buildDirectory == null) buildDirectory = "."; databaseDocumentTx = new ODatabaseDocumentTx("plocal:" + buildDirectory + "/localSBTreeBigValuesTest"); if (databaseDocumentTx.exists()) { databaseDocumentTx.open("admin", "admin"); databaseDocumentTx.drop(); } databaseDocumentTx.create(); sbTree = new OSBTree<Integer, byte[]>( "sbTree", ".sbt", false, ".nbt", (OAbstractPaginatedStorage) databaseDocumentTx.getStorage()); sbTree.create(OIntegerSerializer.INSTANCE, OBinaryTypeSerializer.INSTANCE, null, 1, false); }
@Override @Test(enabled = false) public void init() throws Exception { String buildDirectory = System.getProperty("buildDirectory", "."); if (buildDirectory == null) buildDirectory = "."; databaseDocumentTx = new ODatabaseDocumentTx("local:" + buildDirectory + "/uniqueHashIndexTest"); if (databaseDocumentTx.exists()) { databaseDocumentTx.open("admin", "admin"); databaseDocumentTx.drop(); } databaseDocumentTx.create(); long maxMemory = 2L * 1024 * 1024 * 1024; System.out.println("Max memory :" + maxMemory); buffer = new O2QCache( maxMemory, 15000, ODirectMemoryFactory.INSTANCE.directMemory(), null, OHashIndexBucket.MAX_BUCKET_SIZE_BYTES, (OStorageLocal) databaseDocumentTx.getStorage(), false); hashIndex = new OUniqueHashIndex(); hashIndex.create( "uhashIndexTest", new OSimpleKeyIndexDefinition(OType.STRING), databaseDocumentTx, OMetadata.CLUSTER_INDEX_NAME, new int[0], null); }
public static void createDB(final String inputSrc) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { // TODO Auto-generated method stub final String url = "memory:/tmp/moneyScript"; final ODatabaseDocumentTx db = new ODatabaseDocumentTx(url); db.create(); // db.open("admin", "admin"); final String CLUSTER_NAME = "test"; db.addPhysicalCluster(CLUSTER_NAME); final GZIPInputStream input = new GZIPInputStream(new FileInputStream(inputSrc)); try { final OrientDAL rdr = new OrientDAL(); rdr.loadOrientDB(db, input); } finally { input.close(); db.commit(); // db.close(); // db.delete(); } WicketApplication.db = db; }
@Test public void testUpdateRemoveAll() throws Exception { final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLUpdateTest"); db.create(); db.command(new OCommandSQL("CREATE class company")).execute(); db.command(new OCommandSQL("CREATE property company.name STRING")).execute(); db.command(new OCommandSQL("CREATE class employee")).execute(); db.command(new OCommandSQL("CREATE property employee.name STRING")).execute(); db.command(new OCommandSQL("CREATE property company.employees LINKSET employee")).execute(); db.command(new OCommandSQL("INSERT INTO company SET name = 'MyCompany'")).execute(); final ODocument r = (ODocument) db.query(new OSQLSynchQuery<Object>("SELECT FROM company")).get(0); db.command(new OCommandSQL("INSERT INTO employee SET name = 'Philipp'")).execute(); db.command(new OCommandSQL("INSERT INTO employee SET name = 'Selma'")).execute(); db.command(new OCommandSQL("INSERT INTO employee SET name = 'Thierry'")).execute(); db.command(new OCommandSQL("INSERT INTO employee SET name = 'Linn'")).execute(); db.command(new OCommandSQL("UPDATE company ADD employees = (SELECT FROM employee)")).execute(); r.reload(); assertEquals(((Set) r.field("employees")).size(), 4); db.command( new OCommandSQL( "UPDATE company REMOVE employees = (SELECT FROM employee WHERE name = 'Linn') WHERE name = 'MyCompany'")) .execute(); r.reload(); assertEquals(((Set) r.field("employees")).size(), 3); db.close(); }
@BeforeClass public void beforeClass() throws Exception { db = new ODatabaseDocumentTx(DB_STORAGE + ":" + DB_NAME); db.create(); getProfilerInstance().startRecording(); db.command(new OCommandSQL("CREATE class foo")).execute(); db.command(new OCommandSQL("CREATE property foo.name STRING")).execute(); db.command(new OCommandSQL("CREATE property foo.bar INTEGER")).execute(); db.command(new OCommandSQL("CREATE property foo.address EMBEDDED")).execute(); db.command(new OCommandSQL("CREATE property foo.comp STRING")).execute(); db.command(new OCommandSQL("CREATE property foo.osite INTEGER")).execute(); db.command(new OCommandSQL("CREATE index foo_name on foo (name) NOTUNIQUE")).execute(); db.command(new OCommandSQL("CREATE index foo_bar on foo (bar) NOTUNIQUE")).execute(); db.command(new OCommandSQL("CREATE index foo_comp_osite on foo (comp, osite) NOTUNIQUE")) .execute(); db.command( new OCommandSQL( "insert into foo (name, bar, address) values ('a', 1, {'street':'1st street', 'city':'NY', '@type':'d'})")) .execute(); db.command(new OCommandSQL("insert into foo (name, bar) values ('b', 2)")).execute(); db.command(new OCommandSQL("insert into foo (name, bar) values ('c', 3)")).execute(); db.command(new OCommandSQL("insert into foo (comp, osite) values ('a', 1)")).execute(); db.command(new OCommandSQL("insert into foo (comp, osite) values ('b', 2)")).execute(); db.command(new OCommandSQL("CREATE class bar")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('a', 1)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('b', 2)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('c', 3)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('d', 4)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('e', 5)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('f', 1)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('g', 2)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('h', 3)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('i', 4)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('j', 5)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('k', 1)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('l', 2)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('m', 3)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('n', 4)")).execute(); db.command(new OCommandSQL("insert into bar (name, foo) values ('o', 5)")).execute(); db.command(new OCommandSQL("CREATE class ridsorttest")).execute(); db.command(new OCommandSQL("CREATE property ridsorttest.name INTEGER")).execute(); db.command(new OCommandSQL("CREATE index ridsorttest_name on ridsorttest (name) NOTUNIQUE")) .execute(); db.command(new OCommandSQL("insert into ridsorttest (name) values (1)")).execute(); db.command(new OCommandSQL("insert into ridsorttest (name) values (5)")).execute(); db.command(new OCommandSQL("insert into ridsorttest (name) values (3)")).execute(); db.command(new OCommandSQL("insert into ridsorttest (name) values (4)")).execute(); db.command(new OCommandSQL("insert into ridsorttest (name) values (1)")).execute(); db.command(new OCommandSQL("insert into ridsorttest (name) values (8)")).execute(); db.command(new OCommandSQL("insert into ridsorttest (name) values (6)")).execute(); db.command(new OCommandSQL("CREATE class unwindtest")).execute(); db.command( new OCommandSQL("insert into unwindtest (name, coll) values ('foo', ['foo1', 'foo2'])")) .execute(); db.command( new OCommandSQL("insert into unwindtest (name, coll) values ('bar', ['bar1', 'bar2'])")) .execute(); db.command(new OCommandSQL("CREATE class edge")).execute(); db.command(new OCommandSQL("CREATE class TestFromInSquare")).execute(); db.command( new OCommandSQL( "insert into TestFromInSquare set tags = {' from ':'foo',' to ':'bar'}")) .execute(); db.command(new OCommandSQL("CREATE class TestMultipleClusters")).execute(); db.command( new OCommandSQL("alter class TestMultipleClusters addcluster testmultipleclusters1 ")) .execute(); db.command( new OCommandSQL("alter class TestMultipleClusters addcluster testmultipleclusters2 ")) .execute(); db.command(new OCommandSQL("insert into cluster:testmultipleclusters set name = 'aaa'")) .execute(); db.command(new OCommandSQL("insert into cluster:testmultipleclusters1 set name = 'foo'")) .execute(); db.command(new OCommandSQL("insert into cluster:testmultipleclusters2 set name = 'bar'")) .execute(); db.command(new OCommandSQL("CREATE class TestUrl")).execute(); db.command( new OCommandSQL("insert into TestUrl content { \"url\": \"http://www.google.com\" }")) .execute(); db.command(new OCommandSQL("CREATE class TestParams")).execute(); db.command( new OCommandSQL( "insert into TestParams set name = 'foo', surname ='foo', active = true")) .execute(); db.command( new OCommandSQL( "insert into TestParams set name = 'foo', surname ='bar', active = false")) .execute(); db.command(new OCommandSQL("CREATE class TestParamsEmbedded")).execute(); db.command( new OCommandSQL( "insert into TestParamsEmbedded set emb = { \n" + " \"count\":0,\n" + " \"testupdate\":\"1441258203385\"\n" + " }")) .execute(); db.command( new OCommandSQL( "insert into TestParamsEmbedded set emb = { \n" + " \"count\":1,\n" + " \"testupdate\":\"1441258203385\"\n" + " }")) .execute(); db.command(new OCommandSQL("CREATE class TestBacktick")).execute(); db.command(new OCommandSQL("insert into TestBacktick set foo = 1, bar = 2, `foo-bar` = 10")) .execute(); // /*** from issue #2743 OSchema schema = db.getMetadata().getSchema(); if (!schema.existsClass("alphabet")) { schema.createClass("alphabet"); } ORecordIteratorClass<ODocument> iter = db.browseClass("alphabet"); while (iter.hasNext()) { iter.next().delete(); } // add 26 entries: { "letter": "A", "number": 0 }, ... { "letter": "Z", "number": 25 } String rowModel = "{\"letter\": \"%s\", \"number\": %d}"; for (int i = 0; i < 26; ++i) { String l = String.valueOf((char) ('A' + i)); String json = String.format(rowModel, l, i); ODocument doc = db.newInstance("alphabet"); doc.fromJSON(json); doc.save(); } db.command(new OCommandSQL("create class OCommandExecutorSQLSelectTest_aggregations")) .execute(); db.command( new OCommandSQL( "insert into OCommandExecutorSQLSelectTest_aggregations set data = [{\"size\": 0}, {\"size\": 0}, {\"size\": 30}, {\"size\": 50}, {\"size\": 50}]")) .execute(); initExpandSkipLimit(db); initMassiveOrderSkipLimit(db); initDatesSet(db); initMatchesWithRegex(db); initDistinctLimit(db); }
@BeforeClass public void init() { ODatabaseDocumentTx database = new ODatabaseDocumentTx(url); if ("memory:test".equals(database.getURL())) database.create(); }