Skip to content

Commit

Permalink
refactor: simplified logic of index engine factory
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 22, 2023
1 parent 2732067 commit cfdd41f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.orientechnologies.orient.core.index;

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.index.engine.OBaseIndexEngine;
import com.orientechnologies.orient.core.index.engine.v1.OCellBTreeIndexEngine;
Expand Down Expand Up @@ -140,15 +141,9 @@ public int getLastVersion(final String algorithm) {
}

@Override
public OBaseIndexEngine createIndexEngine(
int indexId,
String algorithm,
String name,
OStorage storage,
int version,
@SuppressWarnings("SpellCheckingInspection") boolean multiValue) {

if (algorithm == null) {
public OBaseIndexEngine createIndexEngine(OStorage storage, IndexEngineData data) {

if (data.getAlgorithm() == null) {
throw new OIndexException("Name of algorithm is not specified");
}
final OBaseIndexEngine indexEngine;
Expand All @@ -161,28 +156,30 @@ public OBaseIndexEngine createIndexEngine(
switch (storageType) {
case "memory":
case "plocal":
switch (algorithm) {
OAbstractPaginatedStorage realStorage = (OAbstractPaginatedStorage) storage;
switch (data.getAlgorithm()) {
case SBTREE_ALGORITHM:
indexEngine =
new OSBTreeIndexEngine(indexId, name, (OAbstractPaginatedStorage) storage, version);
new OSBTreeIndexEngine(
data.getIndexId(), data.getName(), realStorage, data.getVersion());
break;
case CELL_BTREE_ALGORITHM:
if (multiValue) {
if (data.isMultivalue()) {
indexEngine =
new OCellBTreeMultiValueIndexEngine(
indexId, name, (OAbstractPaginatedStorage) storage, version);
data.getIndexId(), data.getName(), realStorage, data.getVersion());
} else {
indexEngine =
new OCellBTreeSingleValueIndexEngine(
indexId, name, (OAbstractPaginatedStorage) storage, version);
data.getIndexId(), data.getName(), realStorage, data.getVersion());
}
break;
default:
throw new IllegalStateException("Invalid name of algorithm :'" + "'");
}
break;
case "remote":
indexEngine = new ORemoteIndexEngine(indexId, name);
indexEngine = new ORemoteIndexEngine(data.getIndexId(), data.getName());
break;
default:
throw new OIndexException("Unsupported storage type: " + storageType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.orientechnologies.orient.core.index;

import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.index.engine.OBaseIndexEngine;
import com.orientechnologies.orient.core.storage.OStorage;
Expand All @@ -43,11 +44,5 @@ public interface OIndexFactory {
*/
OIndexInternal createIndex(OStorage storage, OIndexMetadata im) throws OConfigurationException;

OBaseIndexEngine createIndexEngine(
int indexId,
String algorithm,
String name,
OStorage storage,
int version,
boolean multiValue);
OBaseIndexEngine createIndexEngine(OStorage storage, IndexEngineData data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,7 @@ public static OBaseIndexEngine createIndexEngine(
final OIndexFactory factory =
findFactoryByAlgorithmAndType(metadata.getAlgorithm(), metadata.getIndexType());

return factory.createIndexEngine(
metadata.getIndexId(),
metadata.getAlgorithm(),
metadata.getName(),
storage,
metadata.getVersion(),
metadata.isMultivalue());
return factory.createIndexEngine(storage, metadata);
}

public static String chooseDefaultIndexAlgorithm(String type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.orientechnologies.orient.core.sharding.auto;

import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.index.OIndexException;
import com.orientechnologies.orient.core.index.OIndexFactory;
Expand Down Expand Up @@ -110,33 +111,27 @@ public int getLastVersion(final String algorithm) {
}

@Override
public OBaseIndexEngine createIndexEngine(
int indexId,
final String algorithm,
final String name,
final OStorage storage,
final int version,
boolean multiValue) {

public OBaseIndexEngine createIndexEngine(OStorage storage, IndexEngineData data) {
final OIndexEngine indexEngine;

final String storageType = storage.getType();
OAbstractPaginatedStorage realStorage = (OAbstractPaginatedStorage) storage;
switch (storageType) {
case "memory":
case "plocal":
indexEngine =
new OAutoShardingIndexEngine(
name, indexId, (OAbstractPaginatedStorage) storage, version);
data.getName(), data.getIndexId(), realStorage, data.getVersion());
break;
case "distributed":
// DISTRIBUTED CASE: HANDLE IT AS FOR LOCAL
indexEngine =
new OAutoShardingIndexEngine(
name, indexId, (OAbstractPaginatedStorage) storage, version);
data.getName(), data.getIndexId(), realStorage, data.getVersion());
break;
case "remote":
// MANAGE REMOTE SHARDED INDEX TO CALL THE INTERESTED SERVER
indexEngine = new ORemoteIndexEngine(indexId, name);
indexEngine = new ORemoteIndexEngine(data.getIndexId(), data.getName());
break;
default:
throw new OIndexException("Unsupported storage type: " + storageType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.orientechnologies.orient.core.storage.index.hashindex.local;

import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.index.OIndexDictionary;
import com.orientechnologies.orient.core.index.OIndexException;
Expand Down Expand Up @@ -106,29 +107,26 @@ public final int getLastVersion(final String algorithm) {
}

@Override
public final OBaseIndexEngine createIndexEngine(
final int indexId,
final String algorithm,
final String name,
final OStorage storage,
final int version,
final boolean multiValue) {
public OBaseIndexEngine createIndexEngine(OStorage storage, IndexEngineData data) {
final OIndexEngine indexEngine;

final String storageType = storage.getType();
OAbstractPaginatedStorage realStorage = (OAbstractPaginatedStorage) storage;
switch (storageType) {
case "memory":
case "plocal":
indexEngine =
new OHashTableIndexEngine(name, indexId, (OAbstractPaginatedStorage) storage, version);
new OHashTableIndexEngine(
data.getName(), data.getIndexId(), realStorage, data.getVersion());
break;
case "distributed":
// DISTRIBUTED CASE: HANDLE IT AS FOR LOCAL
indexEngine =
new OHashTableIndexEngine(name, indexId, (OAbstractPaginatedStorage) storage, version);
new OHashTableIndexEngine(
data.getName(), data.getIndexId(), realStorage, data.getVersion());
break;
case "remote":
indexEngine = new ORemoteIndexEngine(indexId, name);
indexEngine = new ORemoteIndexEngine(data.getIndexId(), data.getName());
break;
default:
throw new OIndexException("Unsupported storage type: " + storageType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.orientechnologies.lucene.engine.OLuceneFullTextIndexEngine;
import com.orientechnologies.lucene.index.OLuceneFullTextIndex;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseInternal;
import com.orientechnologies.orient.core.db.ODatabaseLifecycleListener;
Expand Down Expand Up @@ -97,15 +98,8 @@ public OIndexInternal createIndex(OStorage storage, OIndexMetadata im)
}

@Override
public OBaseIndexEngine createIndexEngine(
int indexId,
String algorithm,
String indexName,
OStorage storage,
int version,
boolean multiValue) {

return new OLuceneFullTextIndexEngine(storage, indexName, indexId);
public OBaseIndexEngine createIndexEngine(OStorage storage, IndexEngineData data) {
return new OLuceneFullTextIndexEngine(storage, data.getName(), data.getIndexId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.serialization.types.OBinarySerializer;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.config.IndexEngineData;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseInternal;
import com.orientechnologies.orient.core.db.ODatabaseLifecycleListener;
Expand Down Expand Up @@ -116,15 +117,9 @@ public OIndexInternal createIndex(OStorage storage, OIndexMetadata im)
}

@Override
public OBaseIndexEngine createIndexEngine(
int indexId,
String algorithm,
String name,
OStorage storage,
int version,
boolean multiValue) {

return new OLuceneSpatialIndexEngineDelegator(indexId, name, storage, version);
public OBaseIndexEngine createIndexEngine(OStorage storage, IndexEngineData data) {
return new OLuceneSpatialIndexEngineDelegator(
data.getIndexId(), data.getName(), storage, data.getVersion());
}

@Override
Expand Down

0 comments on commit cfdd41f

Please sign in to comment.