diff --git a/enterprise/runtime/neole/src/main/java/org/neo4j/impl/store/prototype/neole/PropertyCursor.java b/enterprise/runtime/neole/src/main/java/org/neo4j/impl/store/prototype/neole/PropertyCursor.java index 2f1703aee9842..15aa2c45aa2fb 100644 --- a/enterprise/runtime/neole/src/main/java/org/neo4j/impl/store/prototype/neole/PropertyCursor.java +++ b/enterprise/runtime/neole/src/main/java/org/neo4j/impl/store/prototype/neole/PropertyCursor.java @@ -26,6 +26,7 @@ import org.neo4j.values.Values; import static org.neo4j.impl.store.prototype.neole.ReadStore.combineReference; +import static org.neo4j.impl.store.prototype.neole.ShortStringEncoding.ENCODINGS; class PropertyCursor extends org.neo4j.impl.store.prototype.PropertyCursor { @@ -108,6 +109,11 @@ void init( StoreFile properties, long reference ) @Override public boolean next() { + if ( block == Integer.MIN_VALUE ) + { + return false; + } + int nextBlock = block + blocksUsedByCurrent(); while ( nextBlock >= 0 && nextBlock < 4 ) { @@ -284,8 +290,13 @@ private int blocksUsedByCurrent() { int encoding = shortStringEncoding( valueBytes ); int stringLength = shortStringLength( valueBytes ); - return ShortStringEncoding.calculateNumberOfBlocksUsed( ShortStringEncoding.ENCODINGS[ encoding-1 ], - stringLength ); + + if ( encoding == ShortStringEncoding.ENCODING_UTF8 || encoding == ShortStringEncoding.ENCODING_LATIN1 ) + { + return ShortStringEncoding.numberOfBlocksUsedUTF8OrLatin1( stringLength ); + } + + return ShortStringEncoding.numberOfBlocksUsed( ENCODINGS[ encoding - 1 ], stringLength ); } return 1; } diff --git a/enterprise/runtime/neole/src/main/java/org/neo4j/impl/store/prototype/neole/ShortStringEncoding.java b/enterprise/runtime/neole/src/main/java/org/neo4j/impl/store/prototype/neole/ShortStringEncoding.java index c1c843ce01c0e..ad9ba57ee3af7 100644 --- a/enterprise/runtime/neole/src/main/java/org/neo4j/impl/store/prototype/neole/ShortStringEncoding.java +++ b/enterprise/runtime/neole/src/main/java/org/neo4j/impl/store/prototype/neole/ShortStringEncoding.java @@ -5,17 +5,17 @@ * 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. + * it under the terms of the GNU Affero 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. + * GNU Affero 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ package org.neo4j.impl.store.prototype.neole; @@ -784,14 +784,19 @@ private long rightOverflowMask( int step ) return mask; } - public static int calculateNumberOfBlocksUsed( ShortStringEncoding encoding, int length ) + public static int numberOfBlocksUsedUTF8OrLatin1( int length ) + { + return totalBits( length * 8 ); + } + + public static int numberOfBlocksUsed( ShortStringEncoding encoding, int length ) { return totalBits( length * encoding.step ); } private static int totalBits( int bitsForCharacters ) { - int bitsInTotal = 24 + 4 + 5 + 6 + bitsForCharacters; + int bitsInTotal = HEADER_SIZE + bitsForCharacters; return ((bitsInTotal - 1) >> 6) + 1; // /64 } } diff --git a/enterprise/runtime/neole/src/test/java/org/neo4j/impl/store/prototype/neole/PropertyCursorTest.java b/enterprise/runtime/neole/src/test/java/org/neo4j/impl/store/prototype/neole/PropertyCursorTest.java index e9854fc9a808b..17665f4c02df2 100644 --- a/enterprise/runtime/neole/src/test/java/org/neo4j/impl/store/prototype/neole/PropertyCursorTest.java +++ b/enterprise/runtime/neole/src/test/java/org/neo4j/impl/store/prototype/neole/PropertyCursorTest.java @@ -39,8 +39,9 @@ public class PropertyCursorTest { private static long bare, byteProp, shortProp, intProp, inlineLongProp, longProp, - floatProp, doubleProp, trueProp, falseProp, charProp, shortStringProp, allProps; + floatProp, doubleProp, trueProp, falseProp, charProp, shortStringProp, utf8Prop, allProps; + private static String chinese = "造Unicode之"; @ClassRule public static final GraphSetup graph = new GraphSetup() { @@ -65,6 +66,7 @@ protected void create( GraphDatabaseService graphDb ) charProp = createNodeWithProperty( graphDb, "charProp", 'x' ); shortStringProp = createNodeWithProperty( graphDb, "shortStringProp", "hello" ); + utf8Prop = createNodeWithProperty( graphDb, "utf8Prop", chinese ); Node all = graphDb.createNode(); // first property record @@ -83,6 +85,7 @@ protected void create( GraphDatabaseService graphDb ) all.setProperty( "charProp", 'x' ); all.setProperty( "shortStringProp", "hello" ); + all.setProperty( "utf8Prop", chinese ); allProps = all.getId(); @@ -135,6 +138,7 @@ public void shouldAccessSingleProperty() throws Exception assertAccessSingleProperty( falseProp, false ); assertAccessSingleProperty( charProp, 'x' ); assertAccessSingleProperty( shortStringProp, "hello" ); + assertAccessSingleProperty( utf8Prop, chinese ); } @Test @@ -167,8 +171,9 @@ public void shouldAccessAllNodeProperties() throws Exception assertTrue( "falseProp", values.contains( false ) ); assertTrue( "charProp", values.contains( 'x' ) ); assertTrue( "shortStringProp", values.contains( "hello" ) ); + assertTrue( "utf8Prop", values.contains( chinese ) ); - assertEquals( "number of values", 11, values.size() ); + assertEquals( "number of values", 12, values.size() ); } }