public final void updateSchema() { if (db.isClosed()) { db.create(); } OSchema schema = db.getMetadata().getSchema(); for (String docType : DocumentTypes.getDocumentTypes()) { if (!schema.existsClass(docType)) { createDocType(schema, docType); } } if (!schema.existsClass("Signatures")) { createSignatureType(schema); } }
public OSchema getSchema() { return db.getMetadata().getSchema(); }
private OClass getAssetDbClass(final ODatabaseDocumentTx db) { OSchema schema = db.getMetadata().getSchema(); return schema.getClass(ASSET_CLASS); }
/** * 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)); } }); }
/** * 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); } }
public Set<Integer> getBlobClusterIds() { return getMetadata().getSchema().getBlobClusters(); }
public OEdge newLightweightEdge(String iClassName, OVertex from, OVertex to) { OClass clazz = getMetadata().getSchema().getClass(iClassName); OEdgeDelegate result = new OEdgeDelegate(from, to, clazz, iClassName); return result; }
@Override public void apply() throws Exception { withDatabaseAndClass(componentDatabaseInstance, BROWSE_NODE, (db, table) -> { db.getMetadata().getSchema().dropClass(BROWSE_NODE); }); } }
@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 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); } } } } }
@Override public int addBlobCluster(final String iClusterName, final Object... iParameters) { int id; if (!existsCluster(iClusterName)) { id = addCluster(iClusterName, iParameters); } else { id = getClusterIdByName(iClusterName); } getMetadata().getSchema().addBlobCluster(id); return id; }
private void createBucketNameIndex() { try (ODatabaseDocumentTx db = componentDatabaseInstance.get().connect()) { if (db.getMetadata().getIndexManager().getIndex(I_BUCKET_NAME_VERSION) == null) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(COMPONENT_CLASS); if (type != null) { type.createIndex(I_BUCKET_NAME_VERSION, INDEX_TYPE.NOTUNIQUE, new String[] { P_BUCKET, P_NAME, P_VERSION }); } } } } }
private void replaceStorage(ODatabaseDocumentTx db, final OStorage storage) { db.replaceStorage(storage); if (!db.isClosed()) { try { // reload metadata for active connections if old schema is gone if (db.getMetadata().getSchema().countClasses() == 0) { log.debug("Reloading metadata for {} as storage has changed", db.getName()); db.activateOnCurrentThread(); db.getMetadata().reload(); } } catch (Exception e) { log.warn("Problem reloading metadata for {}", db.getName(), e); } } }
/** * {@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} * 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); } }
@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); }
@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); } }); } }
public final void updateSchema() { if (db.isClosed()) { db.create(); } OSchema schema = db.getMetadata().getSchema(); for (String docType : DocumentTypes.getDocumentTypes()) { if (!schema.existsClass(docType)) { createDocType(schema, docType); } } if (!schema.existsClass("Signatures")) { createSignatureType(schema); } }
@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); }