@Override public OCommandCacheSoftRefs enable() { enable = true; configuration.field("enabled", true); try { updateCfgOnDisk(); } catch (IOException e) { throw OException.wrapException( new OConfigurationException("Cannot write Command Cache Cache configuration to file '" + CONFIG_FILE + "'"), e); } return this; }
private void throwSerializedException(final byte[] serializedException) throws IOException { final OMemoryInputStream inputStream = new OMemoryInputStream(serializedException); final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream); Object throwable = null; try { throwable = objectInputStream.readObject(); } catch (ClassNotFoundException e) { OLogManager.instance().error(this, "Error during exception deserialization", e); throw new OException("Error during exception deserialization: " + e.toString()); } objectInputStream.close(); if (throwable instanceof OException) throw (OException) throwable; else if (throwable instanceof Throwable) // WRAP IT throw new OResponseProcessingException("Exception during response processing.", (Throwable) throwable); else OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null")); }
/** * 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()); }
@Override public void begin(ODatabaseDocument db) { super.begin(db); final String[] fieldNames = configuration.fieldNames(); try { String fieldName = fieldNames[0]; block = new OETLComponentFactory().getBlock(fieldName); block.configure(configuration.<ODocument>field(fieldName), context); } catch (Exception e) { throw OException.wrapException(new OConfigurationException("[Block transformer] Error on configuring inner block"), e); } }
ODocument oDocument = new ODocument(map); iResult.add(oDocument); return oDocument; ODocument doc = new ODocument().fromMap((Map<String, ? extends Object>) current); ORecordInternal.setIdentity(doc, new ORecordId(-2, cursor--)); current = doc; } else if (current instanceof List) { ODocument doc = new ODocument().field("value", current); ORecordInternal.setIdentity(doc, new ORecordId(-2, cursor--)); current = doc; throw OException.wrapException(new OCommandExecutionException("Error on execution of the GREMLIN script"), e); } finally { OGremlinHelper.global().releaseEngine(engine);
private void initCache() { configuration = new ODocument(); configuration.field("enabled", enable); configuration.field("evictStrategy", evictStrategy.toString()); configuration.field("minExecutionTime", minExecutionTime); configuration.field("maxResultsetSize", maxResultsetSize); try { ODocument diskConfig = loadConfiguration(); if (diskConfig != null) { configuration = diskConfig; configure(); } else { updateCfgOnDisk(); } } catch (Exception e) { throw OException.wrapException(new OConfigurationException( "Cannot change Command Cache Cache configuration file '" + CONFIG_FILE + "'. Command Cache will use default settings"), e); } }
public void onAfterCollection(final ODocument iRootRecord, final String iFieldName, final Object iUserObject) { try { jsonWriter.endCollection(settings.indentLevel--, true); collectionStack.pop(); } catch (IOException e) { throw OException.wrapException( new OFetchException("Error writing collection field " + iFieldName + " of record " + iRootRecord.getIdentity()), e); } }
private Analyzer buildAnalyzer(String analyzerFQN, Collection<String> stopwords) { try { final Class classAnalyzer = Class.forName(analyzerFQN); final Constructor constructor = classAnalyzer.getDeclaredConstructor(CharArraySet.class); return (Analyzer) constructor.newInstance(new CharArraySet(stopwords, true)); } catch (ClassNotFoundException e) { throw OException.wrapException(new OIndexException("Analyzer: " + analyzerFQN + " not found"), e); } catch (NoSuchMethodException e) { throw OException.wrapException(new OIndexException("Couldn't instantiate analyzer: public constructor not found"), e); } catch (Exception e) { OLogManager.instance().error(this, "Error on getting analyzer for Lucene index", e); } return new StandardAnalyzer(); }
private ODocument loadConfiguration() { try { final File f = getConfigFile(); if (f != null && f.exists()) { final String configurationContent = OIOUtils.readFileAsString(f); return new ODocument().fromJSON(configurationContent); } } catch (Exception e) { throw OException.wrapException(new OConfigurationException( "Cannot load Command Cache Cache configuration file '" + CONFIG_FILE + "'. Command Cache will use default settings"), e); } return null; }
private ORawBuffer doReadRecord(final OCluster clusterSegment, final ORecordId rid, final boolean prefetchRecords) { try { final ORawBuffer buff = clusterSegment.readRecord(rid.getClusterPosition(), prefetchRecords); if (buff != null && OLogManager.instance().isDebugEnabled()) { OLogManager.instance() .debug(this, "Read record %s v.%s size=%d bytes", rid, buff.version, buff.buffer != null ? buff.buffer.length : 0); } recordRead.incrementAndGet(); return buff; } catch (final IOException e) { throw OException.wrapException(new OStorageException("Error during read of record with rid = " + rid), e); } }
public void onBeforeMap(final ODocument iRootRecord, final String iFieldName, final Object iUserObject) { try { jsonWriter.beginObject(++settings.indentLevel, true, iFieldName); if (!(iUserObject instanceof ODocument)) { collectionStack.add(new ODocument()); // <-- sorry for this... fixes #2845 but this mess should be rewritten... } } catch (IOException e) { throw OException.wrapException( new OFetchException("Error writing map field " + iFieldName + " of record " + iRootRecord.getIdentity()), e); } }
@Override public ORawBuffer readRecordIfVersionIsNotLatest(long clusterPosition, int recordVersion) throws IOException, ORecordNotFoundException { throw OException.wrapException(new ORecordNotFoundException(new ORecordId(id, clusterPosition), "Record with rid #" + id + ":" + clusterPosition + " was not found in database"), new OOfflineClusterException("Cannot read a record from the offline cluster '" + name + "'")); }
public static OIndexDefinition getIndexDefinitionFromIndex(IndexWriter writer) { final Document metaDoc = retrieveIndexMetadata(writer); final ODocument defAsJson = new ODocument().fromJSON(metaDoc.get("_DEF_JSON")); final String defClassName = metaDoc.get("_DEF_CLASS_NAME"); try { final Class<?> indexDefClass = Class.forName(defClassName); OIndexDefinition indexDefinition = (OIndexDefinition) indexDefClass.getDeclaredConstructor().newInstance(); indexDefinition.fromStream(defAsJson); return indexDefinition; } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { throw OException.wrapException(new OLuceneIndexException("Error during deserialization of index definition"), e); } }
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; }
@Deprecated public ODocument load(final String iFetchPlan, boolean iIgnoreCache, boolean loadTombstone) { Object result; try { result = getDatabase().load(this, iFetchPlan, iIgnoreCache, loadTombstone, OStorage.LOCKING_STRATEGY.DEFAULT); } catch (Exception e) { throw OException.wrapException(new ORecordNotFoundException(getIdentity()), e); } if (result == null) throw new ORecordNotFoundException(getIdentity()); return (ODocument) result; }
ORecordSerializationContext.pushContext(); try { checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_READ, getClusterNameById(rid.getClusterId())); OLogManager.instance() .warn(this, "You use deprecated record locking strategy: %s it may lead to deadlocks " + lockingStrategy); record.lock(false); OLogManager.instance() .warn(this, "You use deprecated record locking strategy: %s it may lead to deadlocks " + lockingStrategy); record.lock(true); if (!rid.isValid()) recordBuffer = null; else { iRecord = Orient.instance().getRecordFactoryManager().newInstance(recordBuffer.recordType, rid.getClusterId(), this); } catch (Exception t) { if (rid.isTemporary()) throw OException.wrapException(new ODatabaseException("Error on retrieving record using temporary RID: " + rid), t); else throw OException.wrapException(new ODatabaseException( "Error on retrieving record " + rid + " (cluster: " + getStorage().getPhysicalClusterNameById(rid.getClusterId()) + ")"), t);
public OStorage createStorage(final String dbName, final Map<String, String> configuration, long maxWalSegSize) { try { return new OLocalPaginatedStorage(dbName, dbName, getMode(configuration), generateStorageId(), readCache, files, maxWalSegSize); } catch (Exception e) { final String message = "Error on opening database: " + dbName + ". Current location is: " + new java.io.File(".").getAbsolutePath(); OLogManager.instance().error(this, message, e); throw OException.wrapException(new ODatabaseException(message), e); } }
final ORecordId oldRID = rid.copy(); final OCluster cluster = getClusterById(rid.getClusterId()); final OPhysicalPosition ppos = cluster.allocatePosition(ORecordInternal.getRecordType(rec)); rid.setClusterPosition(ppos.clusterPosition); clientTx.updateIdentityAfterCommit(oldRID, rid); throw OException.wrapException(new OStorageException("Could not preallocate RIDs"), ioe); } finally { stateLock.releaseReadLock();
public static synchronized <T extends Object> Iterator<T> lookupProviderWithOrientClassLoader(Class<T> clazz, ClassLoader orientClassLoader) { final ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(orientClassLoader); try { return ServiceLoader.load(clazz).iterator(); } catch (Exception e) { OLogManager.instance().warn(null, "Cannot lookup in service registry", e); throw OException.wrapException(new OConfigurationException("Cannot lookup in service registry"), e); } finally { Thread.currentThread().setContextClassLoader(origClassLoader); } }
try { ppos = cluster.createRecord(content, recordVersion, recordType, allocated); rid.setClusterPosition(ppos.clusterPosition); OLogManager.instance().error(this, "Error on creating record in cluster: " + cluster, e); throw ODatabaseException.wrapException(new OStorageException("Error during creation of record"), e); } finally { atomicOperationsManager.endAtomicOperation(rollback); if (OLogManager.instance().isDebugEnabled()) { OLogManager.instance().debug(this, "Created record %s v.%s size=%d bytes", rid, recordVersion, content.length); throw OException.wrapException( new OStorageException("Error during record deletion in cluster " + (cluster != null ? cluster.getName() : "")), ioe);