@Test public void testUpgradeSchema_TypeAlreadyExists() throws Exception { try (ODatabaseDocumentTx db = database.getInstance().connect()) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.createClass("key_store"); type.createProperty("test_property", OType.STRING); } service.upgradeSchema(); try (ODatabaseDocumentTx db = database.getInstance().connect()) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass("key_store"); assertThat(type, is(notNullValue())); assertThat(type.getProperty("test_property"), is(notNullValue())); assertThat(type.getProperty("name"), is(nullValue())); } }
public void upgradeSchema() throws Exception { log.debug("Updgrading schema for trust store"); try (ODatabaseDocumentTx db = databaseInstance.get().connect()) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(DB_CLASS); if (type == null) { type = schema.createClass(DB_CLASS); type.createProperty(P_NAME, OType.STRING).setMandatory(true).setNotNull(true); type.createProperty(P_BYTES, OType.BINARY).setMandatory(true).setNotNull(true); type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME); log.debug("Created schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } else { log.debug("Skipped creating existing schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } } }
LegacyKeyStoreUpgradeService extends ComponentSupport { public void upgradeSchema() throws Exception { log.debug("Updgrading schema for trust store"); try (ODatabaseDocumentTx db = databaseInstance.get().connect()) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(DB_CLASS); if (type == null) { type = schema.createClass(DB_CLASS); type.createProperty(P_NAME, OType.STRING).setMandatory(true).setNotNull(true); type.createProperty(P_BYTES, OType.BINARY).setMandatory(true).setNotNull(true); type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME); log.debug("Created schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } else { log.debug("Skipped creating existing schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } } } }
LegacyKeyStoreUpgradeService extends ComponentSupport { public void upgradeSchema() throws Exception { log.debug("Updgrading schema for trust store"); try (ODatabaseDocumentTx db = databaseInstance.get().connect()) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(DB_CLASS); if (type == null) { type = schema.createClass(DB_CLASS); type.createProperty(P_NAME, OType.STRING).setMandatory(true).setNotNull(true); type.createProperty(P_BYTES, OType.BINARY).setMandatory(true).setNotNull(true); type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME); log.debug("Created schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } else { log.debug("Skipped creating existing schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } } } @Inject  LegacyKeyStoreUpgradeService(@Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                                      final ApplicationDirectories appDirectories); }
LegacyKeyStoreUpgradeService extends ComponentSupport { public void upgradeSchema() throws Exception { log.debug("Updgrading schema for trust store"); try (ODatabaseDocumentTx db = databaseInstance.get().connect()) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(DB_CLASS); if (type == null) { type = schema.createClass(DB_CLASS); type.createProperty(P_NAME, OType.STRING).setMandatory(true).setNotNull(true); type.createProperty(P_BYTES, OType.BINARY).setMandatory(true).setNotNull(true); type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME); log.debug("Created schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } else { log.debug("Skipped creating existing schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } } } @Inject  LegacyKeyStoreUpgradeService(@Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                                      final ApplicationDirectories appDirectories); void upgradeSchema(); void importKeyStoreFiles(); void deleteKeyStoreFiles(); }
LegacyKeyStoreUpgradeService extends ComponentSupport { public void upgradeSchema() throws Exception { log.debug("Updgrading schema for trust store"); try (ODatabaseDocumentTx db = databaseInstance.get().connect()) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(DB_CLASS); if (type == null) { type = schema.createClass(DB_CLASS); type.createProperty(P_NAME, OType.STRING).setMandatory(true).setNotNull(true); type.createProperty(P_BYTES, OType.BINARY).setMandatory(true).setNotNull(true); type.createIndex(I_NAME, INDEX_TYPE.UNIQUE, P_NAME); log.debug("Created schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } else { log.debug("Skipped creating existing schema type {}: properties={}, indexes={}", type, type.properties(), type.getIndexes()); } } } @Inject  LegacyKeyStoreUpgradeService(@Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                                      final ApplicationDirectories appDirectories); void upgradeSchema(); void importKeyStoreFiles(); void deleteKeyStoreFiles();  }