1
0
Fork 0

remove code duplication

This commit is contained in:
Andrey Abramov 2018-03-30 16:01:00 +03:00
parent 10b338fa77
commit 2cca7a926b
3 changed files with 6 additions and 68 deletions

View File

@ -59,7 +59,6 @@
#include "RestServer/DatabaseFeature.h"
#include "RestServer/DatabasePathFeature.h"
#include "RestServer/ServerIdFeature.h"
#include "RestServer/ViewTypesFeature.h"
#include "StorageEngine/EngineSelectorFeature.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/LogicalView.h"
@ -2056,25 +2055,10 @@ TRI_vocbase_t* MMFilesEngine::openExistingDatabase(TRI_voc_tick_t id,
VPackSlice slice = builder.slice();
TRI_ASSERT(slice.isArray());
auto const* viewTypes =
application_features::ApplicationServer::getFeature<ViewTypesFeature>(
"ViewTypes");
for (auto const& it : VPackArrayIterator(slice)) {
// we found a view that is still active
LOG_TOPIC(TRACE, Logger::FIXME) << "processing view: " << it.toJson();
arangodb::velocypack::StringRef const type(it.get("type"));
auto const& dataSourceType = arangodb::LogicalDataSource::Type::emplace(type);
auto const& viewFactory = viewTypes->factory(dataSourceType);
if (!viewFactory) {
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_BAD_PARAMETER,
"no handler found for view type"
);
}
TRI_ASSERT(!it.get("id").isNone());
auto const viewPath = readPath(it);
@ -2086,12 +2070,10 @@ TRI_vocbase_t* MMFilesEngine::openExistingDatabase(TRI_voc_tick_t id,
);
}
auto view = viewFactory(*vocbase, it, false);
auto const view = LogicalView::create(*vocbase, it, false);
if (!view) {
auto const message =
"failed to instantiate view of type "
+ dataSourceType.name();
auto const message = "failed to instantiate view '" + name + "'";
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, message.c_str());
}

View File

@ -44,7 +44,6 @@
#include "RestHandler/RestHandlerCreator.h"
#include "RestServer/DatabasePathFeature.h"
#include "RestServer/ServerIdFeature.h"
#include "RestServer/ViewTypesFeature.h"
#include "RocksDBEngine/RocksDBAqlFunctions.h"
#include "RocksDBEngine/RocksDBBackgroundThread.h"
#include "RocksDBEngine/RocksDBCollection.h"
@ -1690,31 +1689,15 @@ TRI_vocbase_t* RocksDBEngine::openExistingDatabase(TRI_voc_tick_t id,
VPackSlice const slice = builder.slice();
TRI_ASSERT(slice.isArray());
auto const* viewTypes =
application_features::ApplicationServer::getFeature<ViewTypesFeature>(
"ViewTypes");
for (auto const& it : VPackArrayIterator(slice)) {
// we found a view that is still active
arangodb::velocypack::StringRef const type(it.get("type"));
auto const& dataSourceType = arangodb::LogicalDataSource::Type::emplace(type);
auto const& viewFactory = viewTypes->factory(dataSourceType);
if (!viewFactory) {
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_BAD_PARAMETER,
"no handler found for view type"
);
}
TRI_ASSERT(!it.get("id").isNone());
auto view = viewFactory(*vocbase, it, false);
auto const view = LogicalView::create(*vocbase, it, false);
if (!view) {
auto const message =
"failed to instantiate view of type "
+ dataSourceType.name();
auto const message = "failed to instantiate view '" + name + "'";
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, message.c_str());
}

View File

@ -54,7 +54,6 @@
#include "Replication/DatabaseReplicationApplier.h"
#include "Replication/InitialSyncer.h"
#include "RestServer/DatabaseFeature.h"
#include "RestServer/ViewTypesFeature.h"
#include "StorageEngine/EngineSelectorFeature.h"
#include "StorageEngine/PhysicalCollection.h"
#include "StorageEngine/StorageEngine.h"
@ -1596,37 +1595,11 @@ std::shared_ptr<arangodb::LogicalView> TRI_vocbase_t::createViewWorker(
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_ILLEGAL_NAME);
}
auto const type =
arangodb::basics::VelocyPackHelper::getStringRef(parameters, "type", "");
auto const* viewTypes =
application_features::ApplicationServer::getFeature<ViewTypesFeature>(
"ViewTypes");
if (!viewTypes) {
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL,
std::string("failed to find feature '") + arangodb::ViewTypesFeature::name() + "'"
);
}
auto const& dataSourceType = arangodb::LogicalDataSource::Type::emplace(type);
auto const& viewFactory = viewTypes->factory(dataSourceType);
if (!viewFactory) {
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_BAD_PARAMETER,
"no handler found for view type"
);
}
// Try to create a new view. This is not registered yet
auto view = viewFactory(*this, parameters, true);
auto const view = LogicalView::create(*this, parameters, true);
if (!view) {
auto const message =
"failed to instantiate view of type "
+ dataSourceType.name();
auto const message = "failed to instantiate view '" + name + "'";
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, message.c_str());
}