Refine search
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url); if (db.getStorage().isRemote()) { isRemote = true; if (!isRemote) { if (newdb) { if (db.exists()) { db.open(user, password); LOG.info("OrientDB drop and recreate fresh db"); if (!db.getMetadata().getSchema().existsClass(CLASS)) { db.getMetadata().getSchema().createClass(CLASS);
@Override public void apply() throws Exception { try (ODatabaseDocumentTx db = componentDatabaseInstance.get().connect()) { if(db.getMetadata().getSchema().existsClass("assetdownloadcount")){ int updates = db.command(new OCommandSQL(UPDATE_ASSET_NAME)).execute(); if (updates > 0) { log.info("Updated {} records with null assetIds", updates); } } } } }
/** * Runs a {@link BiConsumer} of {@link ODatabaseDocumentTx} and {@link OClass} * if the specified {@code className} exists. */ protected static void withDatabaseAndClass(final Provider<DatabaseInstance> databaseInstance, final String className, final BiConsumer<ODatabaseDocumentTx, OClass> consumer) { withDatabase(databaseInstance, db -> { if (db.getMetadata().getSchema().existsClass(className)) { consumer.accept(db, db.getMetadata().getSchema().getClass(className)); } }); }
@Override public void apply() throws Exception { withDatabaseAndClass(componentDatabaseInstance, BROWSE_NODE, (db, table) -> { db.getMetadata().getSchema().dropClass(BROWSE_NODE); }); } }
period.setParentModel(db.getMetadata().getSchema().getClassByClusterId(parent.getClusterId()).getName());
/** * {@inheritDoc} * Check whether there exist a schema enforced over OrientDB document class. */ @Override public boolean schemaExists() throws GoraException { try (ODatabaseDocumentTx schemaTx = connectionPool.acquire()) { schemaTx.activateOnCurrentThread(); return schemaTx.getMetadata().getSchema() .existsClass(orientDBMapping.getDocumentClass()); } catch (Exception e) { throw new GoraException(e); } }
/** * {@inheritDoc} * Create a new class of OrientDB documents if necessary. Enforce specified schema over the document class. * */ @Override public void createSchema() throws GoraException { if (schemaExists()) { return; } try (ODatabaseDocumentTx schemaTx = connectionPool.acquire()) { schemaTx.activateOnCurrentThread(); OClass documentClass = schemaTx.getMetadata().getSchema().createClass(orientDBMapping.getDocumentClass()); documentClass.createProperty("_id", OType.getTypeByClass(super.getKeyClass())).createIndex(OClass.INDEX_TYPE.UNIQUE); for (String docField : orientDBMapping.getDocumentFields()) { documentClass.createProperty(docField, OType.valueOf(orientDBMapping.getDocumentFieldType(docField).name())); } schemaTx.getMetadata().getSchema().reload(); } catch (Exception e) { throw new GoraException(e); } }
/** * {@inheritDoc} * Deletes enforced schema over OrientDB Document class. */ @Override public void deleteSchema() throws GoraException { try (ODatabaseDocumentTx schemaTx = connectionPool.acquire()) { schemaTx.activateOnCurrentThread(); schemaTx.getMetadata().getSchema().dropClass(orientDBMapping.getDocumentClass()); } catch (Exception e) { throw new GoraException(e); } }
/** * Returns {@code true} if the given schema class exists, otherwise {@code false}. */ protected static boolean hasSchemaClass(final Provider<DatabaseInstance> databaseInstance, final String className) { try (ODatabaseDocumentTx db = databaseInstance.get().connect()) { return db.getMetadata().getSchema().existsClass(className); } }
@VisibleForTesting void upgradeSchemaToCaseInsensitiveName() { try (ODatabaseDocumentTx db = configDatabaseInstance.get().connect()) { OClass blobStoreClass = db.getMetadata().getSchema().getClass(DB_CLASS); blobStoreClass.getProperty(P_NAME).setCollate(new OCaseInsensitiveCollate()); } }
@Override public boolean dropCluster(final String iClusterName, final boolean iTruncate) { checkIfActive(); final int clusterId = getClusterIdByName(iClusterName); OSchemaProxy schema = metadata.getSchema(); OClass clazz = schema.getClassByClusterId(clusterId); if (clazz != null) clazz.removeClusterId(clusterId); if (schema.getBlobClusters().contains(clusterId)) schema.removeBlobCluster(iClusterName); getLocalCache().freeCluster(clusterId); checkForClusterPermissions(iClusterName); return getStorage().dropCluster(iClusterName, iTruncate); }
public OSharedContext init(OSharedContext shared) { schemaClusterId = database.getClusterIdByName(CLUSTER_INTERNAL_NAME); schema = new OSchemaProxy(shared.getSchema(), database); indexManager = new OIndexManagerProxy(shared.getIndexManager(), database); security = new OSecurityProxy(shared.getSecurity(), database); commandCache = shared.getCommandCache(); functionLibrary = new OFunctionLibraryProxy(shared.getFunctionLibrary(), database); sequenceLibrary = new OSequenceLibraryProxy(shared.getSequenceLibrary(), database); scheduler = new OSchedulerProxy(shared.getScheduler(), database); return shared; }
if (db.getMetadata().getSchema().existsClass("Config")) { List<ODocument> list = db.command(query).execute(); db.close();
if (documentDatabase.getMetadata().getSchema().existsClass(iClassName)) cls = documentDatabase.getMetadata().getSchema().getClass(iClassName); else { if (iSuperClass != null) { final OClass superClass = documentDatabase.getMetadata().getSchema().getClass(iSuperClass); if (superClass == null) throw new OLoaderException("Cannot find super class '" + iSuperClass + "'"); cls = documentDatabase.getMetadata().getSchema().createClass(iClassName, superClass); log(OETLProcessor.LOG_LEVELS.DEBUG, "- OrientDBLoader: created class '%s' extends '%s'", iClassName, iSuperClass); } else { cls = documentDatabase.getMetadata().getSchema().createClass(iClassName); log(OETLProcessor.LOG_LEVELS.DEBUG, "- OrientDBLoader: created class '%s'", iClassName); final OSchemaProxy schema = graphDatabase.getRawGraph().getMetadata().getSchema(); cls = schema.getClass(iClassName); if (cls == null) { final OClass superClass = graphDatabase.getRawGraph().getMetadata().getSchema().getClass(iSuperClass); if (superClass == null) throw new OLoaderException("Cannot find super class '" + iSuperClass + "'");
@Override public void apply() throws Exception { withDatabaseAndClass(componentDatabaseInstance, BROWSE_NODE, (db, table) -> { db.getMetadata().getSchema().dropClass(BROWSE_NODE); }); withDatabaseAndClass(componentDatabaseInstance, ASSET, (db, table) -> { if (!table.existsProperty(AssetEntityAdapter.P_CREATED_BY)) { table.createProperty(AssetEntityAdapter.P_CREATED_BY, OType.STRING); } if (!table.existsProperty(AssetEntityAdapter.P_CREATED_BY_IP)) { table.createProperty(AssetEntityAdapter.P_CREATED_BY_IP, OType.STRING); } }); } }
@Override public ILocation convertToEntity(ODocument document) { Location location = new Location(); location.setLongitude(document.field("longitude", Double.class)); location.setLatitude(document.field("latitude", Double.class)); location.setComment(document.field("comment", String.class)); // populate with data populateEntityWithBaseData(document, location); populateEntityWithCreatedModified(document, location); // parent ORecordId parent = document.field("parent", ORecordId.class); if (parent != null) { initDb(); location.setParentId(parent.getIdentity().toString()); location.setParentModel(db.getMetadata().getSchema().getClassByClusterId(parent.getClusterId()).getName()); //TODO: lazy load parent } // add distance, if set in document (added by some query results) if (document.field("$distance") != null) location.setDistance(document.field("$distance", Double.class)); return location; }
@Override public boolean dropCluster(final int iClusterId, final boolean iTruncate) { checkIfActive(); checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_DELETE, getClusterNameById(iClusterId)); OSchemaProxy schema = metadata.getSchema(); final OClass clazz = schema.getClassByClusterId(iClusterId); if (clazz != null) clazz.removeClusterId(iClusterId); getLocalCache().freeCluster(iClusterId); if (schema.getBlobClusters().contains(iClusterId)) schema.removeBlobCluster(getClusterNameById(iClusterId)); checkForClusterPermissions(getClusterNameById(iClusterId)); return getStorage().dropCluster(iClusterId, iTruncate); }
if (db.getMetadata().getSchema().existsClass("Config")) { List<ODocument> list = db.command(query).execute(); db.command(new OCommandSQL("DELETE FROM Config WHERE key = 'versionUpdate'")).execute();