/** * Verifies that a record's in use status is in line with the mode, might throw {@link InvalidRecordException}. */ public final boolean verify( AbstractBaseRecord record ) { boolean inUse = record.inUse(); if ( this == NORMAL & !inUse ) { throw new InvalidRecordException( record + " not in use" ); } return this == FORCE | inUse; }
/** * Any out of range value means a store corruption */ private static void checkValidNanoOfDay( long nanoOfDay ) { if ( nanoOfDay > LocalTime.MAX.toNanoOfDay() || nanoOfDay < LocalTime.MIN.toNanoOfDay() ) { throw new InvalidRecordException( "Nanosecond of day out of range:" + nanoOfDay ); } }
public static PropertyType getPropertyTypeOrThrow( long propBlock ) { PropertyType type = getPropertyTypeOrNull( propBlock ); if ( type == null ) { throw new InvalidRecordException( "Unknown property type for type " + typeIdentifier( propBlock ) ); } return type; }
@Override public ArrayValue decodeArray( Value dataValue ) { if ( dataValue instanceof LongArray ) { LongArray numbers = (LongArray) dataValue; LocalDateTime[] dateTimes = new LocalDateTime[numbers.length() / BLOCKS_LOCAL_DATETIME]; for ( int i = 0; i < dateTimes.length; i++ ) { long epochSecond = numbers.longValue( i * BLOCKS_LOCAL_DATETIME ); long nanoOfSecond = numbers.longValue( i * BLOCKS_LOCAL_DATETIME + 1 ); checkValidNanoOfSecond( nanoOfSecond ); dateTimes[i] = LocalDateTime.ofInstant( Instant.ofEpochSecond( epochSecond, nanoOfSecond ), UTC ); } return Values.localDateTimeArray( dateTimes ); } else { throw new InvalidRecordException( "Array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: LongArray." ); } } },
/** * Depending on the mode, this will - if a cursor error has been raised on the given {@link PageCursor} - either * throw an {@link InvalidRecordException} with the underlying {@link CursorException}, or clear the error condition * on the cursor. * @param cursor The {@link PageCursor} to be checked for errors. */ public final void clearOrThrowCursorError( PageCursor cursor ) { if ( this == NORMAL ) { try { cursor.checkAndClearCursorException(); } catch ( CursorException e ) { throw new InvalidRecordException( e ); } } else { // The CHECK and FORCE modes do not bother with reporting decoding errors... // ... but they must still clear them, since the page cursor may be reused to read other records cursor.clearCursorException(); } }
@Override public ArrayValue decodeArray( Value dataValue ) { if ( dataValue instanceof LongArray ) { LongArray numbers = (LongArray) dataValue; LocalDate[] dates = new LocalDate[numbers.length()]; for ( int i = 0; i < dates.length; i++ ) { dates[i] = LocalDate.ofEpochDay( numbers.longValue( i ) ); } return Values.dateArray( dates ); } else { throw new InvalidRecordException( "Array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: LongArray." ); } }
@Override public ArrayValue decodeArray( Value dataValue ) { if ( dataValue instanceof LongArray ) { LongArray numbers = (LongArray) dataValue; LocalTime[] times = new LocalTime[numbers.length()]; for ( int i = 0; i < times.length; i++ ) { long nanoOfDay = numbers.longValue( i ); checkValidNanoOfDay( nanoOfDay ); times[i] = LocalTime.ofNanoOfDay( nanoOfDay ); } return Values.localTimeArray( times ); } else { throw new InvalidRecordException( "Array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: LongArray." ); } }
throw new InvalidRecordException( "LocalTime array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: LongArray." );
private void updateDynamicRecords( List<DynamicRecord> records ) { for ( DynamicRecord valueRecord : records ) { PropertyType recordType = valueRecord.getType(); if ( recordType == PropertyType.STRING ) { stringStore.updateRecord( valueRecord ); } else if ( recordType == PropertyType.ARRAY ) { arrayStore.updateRecord( valueRecord ); } else { throw new InvalidRecordException( "Unknown dynamic record" + valueRecord ); } } }
@Override public ArrayValue decodeArray( GeometryHeader header, byte[] data ) { byte[] dataHeader = PropertyType.ARRAY.readDynamicRecordHeader( data ); byte[] dataBody = new byte[data.length - dataHeader.length]; System.arraycopy( data, dataHeader.length, dataBody, 0, dataBody.length ); Value dataValue = DynamicArrayStore.getRightArray( Pair.of( dataHeader, dataBody ) ); if ( dataValue instanceof FloatingPointArray ) { FloatingPointArray numbers = (FloatingPointArray) dataValue; PointValue[] points = new PointValue[numbers.length() / header.dimension]; for ( int i = 0; i < points.length; i++ ) { double[] coords = new double[header.dimension]; for ( int d = 0; d < header.dimension; d++ ) { coords[d] = numbers.doubleValue( i * header.dimension + d ); } points[i] = Values.pointValue( header.crs, coords ); } return Values.pointArray( points ); } else { throw new InvalidRecordException( "Point array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: FloatingPointArray." ); } } };
@Override public ArrayValue decodeArray( Value dataValue ) { if ( dataValue instanceof LongArray ) { LongArray numbers = (LongArray) dataValue; DurationValue[] durations = new DurationValue[(int) (numbers.length() / BLOCKS_DURATION)]; for ( int i = 0; i < durations.length; i++ ) { durations[i] = DurationValue.duration( numbers.longValue( i * BLOCKS_DURATION ), numbers.longValue( i * BLOCKS_DURATION + 1 ), numbers.longValue( i * BLOCKS_DURATION + 2 ), numbers.longValue( i * BLOCKS_DURATION + 3 ) ); } return Values.durationArray( durations ); } else { throw new InvalidRecordException( "Array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: LongArray." ); } } };
@Override public ArrayValue decodeArray( Value dataValue ) { if ( dataValue instanceof LongArray ) { LongArray numbers = (LongArray) dataValue; OffsetTime[] times = new OffsetTime[(int) (numbers.length() / BLOCKS_TIME)]; for ( int i = 0; i < times.length; i++ ) { long nanoOfDay = numbers.longValue( i * BLOCKS_TIME ); int secondOffset = (int) numbers.longValue( i * BLOCKS_TIME + 1 ); checkValidNanoOfDay( nanoOfDay ); times[i] = OffsetTime.of( LocalTime.ofNanoOfDay( nanoOfDay ), ZoneOffset.ofTotalSeconds( secondOffset ) ); } return Values.timeArray( times ); } else { throw new InvalidRecordException( "Array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: LongArray." ); } } },
private void disconnect( RelationshipRecord rel, RelationshipConnection pointer, RecordAccess<RelationshipRecord, Void> relChanges, ResourceLocker locks ) { long otherRelId = pointer.otherSide().get( rel ); if ( otherRelId == Record.NO_NEXT_RELATIONSHIP.intValue() ) { return; } locks.acquireExclusive( LockTracer.NONE, ResourceTypes.RELATIONSHIP, otherRelId ); RelationshipRecord otherRel = relChanges.getOrLoad( otherRelId, null ).forChangingLinkage(); boolean changed = false; long newId = pointer.get( rel ); boolean newIsFirst = pointer.isFirstInChain( rel ); if ( otherRel.getFirstNode() == pointer.compareNode( rel ) ) { pointer.start().set( otherRel, newId, newIsFirst ); changed = true; } if ( otherRel.getSecondNode() == pointer.compareNode( rel ) ) { pointer.end().set( otherRel, newId, newIsFirst ); changed = true; } if ( !changed ) { throw new InvalidRecordException( otherRel + " don't match " + rel ); } }
throw new InvalidRecordException( nodeId + " doesn't match " + firstRel );
if ( blockSize <= 0 ) throw new InvalidRecordException( "Illegal blockSize: " + blockSize );
/** * Verifies that a record's in use status is in line with the mode, might throw {@link InvalidRecordException}. */ public final boolean verify( AbstractBaseRecord record ) { boolean inUse = record.inUse(); if ( this == NORMAL & !inUse ) { throw new InvalidRecordException( record + " not in use" ); } return this == FORCE | inUse; }
public static PropertyType getPropertyTypeOrThrow( long propBlock ) { PropertyType type = getPropertyTypeOrNull( propBlock ); if ( type == null ) { throw new InvalidRecordException( "Unknown property type for type " + typeIdentifier( propBlock ) ); } return type; }
/** * Any out of range value means a store corruption */ private static void checkValidNanoOfDay( long nanoOfDay ) { if ( nanoOfDay > LocalTime.MAX.toNanoOfDay() || nanoOfDay < LocalTime.MIN.toNanoOfDay() ) { throw new InvalidRecordException( "Nanosecond of day out of range:" + nanoOfDay ); } }
@Override public ArrayValue decodeArray( Value dataValue ) { if ( dataValue instanceof LongArray ) { LongArray numbers = (LongArray) dataValue; LocalDate[] dates = new LocalDate[numbers.length()]; for ( int i = 0; i < dates.length; i++ ) { dates[i] = LocalDate.ofEpochDay( numbers.longValue( i ) ); } return Values.dateArray( dates ); } else { throw new InvalidRecordException( "Array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: LongArray." ); } }
@Override public ArrayValue decodeArray( Value dataValue ) { if ( dataValue instanceof LongArray ) { LongArray numbers = (LongArray) dataValue; DurationValue[] durations = new DurationValue[(int) (numbers.length() / BLOCKS_DURATION)]; for ( int i = 0; i < durations.length; i++ ) { durations[i] = DurationValue.duration( numbers.longValue( i * BLOCKS_DURATION ), numbers.longValue( i * BLOCKS_DURATION + 1 ), numbers.longValue( i * BLOCKS_DURATION + 2 ), numbers.longValue( i * BLOCKS_DURATION + 3 ) ); } return Values.durationArray( durations ); } else { throw new InvalidRecordException( "Array with unexpected type. Actual:" + dataValue.getClass().getSimpleName() + ". Expected: LongArray." ); } } };