Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes index value validation customizable per IndexAccessor
Instead of having on global static tailored to lucene. This allows native indexes to have their own validation.
- Loading branch information
Showing
53 changed files
with
876 additions
and
465 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
47 changes: 0 additions & 47 deletions
47
community/kernel/src/main/java/org/neo4j/kernel/impl/api/IndexSimpleValueValidator.java
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
community/kernel/src/main/java/org/neo4j/kernel/impl/api/IndexTextValueLengthValidator.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,72 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.impl.api; | |||
|
|||
import org.neo4j.kernel.impl.util.Validator; | |||
import org.neo4j.values.storable.TextValue; | |||
import org.neo4j.values.storable.Value; | |||
import org.neo4j.values.storable.Values; | |||
|
|||
/** | |||
* Validates {@link TextValue text values} so that they are within a certain length, byte-wise. | |||
*/ | |||
public class IndexTextValueLengthValidator implements Validator<Value> | |||
{ | |||
private final int maxByteLength; | |||
private final int checkThreshold; | |||
|
|||
public IndexTextValueLengthValidator( int maxByteLength ) | |||
{ | |||
this.maxByteLength = maxByteLength; | |||
|
|||
// This check threshold is for not having to check every value that comes in, only those that may have a chance to exceed the max length. | |||
// The value 5 comes from a safer 4, which is the number of bytes that a max size UTF-8 code point needs. | |||
this.checkThreshold = maxByteLength / 5; | |||
} | |||
|
|||
@Override | |||
public void validate( Value value ) | |||
{ | |||
if ( value == null || value == Values.NO_VALUE ) | |||
{ | |||
throw new IllegalArgumentException( "Null value" ); | |||
} | |||
if ( Values.isTextValue( value ) && ((TextValue)value).length() >= checkThreshold ) | |||
{ | |||
validate( ((TextValue)value).stringValue().getBytes() ); | |||
} | |||
} | |||
|
|||
public void validate( byte[] encodedValue ) | |||
{ | |||
if ( encodedValue == null ) | |||
{ | |||
throw new IllegalArgumentException( "Null value" ); | |||
} | |||
|
|||
int byteLength = encodedValue.length; | |||
if ( byteLength > maxByteLength ) | |||
{ | |||
throw new IllegalArgumentException( "Property value bytes length: " + byteLength + | |||
" is longer than " + maxByteLength + ", which is maximum supported length" + | |||
" of indexed property value." ); | |||
} | |||
} | |||
} |
44 changes: 0 additions & 44 deletions
44
community/kernel/src/main/java/org/neo4j/kernel/impl/api/IndexValueValidator.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.