本文整理汇总了Java中com.amazon.carbonado.PersistException类的典型用法代码示例。如果您正苦于以下问题:Java PersistException类的具体用法?Java PersistException怎么用?Java PersistException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistException类属于com.amazon.carbonado包,在下文中一共展示了PersistException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateBlock
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
private void updateBlock() throws PersistException {
if (mStoredBlock != null) {
byte[] blockData = mBlockData;
if (blockData.length != mBlockLength) {
byte[] truncated = new byte[mBlockLength];
System.arraycopy(blockData, 0, truncated, 0, truncated.length);
blockData = truncated;
}
mStoredBlock.setData(blockData);
if (mDoInsert) {
mStoredBlock.insert();
mDoInsert = false;
} else {
mStoredBlock.update();
}
}
}
示例2: nextIntValue
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
/**
* Returns the next value from the sequence, which may wrap negative if all
* positive values are exhausted. When sequence wraps back to initial
* value, the sequence is fully exhausted, and an exception is thrown to
* indicate this.
*
* <p>Note: this method throws PersistException even for fetch failures
* since this method is called by insert operations. Insert operations can
* only throw a PersistException.
*
* @throws PersistException for fetch/persist failure or if sequence is
* exhausted for int values.
*/
@Override
public int nextIntValue() throws PersistException {
try {
synchronized (mStoredSequence) {
long initial = mStoredSequence.getInitialValue();
if (initial >= 0x100000000L) {
throw new PersistException
("Sequence initial value too large to support 32-bit ints: " +
mStoredSequence.getName() + ", initial: " + initial);
}
long next = nextUnadjustedValue();
if (next >= Long.MIN_VALUE + 0x100000000L) {
// Everytime we throw this exception, a long sequence value
// has been lost. This seems fairly benign.
throw new PersistException
("Sequence exhausted for 32-bit ints: " + mStoredSequence.getName() +
", next: " + (next + Long.MIN_VALUE + initial));
}
return (int) (next + Long.MIN_VALUE + initial);
}
} catch (FetchException e) {
throw e.toPersistException();
}
}
示例3: store
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
public void store(S storable, byte[] key, byte[] value) throws PersistException {
TransactionScope<Txn> scope = mStorage.localTransactionScope();
// Lock out shutdown task.
scope.getLock().lock();
try {
try {
if (!mStorage.db_put(scope.getTxn(), key, value)) {
throw new PersistException("Failed");
}
} catch (Throwable e) {
throw mStorage.toPersistException(e);
}
} finally {
scope.getLock().unlock();
}
}
示例4: beforeInsert
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
@Override
public Object beforeInsert(Transaction txn, S storable) throws PersistException {
if (isLocallyDisabled()) {
return null;
}
TriggerStates<S> triggerStates = null;
Trigger<? super S>[] triggers = mTriggers;
for (int i=triggers.length; --i>=0; ) {
Object state = triggers[i].beforeInsert(txn, storable);
if (state != null) {
if (triggerStates == null) {
triggerStates = new TriggerStates<S>(triggers);
}
triggerStates.mStates[i] = state;
}
}
return triggerStates == null ? triggers : triggerStates;
}
示例5: beforeTryUpdate
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
@Override
public Object beforeTryUpdate(Transaction txn, S storable) throws PersistException {
if (isLocallyDisabled()) {
return null;
}
TriggerStates<S> triggerStates = null;
Trigger<? super S>[] triggers = mTriggers;
for (int i=triggers.length; --i>=0; ) {
Object state = triggers[i].beforeTryUpdate(txn, storable);
if (state != null) {
if (triggerStates == null) {
triggerStates = new TriggerStates<S>(triggers);
}
triggerStates.mStates[i] = state;
}
}
return triggerStates == null ? triggers : triggerStates;
}
示例6: deleteLob
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
/**
* Deletes Lob data, freeing up all space consumed by it.
*/
public void deleteLob(long locator) throws PersistException {
if (locator == 0) {
return;
}
Transaction txn = mRepo.enterTransaction(IsolationLevel.READ_COMMITTED);
try {
StoredLob lob = mLobStorage.prepare();
lob.setLocator(locator);
if (lob.tryDelete()) {
try {
mLobBlockStorage.query("locator = ?").with(lob.getLocator()).deleteAll();
} catch (FetchException e) {
throw e.toPersistException();
}
}
txn.commit();
} finally {
txn.exit();
}
}
示例7: beforeTryInsert
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
@Override
public Object beforeTryInsert(S storable) throws PersistException {
if (isLocallyDisabled()) {
return null;
}
TriggerStates<S> triggerStates = null;
Trigger<? super S>[] triggers = mTriggers;
for (int i=triggers.length; --i>=0; ) {
Object state = triggers[i].beforeTryInsert(storable);
if (state != null) {
if (triggerStates == null) {
triggerStates = new TriggerStates<S>(triggers);
}
triggerStates.mStates[i] = state;
}
}
return triggerStates == null ? triggers : triggerStates;
}
示例8: beforeDelete
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
@Override
public Object beforeDelete(S storable) throws PersistException {
if (isLocallyDisabled()) {
return null;
}
TriggerStates<S> triggerStates = null;
Trigger<? super S>[] triggers = mTriggers;
for (int i=triggers.length; --i>=0; ) {
Object state = triggers[i].beforeDelete(storable);
if (state != null) {
if (triggerStates == null) {
triggerStates = new TriggerStates<S>(triggers);
}
triggerStates.mStates[i] = state;
}
}
return triggerStates == null ? triggers : triggerStates;
}
示例9: toPersistException
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
/**
* Transforms the given throwable into an appropriate persist exception. If
* it already is a persist exception, it is simply casted.
*
* @param e required exception to transform
* @return PersistException, never null
*/
public PersistException toPersistException(Throwable e) {
PersistException pe = transformIntoPersistException(e);
if (pe != null) {
return pe;
}
Throwable cause = e.getCause();
if (cause != null) {
pe = transformIntoPersistException(cause);
if (pe != null) {
return pe;
}
} else {
cause = e;
}
return new PersistException(cause);
}
示例10: reset
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
/**
* Reset the sequence.
*
* @param initialValue first value produced by sequence
*/
public void reset(int initialValue) throws FetchException, PersistException {
synchronized (mStoredSequence) {
Transaction txn = mRepository.enterTopTransaction(null);
txn.setForUpdate(true);
try {
boolean doUpdate = mStoredSequence.tryLoad();
mStoredSequence.setInitialValue(initialValue);
// Start as small as possible to allow signed long comparisons to work.
mStoredSequence.setNextValue(Long.MIN_VALUE);
if (doUpdate) {
mStoredSequence.update();
} else {
mStoredSequence.insert();
}
txn.commit();
mHasReservedValues = false;
} finally {
txn.exit();
}
}
}
示例11: beforeTryDelete
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
@Override
public Object beforeTryDelete(Transaction txn, S storable) throws PersistException {
if (isLocallyDisabled()) {
return null;
}
TriggerStates<S> triggerStates = null;
Trigger<? super S>[] triggers = mTriggers;
for (int i=triggers.length; --i>=0; ) {
Object state = triggers[i].beforeTryDelete(txn, storable);
if (state != null) {
if (triggerStates == null) {
triggerStates = new TriggerStates<S>(triggers);
}
triggerStates.mStates[i] = state;
}
}
return triggerStates == null ? triggers : triggerStates;
}
示例12: tryInsert
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
public boolean tryInsert(S storable, byte[] key, byte[] value) throws PersistException {
TransactionScope<Txn> scope = mStorage.localTransactionScope();
Object result;
// Lock out shutdown task.
scope.getLock().lock();
try {
try {
result = mStorage.db_putNoOverwrite(scope.getTxn(), key, value);
} catch (Throwable e) {
throw mStorage.toPersistException(e);
}
} finally {
scope.getLock().unlock();
}
if (result == KEY_EXIST) {
return false;
}
if (result != SUCCESS) {
throw new PersistException("Failed");
}
return true;
}
示例13: transformIntoPersistException
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
@Override
protected PersistException transformIntoPersistException(Throwable e) {
PersistException pe = super.transformIntoPersistException(e);
if (pe != null) {
return pe;
}
if (e instanceof LockFailureException) {
if (e instanceof LockTimeoutException) {
if (e instanceof DeadlockException) {
String message = messageFrom((DeadlockException) e);
return message == null ? new PersistDeadlockException(e)
: new PersistDeadlockException(message);
}
return new PersistTimeoutException(e);
}
if (e instanceof LockInterruptedException) {
return new PersistInterruptedException(e);
}
}
if (e instanceof UnmodifiableReplicaException) {
return new PersistDeniedException(e);
}
return null;
}
示例14: createSequenceValueProducer
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
/**
* @since 1.2
*/
SequenceValueProducer createSequenceValueProducer(String name)
throws RepositoryException
{
if (name == null) {
throw new IllegalArgumentException("Sequence name is null");
}
String format = getSequenceSelectStatement();
if (format != null && format.length() > 0 && !isForceStoredSequence()) {
String sequenceQuery = String.format(format, name);
return new JDBCSequenceValueProducer(mRepo, sequenceQuery);
} else {
try {
return new SequenceValueGenerator(mRepo, name);
} catch (UnsupportedTypeException e) {
if (e.getType() != StoredSequence.class) {
throw e;
}
throw new PersistException
("Native sequences are not currently supported for \"" +
mRepo.getDatabaseProductName() + "\". Instead, define a table named " +
"CARBONADO_SEQUENCE as required by " + StoredSequence.class.getName() + '.');
}
}
}
示例15: setClobValue
import com.amazon.carbonado.PersistException; //导入依赖的package包/类
/**
* Stores a value into a Clob, replacing anything that was there
* before. Passing null deletes the Clob, which is a convenience for
* auto-generated code that may call this method.
*
* @param locator lob locator as created by createNewClob
* @param data source of data for Clob, which may be null to delete
* @throws IllegalArgumentException if locator is zero
*/
public void setClobValue(long locator, Clob data) throws PersistException, IOException {
if (data == null) {
deleteLob(locator);
return;
}
if (locator == 0) {
throw new IllegalArgumentException("Cannot use locator zero");
}
if (data instanceof ClobImpl) {
BlobImpl impl = ((ClobImpl) data).getWrappedBlob();
if (impl.getEnclosing() == this && impl.mLocator == locator) {
// Blob is ours and locator is the same, so nothing to do.
return;
}
}
try {
setClobValue(locator, data.openReader(0, 0));
} catch (FetchException e) {
throw e.toPersistException();
}
}