/** * Should be used only by console commands */ protected void checkCurrentObject() { if (currentRecord == null) throw new OSystemException("The is no current object selected: create a new one or load it"); }
/** * This constructor is needed to restore and reproduce exception on client side in case of remote storage exception handling. * Please create "copy constructor" for each exception which has current one as a parent. */ public OException(final OException exception) { super(exception.getMessage(), exception.getCause()); }
public static OException wrapException(final OException exception, final Throwable cause) { if (cause instanceof OHighLevelException) return (OException) cause; exception.initCause(cause); return exception; }
private byte[] bytesFromString(final String toWrite) { try { return toWrite.getBytes(CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string encoding"), e); } }
public V newInstanceOfDefaultClass() { if (defaultClass != null) { try { return defaultClass.newInstance(); } catch (Exception e) { throw OException.wrapException( new OSystemException(String.format("Error on creating new instance of default class '%s'", defaultClass)), e); } } return null; }
@Override public final String getMessage() { final StringBuilder builder = new StringBuilder(super.getMessage()); if (dbName != null) { builder.append("\r\n\t").append("DB name=\"").append(dbName).append("\""); } if (componentName != null) { builder.append("\r\n\t").append("Component Name=\"").append(componentName).append("\""); } if (errorCode != null) { builder.append("\r\n\t").append("Error Code=\"").append(errorCode.getCode()).append("\""); } return builder.toString(); } }
public void throwException(Throwable parent) { throwException(this.description, parent); }
public void throwException(String message, Throwable parent) { OException exc = newException(message, parent); throw exc; }
/** * Mocks the given Orient exception type so it can participate in unit tests without * depending on internal state such as {@link ODatabaseRecordThreadLocal#INSTANCE}. */ public static <E extends OException> E mockOrientException(final Class<E> exceptionType) { E exception = mock(exceptionType); when(exception.getStackTrace()).thenReturn(new StackTraceElement[0]); return exception; } }
protected String stringFromBytes(final byte[] bytes, final int offset, final int len) { try { return new String(bytes, offset, len, CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string decoding"), e); } }
public void declareRecordType(byte iByte, String iName, Class<? extends ORecord> iClass, final ORecordFactory iFactory) { if (recordTypes[iByte] != null) throw new OSystemException("Record type byte '" + iByte + "' already in use : " + recordTypes[iByte].getName()); recordTypeNames[iByte] = iName; recordTypes[iByte] = iClass; recordFactories[iByte] = iFactory; }
public void throwException() { throwException(this.description, null); }
@Override public void clear() { try { sbTree.clear(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during clear index " + name), e); } }
/** * Should be used only by console commands */ protected void checkForRemoteServer() { if (orientDB == null || OrientDBInternal.extract(orientDB).isEmbedded()) throw new OSystemException( "Remote server is not connected. Use 'connect remote:<host>[:<port>][/<database-name>]' to connect"); }
public void throwException(String message) { throwException(message, null); }
@Override public void update(Object key, OIndexKeyUpdater<Object> updater) { try { sbTree.update(key, updater, null); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during update of key " + key + " in index " + name), e); } }
public void delete() { try { tree.delete(); } catch (IOException e) { throw OException.wrapException(new ODatabaseException("Error during deletion index container"), e); } }
@Override public void clear() { try { sbTree.clear(); } catch (IOException e) { throw OException.wrapException(new OIndexException("Error during clearing of index " + name), e); } }
public Object createSingleValue(final Object... param) { try { return OType.convert(param[0], keyType.getDefaultJavaType()); } catch (Exception e) { OException ex = OException .wrapException(new OIndexException("Invalid key for index: " + param[0] + " cannot be converted to " + keyType), e); throw ex; } }
private static ODocument checkForLoading(final ODocument iRecord) { if (iRecord.getInternalStatus() == ORecordElement.STATUS.NOT_LOADED) { try { return (ODocument) iRecord.load(); } catch (final ORecordNotFoundException e) { throw OException.wrapException(new OIndexException("Error during loading of record with id " + iRecord.getIdentity()), e); } } return iRecord; }