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
9 changed files
with
211 additions
and
6 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
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
90 changes: 90 additions & 0 deletions
90
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/ZonedTimeLayout.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,90 @@ | ||
/* | ||
* 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.index.schema; | ||
|
||
import java.util.Comparator; | ||
|
||
import org.neo4j.index.internal.gbptree.Layout; | ||
import org.neo4j.io.pagecache.PageCursor; | ||
import org.neo4j.kernel.api.schema.index.IndexDescriptor; | ||
|
||
/** | ||
* {@link Layout} for absolute times. | ||
*/ | ||
class ZonedTimeLayout extends BaseLayout<ZonedTimeSchemaKey> | ||
{ | ||
public static Layout<ZonedTimeSchemaKey,NativeSchemaValue> of( IndexDescriptor descriptor ) | ||
{ | ||
return descriptor.type() == IndexDescriptor.Type.UNIQUE ? ZonedTimeLayout.UNIQUE : ZonedTimeLayout.NON_UNIQUE; | ||
} | ||
|
||
private static final ZonedTimeLayout UNIQUE = new ZonedTimeLayout( "UTzt", 0, 1, ComparableNativeSchemaKey.UNIQUE() ); | ||
private static final ZonedTimeLayout NON_UNIQUE = new ZonedTimeLayout( "NTzt", 0, 1, ComparableNativeSchemaKey.NON_UNIQUE() ); | ||
|
||
private ZonedTimeLayout( | ||
String layoutName, int majorVersion, int minorVersion, Comparator<ZonedTimeSchemaKey> comparator ) | ||
{ | ||
super( layoutName, majorVersion, minorVersion, comparator ); | ||
} | ||
|
||
@Override | ||
public ZonedTimeSchemaKey newKey() | ||
{ | ||
return new ZonedTimeSchemaKey(); | ||
} | ||
|
||
@Override | ||
public ZonedTimeSchemaKey copyKey( ZonedTimeSchemaKey key, ZonedTimeSchemaKey into ) | ||
{ | ||
into.nanosOfDayUTC = key.nanosOfDayUTC; | ||
into.zoneOffsetSeconds = key.zoneOffsetSeconds; | ||
into.setEntityId( key.getEntityId() ); | ||
into.setCompareId( key.getCompareId() ); | ||
return into; | ||
} | ||
|
||
@Override | ||
public int keySize( ZonedTimeSchemaKey key ) | ||
{ | ||
return ZonedTimeSchemaKey.SIZE; | ||
} | ||
|
||
@Override | ||
public void writeKey( PageCursor cursor, ZonedTimeSchemaKey key ) | ||
{ | ||
cursor.putLong( key.nanosOfDayUTC ); | ||
cursor.putInt( key.zoneOffsetSeconds ); | ||
cursor.putLong( key.getEntityId() ); | ||
} | ||
|
||
@Override | ||
public void readKey( PageCursor cursor, ZonedTimeSchemaKey into, int keySize ) | ||
{ | ||
into.nanosOfDayUTC = cursor.getLong(); | ||
into.zoneOffsetSeconds = cursor.getInt(); | ||
into.setEntityId( cursor.getLong() ); | ||
} | ||
|
||
@Override | ||
public boolean fixedSize() | ||
{ | ||
return true; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/ZonedTimeSchemaKey.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,101 @@ | ||
/* | ||
* 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.index.schema; | ||
|
||
import java.time.ZoneOffset; | ||
|
||
import org.neo4j.values.storable.TimeValue; | ||
import org.neo4j.values.storable.Value; | ||
|
||
import static java.lang.String.format; | ||
|
||
/** | ||
* Includes value and entity id (to be able to handle non-unique values). A value can be any {@link TimeValue}. | ||
* | ||
* With these keys the TimeValues are sorted by UTC time of day, and then by time zone. | ||
*/ | ||
class ZonedTimeSchemaKey extends TemporalSchemaKey implements ComparableNativeSchemaKey<ZonedTimeSchemaKey> | ||
{ | ||
static final int SIZE = | ||
Long.BYTES + /* nanosOfDayUTC */ | ||
Integer.BYTES + /* zoneOffsetSeconds */ | ||
Long.BYTES; /* entityId */ | ||
|
||
long nanosOfDayUTC; | ||
int zoneOffsetSeconds; | ||
|
||
@Override | ||
public Value asValue() | ||
{ | ||
return TimeValue.time( nanosOfDayUTC, ZoneOffset.ofTotalSeconds( zoneOffsetSeconds ) ); | ||
} | ||
|
||
@Override | ||
public void initAsLowest() | ||
{ | ||
super.initAsLowest(); | ||
nanosOfDayUTC = Long.MIN_VALUE; | ||
zoneOffsetSeconds = Integer.MIN_VALUE; | ||
} | ||
|
||
@Override | ||
public void initAsHighest() | ||
{ | ||
super.initAsHighest(); | ||
nanosOfDayUTC = Long.MAX_VALUE; | ||
zoneOffsetSeconds = Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public int compareValueTo( ZonedTimeSchemaKey other ) | ||
{ | ||
int compare = Long.compare( nanosOfDayUTC, other.nanosOfDayUTC ); | ||
if ( compare == 0 ) | ||
{ | ||
compare = Integer.compare( zoneOffsetSeconds, other.zoneOffsetSeconds ); | ||
} | ||
return compare; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return format( "value=%s,entityId=%d,nanosOfDayUTC=%d,zoneOffsetSeconds=%d", | ||
asValue(), entityId, nanosOfDayUTC, zoneOffsetSeconds ); | ||
} | ||
|
||
@Override | ||
public void writeTime( long nanosOfDayUTC, int offsetSeconds ) | ||
{ | ||
this.nanosOfDayUTC = nanosOfDayUTC; | ||
this.zoneOffsetSeconds = offsetSeconds; | ||
} | ||
|
||
@Override | ||
protected Value assertCorrectType( Value value ) | ||
{ | ||
if ( !(value instanceof TimeValue) ) | ||
{ | ||
throw new IllegalArgumentException( | ||
"Key layout does only support TimeValue, tried to create key from " + value ); | ||
} | ||
return 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