use of org.apache.phoenix.schema.SequenceInfo in project phoenix by apache.
the class ConnectionlessQueryServicesImpl method incrementSequences.
@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++;
}
}
use of org.apache.phoenix.schema.SequenceInfo in project phoenix by apache.
the class ConnectionlessQueryServicesImpl method createSequence.
@Override
public long createSequence(String tenantId, String schemaName, String sequenceName, long startWith, long incrementBy, long cacheSize, long minValue, long maxValue, boolean cycle, long timestamp) throws SQLException {
SequenceKey key = new SequenceKey(tenantId, schemaName, sequenceName, getSequenceSaltBuckets());
if (sequenceMap.get(key) != null) {
throw new SequenceAlreadyExistsException(schemaName, sequenceName);
}
sequenceMap.put(key, new SequenceInfo(startWith, incrementBy, minValue, maxValue, 1l, cycle));
return timestamp;
}
use of org.apache.phoenix.schema.SequenceInfo in project phoenix by apache.
the class ConnectionlessQueryServicesImpl method validateSequences.
@Override
public void validateSequences(List<SequenceAllocation> sequenceAllocations, long timestamp, long[] values, SQLException[] exceptions, Sequence.ValueOp action) throws SQLException {
int i = 0;
for (SequenceAllocation sequenceAllocation : sequenceAllocations) {
SequenceInfo info = sequenceMap.get(sequenceAllocation.getSequenceKey());
if (info == null) {
exceptions[i] = new SequenceNotFoundException(sequenceAllocation.getSequenceKey().getSchemaName(), sequenceAllocation.getSequenceKey().getSequenceName());
} else {
values[i] = info.sequenceValue;
}
i++;
}
}
Aggregations