Java Code Examples for org.apache.phoenix.exception.SQLExceptionCode#SEQUENCE_VAL_REACHED_MIN_VALUE
The following examples show how to use
org.apache.phoenix.exception.SQLExceptionCode#SEQUENCE_VAL_REACHED_MIN_VALUE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionlessQueryServicesImpl.java From phoenix with Apache License 2.0 | 5 votes |
@Override public void incrementSequences(List<SequenceKey> sequenceKeys, long timestamp, long[] values, SQLException[] exceptions) throws SQLException { int i = 0; for (SequenceKey key : sequenceKeys) { SequenceInfo info = sequenceMap.get(key); if (info == null) { exceptions[i] = new SequenceNotFoundException( key.getSchemaName(), key.getSequenceName()); } else { boolean increaseSeq = info.incrementBy > 0; if (info.limitReached) { SQLExceptionCode code = increaseSeq ? SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE : SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE; exceptions[i] = new SQLExceptionInfo.Builder(code).build().buildException(); } else { values[i] = info.sequenceValue; info.sequenceValue += info.incrementBy * info.cacheSize; info.limitReached = SequenceUtil.checkIfLimitReached(info); if (info.limitReached && info.cycle) { info.sequenceValue = increaseSeq ? info.minValue : info.maxValue; info.limitReached = false; } } } i++; } i = 0; for (SQLException e : exceptions) { if (e != null) { sequenceMap.remove(sequenceKeys.get(i)); } i++; } }
Example 2
Source File: Sequence.java From phoenix with Apache License 2.0 | 5 votes |
private long increment(SequenceValue value, ValueOp op) throws SQLException { boolean increasingSeq = value.incrementBy > 0 && op != ValueOp.VALIDATE_SEQUENCE; // check if the the sequence has already reached the min/max limit if (value.limitReached && op != ValueOp.VALIDATE_SEQUENCE) { if (value.cycle) { value.limitReached=false; throw EMPTY_SEQUENCE_CACHE_EXCEPTION; } else { SQLExceptionCode code = increasingSeq ? SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE : SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE; throw SequenceUtil.getException(this.key.getSchemaName(), this.key.getSequenceName(), code); } } long returnValue = value.currentValue; if (op == ValueOp.INCREMENT_SEQUENCE) { boolean overflowOrUnderflow=false; // advance currentValue while checking for overflow try { value.currentValue = LongMath.checkedAdd(value.currentValue, value.incrementBy); } catch (ArithmeticException e) { overflowOrUnderflow = true; } // set the limitReached flag (which will be checked the next time increment is called) // if overflow or limit was reached if (overflowOrUnderflow || (increasingSeq && value.currentValue > value.maxValue) || (!increasingSeq && value.currentValue < value.minValue)) { value.limitReached=true; } } return returnValue; }
Example 3
Source File: ConnectionlessQueryServicesImpl.java From phoenix with Apache License 2.0 | 5 votes |
@Override public void incrementSequences(List<SequenceAllocation> sequenceAllocations, long timestamp, long[] values, SQLException[] exceptions) throws SQLException { int i = 0; for (SequenceAllocation sequenceAllocation : sequenceAllocations) { SequenceKey key = sequenceAllocation.getSequenceKey(); SequenceInfo info = sequenceMap.get(key); if (info == null) { exceptions[i] = new SequenceNotFoundException( key.getSchemaName(), key.getSequenceName()); } else { boolean increaseSeq = info.incrementBy > 0; if (info.limitReached) { SQLExceptionCode code = increaseSeq ? SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE : SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE; exceptions[i] = new SQLExceptionInfo.Builder(code).build().buildException(); } else { values[i] = info.sequenceValue; info.sequenceValue += info.incrementBy * info.cacheSize; info.limitReached = SequenceUtil.checkIfLimitReached(info); if (info.limitReached && info.cycle) { info.sequenceValue = increaseSeq ? info.minValue : info.maxValue; info.limitReached = false; } } } i++; } i = 0; for (SQLException e : exceptions) { if (e != null) { sequenceMap.remove(sequenceAllocations.get(i).getSequenceKey()); } i++; } }
Example 4
Source File: Sequence.java From phoenix with Apache License 2.0 | 5 votes |
private long increment(SequenceValue value, ValueOp op, long numToAllocate) throws SQLException { boolean increasingSeq = value.incrementBy > 0 && op != ValueOp.VALIDATE_SEQUENCE; // check if the the sequence has already reached the min/max limit if (value.limitReached && op != ValueOp.VALIDATE_SEQUENCE) { if (value.cycle) { value.limitReached=false; throw EMPTY_SEQUENCE_CACHE_EXCEPTION; } else { SQLExceptionCode code = increasingSeq ? SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE : SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE; throw SequenceUtil.getException(this.key.getSchemaName(), this.key.getSequenceName(), code); } } long returnValue = value.currentValue; if (op == ValueOp.INCREMENT_SEQUENCE) { boolean overflowOrUnderflow=false; // advance currentValue while checking for overflow try { // advance by numToAllocate * the increment amount value.currentValue = LongMath.checkedAdd(value.currentValue, numToAllocate * value.incrementBy); } catch (ArithmeticException e) { overflowOrUnderflow = true; } // set the limitReached flag (which will be checked the next time increment is called) // if overflow or limit was reached if (overflowOrUnderflow || (increasingSeq && value.currentValue > value.maxValue) || (!increasingSeq && value.currentValue < value.minValue)) { value.limitReached=true; } } return returnValue; }
Example 5
Source File: SequenceUtil.java From phoenix with Apache License 2.0 | 4 votes |
/** * Returns the correct instance of SQLExceptionCode when we detect a limit has been reached, * depending upon whether a min or max value caused the limit to be exceeded. */ public static SQLExceptionCode getLimitReachedErrorCode(boolean increasingSeq) { SQLExceptionCode code = increasingSeq ? SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE : SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE; return code; }