Java Code Examples for com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx#exists()
The following examples show how to use
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx#exists() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportDataFromJson.java From orientdb-lucene with Apache License 2.0 | 6 votes |
@Test public void importAllFiles() { ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:databases/us_pacific"); if (!db.exists()) { db.create(); } else { db.open("admin", "admin"); } try { importGeometry(db, "/Volumes/MACCHI/spatialIndex/us-pacific/us-pacific-latest_points.json", "Points", "OPoint"); importGeometry(db, "/Volumes/MACCHI/spatialIndex/us-pacific/us-pacific-latest_lines.json", "Lines", "OLineString"); importGeometry(db, "/Volumes/MACCHI/spatialIndex/us-pacific/us-pacific-latest_multipolygons.json", "MultiPolygons", "OMultipolygon"); importGeometry(db, "/Volumes/MACCHI/spatialIndex/us-pacific/us-pacific-latest_multilinestrings.json", "MultiLineStrings", "OMultiLineString"); importGeometry(db, "/Volumes/MACCHI/spatialIndex/us-pacific/us-pacific-latest_other_relations.json", "GeometryCollections", "OGeometryCollection"); } catch (IOException e1) { e1.printStackTrace(); } }
Example 2
Source File: BaseRemoteLuceneTest.java From orientdb-lucene with Apache License 2.0 | 6 votes |
@Test(enabled = false) public void initDB() { try { server = OServerMain.create(); server.startup(ClassLoader.getSystemResourceAsStream("orientdb-server-config.xml")); server.activate(); } catch (Exception e) { e.printStackTrace(); } databaseDocumentTx = new ODatabaseDocumentTx(url); if (!databaseDocumentTx.exists()) { databaseDocumentTx = Orient.instance().getDatabaseFactory().createDatabase("graph", url); databaseDocumentTx.create(); } else { databaseDocumentTx.open("admin", "admin"); } }
Example 3
Source File: DatabaseManagerSupport.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public ODatabaseDocumentTx connect(final String name, final boolean create) { checkNotNull(name); ensureStarted(); String uri = connectionUri(name); ODatabaseDocumentTx db = new ODatabaseDocumentTx(uri); if (db.exists()) { db.open(SYSTEM_USER, SYSTEM_PASSWORD); log.debug("Opened database: {} -> {}", name, db); } else { if (create) { db.create(); log.debug("Created database: {} -> {}", name, db); // invoke created callback try { created(db, name); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } } else { log.debug("Database does not exist: {}", name); } } return db; }
Example 4
Source File: CreateCityDb.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override @Test(enabled = false) public void init() throws Exception { String buildDirectory = System.getProperty("buildDirectory", "."); if (buildDirectory == null) buildDirectory = "."; String uri = "plocal:" + buildDirectory + "/databases/city"; databaseDocumentTx = new ODatabaseDocumentTx(uri); if (databaseDocumentTx.exists()) { databaseDocumentTx.open("admin", "admin"); databaseDocumentTx.drop(); } databaseDocumentTx.create(); OSchema schema = databaseDocumentTx.getMetadata().getSchema(); if (schema.getClass("City") == null) { OClass oClass = schema.createClass("City"); oClass.createProperty("latitude", OType.DOUBLE); oClass.createProperty("longitude", OType.DOUBLE); oClass.createProperty("name", OType.STRING); oClass.createIndex("City.name", "FULLTEXT", null, null, "LUCENE", new String[] { "name" }); oClass.createIndex("City.lat_lng", "SPATIAL", null, null, "LUCENE", new String[] { "latitude", "longitude" }); } ZipFile zipFile = new ZipFile("files/allCountries.zip"); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().equals("allCountries.txt")) { InputStream stream = zipFile.getInputStream(entry); lineReader = new LineNumberReader(new InputStreamReader(stream)); } } databaseDocumentTx.declareIntent(new OIntentMassiveInsert()); }
Example 5
Source File: CreateLocationDb.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override @Test(enabled = false) public void init() throws Exception { String buildDirectory = System.getProperty("buildDirectory", "."); if (buildDirectory == null) buildDirectory = "."; databaseDocumentTx = new ODatabaseDocumentTx("plocal:" + buildDirectory + "/location"); if (databaseDocumentTx.exists()) { databaseDocumentTx.open("admin", "admin"); databaseDocumentTx.drop(); } databaseDocumentTx.create(); OSchema schema = databaseDocumentTx.getMetadata().getSchema(); OClass oClass = schema.createClass("City"); oClass.createProperty("latitude", OType.DOUBLE); oClass.createProperty("longitude", OType.DOUBLE); oClass.createProperty("name", OType.STRING); oClass.createIndex("City.latitude_longitude", "SPATIAL", null, null, "LUCENE", new String[] { "latitude", "longitude" }); oClass.createIndex("City.name", "FULLTEXT", null, null, "LUCENE", new String[] { "name" }); ZipFile zipFile = new ZipFile("files/location.csv.zip"); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().equals("location.csv")) { InputStream stream = zipFile.getInputStream(entry); reader = new CSVReader(new InputStreamReader(stream), ','); } } }
Example 6
Source File: LuceneInsertMultithreadTest.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Test public void testConcurrentInsertWithIndex() throws Exception { databaseDocumentTx = new ODatabaseDocumentTx(url); if (!url.contains("remote:") && databaseDocumentTx.exists()) { databaseDocumentTx.open("admin", "admin"); databaseDocumentTx.drop(); databaseDocumentTx.create(); } else { databaseDocumentTx.create(); } OSchema schema = databaseDocumentTx.getMetadata().getSchema(); if (schema.getClass("City") == null) { OClass oClass = schema.createClass("City"); oClass.createProperty("name", OType.STRING); oClass.createIndex("City.name", "FULLTEXT", null, null, "LUCENE", new String[] { "name" }); } Thread[] threads = new Thread[THREADS + RTHREADS]; for (int i = 0; i < THREADS; ++i) threads[i] = new Thread(new LuceneInsertThread(CYCLE), "ConcurrentWriteTest" + i); for (int i = THREADS; i < THREADS + RTHREADS; ++i) threads[i] = new Thread(new LuceneReadThread(CYCLE), "ConcurrentReadTest" + i); for (int i = 0; i < THREADS + RTHREADS; ++i) threads[i].start(); for (int i = 0; i < THREADS + RTHREADS; ++i) threads[i].join(); OIndex idx = schema.getClass("City").getClassIndex("City.name"); Assert.assertEquals(idx.getSize(), THREADS * CYCLE); databaseDocumentTx.drop(); }
Example 7
Source File: OrientDBDaoTest.java From divide with Apache License 2.0 | 5 votes |
@Before public void setUp() { db = new ODatabaseDocumentTx(OrientDBDao.DEFAULT_CONFIG); if(db.exists()){ db.open("admin","admin"); } else { db.create(); } dao = new OrientDBDao(db); super.setUp(); }
Example 8
Source File: OrientDbLoader.java From nextreports-server with Apache License 2.0 | 5 votes |
@Override public void init() { log.debug("Init loader"); documentDatabase = new ODatabaseDocumentTx(dbUrl, false); String databaseName = documentDatabase.getName(); if (documentDatabase.exists() && dbAutoDropIfExists) { log.debug("Dropping existent database '{}'", databaseName); documentDatabase.open(dbUser, dbPassword).drop(); } if (documentDatabase.exists()) { log.debug("Open database '{}'", databaseName); documentDatabase.open(dbUser, dbPassword); if ((className != null) && autoDropClass) { OSchema schema = documentDatabase.getMetadata().getSchema(); if (schema.existsClass(className)) { log.debug("Dropping class '{}'", className); documentDatabase.command(new OCommandSQL("DELETE FROM " + className)).execute(); schema.dropClass(className); } } } else { long time = System.currentTimeMillis(); log.debug("Create database '{}'", databaseName); documentDatabase.create(); time = System.currentTimeMillis() - time; log.debug("Created database '{}' in {} ms", databaseName, time); } documentDatabase.declareIntent(new OIntentMassiveInsert()); }
Example 9
Source File: OOrientDBLoader.java From orientdb-etl with Apache License 2.0 | 4 votes |
@Override public void configure(final OETLProcessor iProcessor, final ODocument iConfiguration, final OCommandContext iContext) { super.configure(iProcessor, iConfiguration, iContext); if (iConfiguration.containsField("dbURL")) dbURL = (String) resolve(iConfiguration.field("dbURL")); if (iConfiguration.containsField("dbUser")) dbUser = (String) resolve(iConfiguration.field("dbUser")); if (iConfiguration.containsField("dbPassword")) dbPassword = (String) resolve(iConfiguration.field("dbPassword")); if (iConfiguration.containsField("dbType")) dbType = DB_TYPE.valueOf(iConfiguration.field("dbType").toString().toUpperCase()); if (iConfiguration.containsField("tx")) tx = (Boolean) iConfiguration.field("tx"); if (iConfiguration.containsField("wal")) wal = (Boolean) iConfiguration.field("wal"); if (iConfiguration.containsField("txUseLog")) txUseLog = (Boolean) iConfiguration.field("txUseLog"); if (iConfiguration.containsField("batchCommit")) batchCommit = (Integer) iConfiguration.field("batchCommit"); if (iConfiguration.containsField("dbAutoCreate")) dbAutoCreate = (Boolean) iConfiguration.field("dbAutoCreate"); if (iConfiguration.containsField("dbAutoDropIfExists")) dbAutoDropIfExists = (Boolean) iConfiguration.field("dbAutoDropIfExists"); if (iConfiguration.containsField("dbAutoCreateProperties")) dbAutoCreateProperties = (Boolean) iConfiguration.field("dbAutoCreateProperties"); if (iConfiguration.containsField("useLightweightEdges")) useLightweightEdges = (Boolean) iConfiguration.field("useLightweightEdges"); if (iConfiguration.containsField("standardElementConstraints")) standardElementConstraints = (Boolean) iConfiguration.field("standardElementConstraints"); clusterName = iConfiguration.field("cluster"); className = iConfiguration.field("class"); indexes = iConfiguration.field("indexes"); classes = iConfiguration.field("classes"); if (iConfiguration.containsField("settings")) { final ODocument settings = (ODocument) iConfiguration.field("settings"); settings.setAllowChainedAccess(false); for (String s : settings.fieldNames()) { final OGlobalConfiguration v = OGlobalConfiguration.findByKey(s); if (v != null) v.setValue(settings.field(s)); } } if (!wal) OGlobalConfiguration.USE_WAL.setValue(wal); switch (dbType) { case DOCUMENT: final ODatabaseDocumentTx documentDatabase = new ODatabaseDocumentTx(dbURL); if (documentDatabase.exists() && dbAutoDropIfExists) { log(OETLProcessor.LOG_LEVELS.INFO, "Dropping existent database '%s'...", dbURL); documentDatabase.open(dbUser, dbPassword); documentDatabase.drop(); } if (documentDatabase.exists()) { log(OETLProcessor.LOG_LEVELS.DEBUG, "Opening database '%s'...", dbURL); documentDatabase.open(dbUser, dbPassword); } else if (dbAutoCreate) { documentDatabase.create(); } else throw new IllegalArgumentException("Database '" + dbURL + "' not exists and 'dbAutoCreate' setting is false"); documentDatabase.close(); break; case GRAPH: final OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword); if (dbAutoDropIfExists && factory.exists()) { log(OETLProcessor.LOG_LEVELS.INFO, "Dropping existent database '%s'...", dbURL); factory.drop(); } final OrientBaseGraph graphDatabase = tx ? factory.getTx() : factory.getNoTx(); graphDatabase.shutdown(); break; } }