-
Notifications
You must be signed in to change notification settings - Fork 871
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
535 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core/src/main/java/com/orientechnologies/orient/core/index/engine/IndexEngineValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.orientechnologies.orient.core.index.engine; | ||
|
||
/** | ||
* Put operation validator. | ||
* | ||
* @param <K> the key type. | ||
* @param <V> the value type. | ||
*/ | ||
public interface IndexEngineValidator<K, V> { | ||
|
||
/** | ||
* Indicates that a put request should be silently ignored by the store. | ||
* | ||
* @see #validate(Object, Object, Object) | ||
*/ | ||
Object IGNORE = new Object(); | ||
|
||
/** | ||
* Validates the put operation for the given key, the old value and the new value. May throw an | ||
* exception to abort the current put operation with an error. | ||
* | ||
* @param key the put operation key. | ||
* @param oldValue the old value or {@code null} if no value is currently stored. | ||
* @param newValue the new value passed to validatedPut(Object, OIdentifiable, Validator). | ||
* @return the new value to store, may differ from the passed one, or the special {@link #IGNORE} | ||
* value to silently ignore the put operation request being processed. | ||
*/ | ||
Object validate(K key, V oldValue, V newValue); | ||
} |
8 changes: 8 additions & 0 deletions
8
...ain/java/com/orientechnologies/orient/core/index/engine/IndexEngineValuesTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.orientechnologies.orient.core.index.engine; | ||
|
||
import com.orientechnologies.orient.core.id.ORID; | ||
import java.util.Collection; | ||
|
||
public interface IndexEngineValuesTransformer { | ||
Collection<ORID> transformFromValue(Object value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
.../main/java/com/orientechnologies/orient/core/index/engine/UniqueIndexEngineValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.orientechnologies.orient.core.index.engine; | ||
|
||
import com.orientechnologies.orient.core.id.ORID; | ||
import com.orientechnologies.orient.core.index.OIndexInternal; | ||
import com.orientechnologies.orient.core.index.OIndexUnique; | ||
import com.orientechnologies.orient.core.record.impl.ODocument; | ||
import com.orientechnologies.orient.core.storage.ORecordDuplicatedException; | ||
|
||
public class UniqueIndexEngineValidator implements IndexEngineValidator<Object, ORID> { | ||
|
||
/** */ | ||
private final OIndexUnique indexUnique; | ||
|
||
/** @param oIndexUnique */ | ||
public UniqueIndexEngineValidator(OIndexUnique oIndexUnique) { | ||
indexUnique = oIndexUnique; | ||
} | ||
|
||
@Override | ||
public Object validate(Object key, ORID oldValue, ORID newValue) { | ||
if (oldValue != null) { | ||
ODocument metadata = indexUnique.getMetadata(); | ||
// CHECK IF THE ID IS THE SAME OF CURRENT: THIS IS THE UPDATE CASE | ||
if (!oldValue.equals(newValue)) { | ||
final Boolean mergeSameKey = | ||
metadata != null ? (Boolean) metadata.field(OIndexInternal.MERGE_KEYS) : Boolean.FALSE; | ||
if (mergeSameKey == null || !mergeSameKey) { | ||
throw new ORecordDuplicatedException( | ||
String.format( | ||
"Cannot index record %s: found duplicated key '%s' in index '%s' previously assigned to the record %s", | ||
newValue.getIdentity(), key, indexUnique.getName(), oldValue.getIdentity()), | ||
indexUnique.getName(), | ||
oldValue.getIdentity(), | ||
key); | ||
} | ||
} else { | ||
return IndexEngineValidator.IGNORE; | ||
} | ||
} | ||
|
||
if (!newValue.getIdentity().isPersistent()) { | ||
newValue = newValue.getRecord().getIdentity(); | ||
} | ||
return newValue.getIdentity(); | ||
} | ||
} |
Oops, something went wrong.