com.orientechnologies.orient.core.db.ODatabaseDocumentInternal Java Examples
The following examples show how to use
com.orientechnologies.orient.core.db.ODatabaseDocumentInternal.
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: DatabaseExportResource.java From Orienteer with Apache License 2.0 | 6 votes |
@Override protected ResourceResponse newResourceResponse(Attributes attrs) { ResourceResponse resourceResponse = new ResourceResponse(); resourceResponse.setContentType("application/x-gzip"); resourceResponse.setFileName("export.gz"); resourceResponse.setWriteCallback(new WriteCallback() { @Override public void writeData(Attributes attributes) throws IOException { OutputStream out = attributes.getResponse().getOutputStream(); GZIPOutputStream gzipOut = new GZIPOutputStream(out); ODatabaseDocumentInternal db = (ODatabaseDocumentInternal)OrientDbWebSession.get().getDatabase(); ODatabaseExport dbExport = new ODatabaseExport(db, gzipOut, LoggerOCommandOutputListener.INSTANCE); configureODatabaseExport(dbExport); dbExport.exportDatabase(); } }); return resourceResponse; }
Example #2
Source File: DatabasePoolSupport.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
protected void replaceStorage(final OPartitionedDatabasePool pool, final OStorage storage) { if (partitionsField != null) { ODatabaseDocumentInternal originalDb = ODatabaseRecordThreadLocal.instance().getIfDefined(); try { // use reflection as workaround until public API is available for (Object partition : (Object[]) partitionsField.get(pool)) { for (ODatabaseDocumentTx db : (Iterable<ODatabaseDocumentTx>) partitionQueueField.get(partition)) { replaceStorage(db, storage); } } } catch (Exception | LinkageError e) { log.warn("Problem replacing storage for {}", storage.getName(), e); } finally { ODatabaseRecordThreadLocal.instance().set(originalDb); } } }
Example #3
Source File: OLuceneFacetManager.java From orientdb-lucene with Apache License 2.0 | 6 votes |
protected void buildFacetIndexIfNeeded() throws IOException { if (metadata != null && metadata.containsField(FACET_FIELDS)) { ODatabaseDocumentInternal database = owner.getDatabase(); Iterable<String> iterable = metadata.field(FACET_FIELDS); if (iterable != null) { Directory dir = getTaxDirectory(database); taxonomyWriter = new DirectoryTaxonomyWriter(dir, IndexWriterConfig.OpenMode.CREATE_OR_APPEND); for (String s : iterable) { facetField = s; // facetField = "facet_" + s; // facetDim = s; // config.setIndexFieldName(s, "facet_" + s); config.setHierarchical(s, true); } } } }
Example #4
Source File: DBClosure.java From wicket-orientdb with Apache License 2.0 | 6 votes |
/** * @return result of execution */ public final V execute() { ODatabaseDocument db = null; ODatabaseRecordThreadLocal orientDbThreadLocal = ODatabaseRecordThreadLocal.instance(); ODatabaseDocument oldDb = orientDbThreadLocal.getIfDefined(); if(oldDb!=null) orientDbThreadLocal.remove(); //Required to avoid stack of transactions try { db = getSettings().getDatabasePoolFactory().get(getDBUrl(), getUsername(), getPassword()).acquire(); db.activateOnCurrentThread(); return execute(db); } finally { if(db!=null) db.close(); if(oldDb!=null) orientDbThreadLocal.set((ODatabaseDocumentInternal)oldDb); else orientDbThreadLocal.remove(); } }
Example #5
Source File: UserManager.java From guice-persist-orient with MIT License | 6 votes |
/** * Changes current connection user. Affects only current transaction and can't be used outside of transaction * ({@link ODatabaseDocumentInternal#setUser(com.orientechnologies.orient.core.metadata.security.OSecurityUser)}). * <p> * Recursive user changes are not allowed, so attempt to change user under already changed user will * lead to error. The only exception is change to the same user (in this case change is ignored). * <p> * Action approach is important to explicitly define scope of specific user and * properly cleanup state (which may be not done in case of direct override). * <p> * Propagates runtime exceptions (orient exceptions). * * @param user specific user * @param userAction logic to execute with specific user * @param <T> type of returned result (may be Void) * @return action result (may be null) */ public <T> T executeWithTxUser(final OSecurityUser user, final SpecificUserAction<T> userAction) { final boolean userChanged = checkSpecificUserConditions(user.getName()); final ODatabaseDocumentInternal db = (ODatabaseDocumentInternal) connectionProvider.get(); final OSecurityUser original = db.getUser(); if (userChanged) { // no need to track user change if user not changed specificTxUser.set(user); db.setUser(user); } T result = null; try { result = userAction.execute(); } catch (Throwable th) { Throwables.throwIfUnchecked(th); throw new UserActionException(String.format("Failed to perform tx action with user '%s'", user.getName()), th); } finally { if (userChanged) { db.setUser(original); specificTxUser.remove(); } } return result; }
Example #6
Source File: DefaultODatabaseThreadLocalFactory.java From wicket-orientdb with Apache License 2.0 | 6 votes |
@Override public ODatabaseDocumentInternal getThreadDatabase() { IOrientDbSettings settings = app.getOrientDbSettings(); OrientDbWebSession session = OrientDbWebSession.exists()?OrientDbWebSession.get():null; ODatabaseDocumentInternal db; String username; String password; if(session!=null && session.isSignedIn()) { username = session.getUsername(); password = session.getPassword(); } else { username = settings.getGuestUserName(); password = settings.getGuestPassword(); } db = settings.getDatabasePoolFactory().get(settings.getDBUrl(), username, password).acquire(); return db; }
Example #7
Source File: EntityHook.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private static <T> T withActiveDb(final ODatabase db, final Supplier<T> supplier) { @SuppressWarnings("resource") final ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db.equals(currentDb) || !(db instanceof ODatabaseDocumentInternal)) { return supplier.get(); } try { ODatabaseRecordThreadLocal.instance().set((ODatabaseDocumentInternal) db); return supplier.get(); } finally { if (currentDb != null) { ODatabaseRecordThreadLocal.instance().set(currentDb); } else { ODatabaseRecordThreadLocal.instance().remove(); } } }
Example #8
Source File: ObjectPool.java From guice-persist-orient with MIT License | 5 votes |
@Override public ODatabaseObject get() { if (transaction.get() == null) { final ODatabaseDocumentInternal documentDb = (ODatabaseDocumentInternal) documentPool.get(); final OObjectDatabaseTx value = new OObjectDatabaseTx(documentDb); transaction.set(value); } final ODatabaseObject db = transaction.get(); db.activateOnCurrentThread(); return db; }
Example #9
Source File: ODateConverter.java From Orienteer with Apache License 2.0 | 5 votes |
private ZoneId getServerZoneId() { ZoneId zoneId = ((ODatabaseDocumentInternal)OrienteerWebApplication.lookupApplication().getDatabase()) .getStorage().getConfiguration().getTimeZone().toZoneId(); if(zoneId==null) { zoneId = ZoneId.systemDefault(); } return zoneId; }
Example #10
Source File: OLuceneIndexFactory.java From orientdb-lucene with Apache License 2.0 | 5 votes |
private OIndexInternal<?> createLuceneIndex(String name, ODatabaseDocumentInternal oDatabaseRecord, String indexType, String valueContainerAlgorithm, ODocument metadata) { if (OClass.INDEX_TYPE.FULLTEXT.toString().equals(indexType)) { return new OLuceneFullTextIndex(name, indexType, LUCENE_ALGORITHM, new OLuceneIndexEngine<Set<OIdentifiable>>( new OLuceneFullTextIndexManager(), indexType), valueContainerAlgorithm, metadata); } else if (OClass.INDEX_TYPE.SPATIAL.toString().equals(indexType)) { return new OLuceneSpatialIndex(name, indexType, LUCENE_ALGORITHM, new OLuceneIndexEngine<Set<OIdentifiable>>( new OLuceneSpatialIndexManager(OShapeFactoryImpl.INSTANCE), indexType), valueContainerAlgorithm, metadata); } throw new OConfigurationException("Unsupported type : " + indexType); }
Example #11
Source File: GraphPool.java From guice-persist-orient with MIT License | 5 votes |
@Override public OrientBaseGraph get() { if (transaction.get() == null) { final ODatabaseDocumentInternal documentDb = (ODatabaseDocumentInternal) documentPool.get(); final OrientBaseGraph graph = transactionManager.getActiveTransactionType() == OTransaction.TXTYPE.NOTX ? new OrientGraphNoTx(documentDb) : new OrientGraph(documentDb); transaction.set(graph); } final OrientBaseGraph db = transaction.get(); db.getRawGraph().activateOnCurrentThread(); return db; }
Example #12
Source File: GraphPool.java From guice-persist-orient with MIT License | 5 votes |
@Override public void start(final String database) { // test connection and let orient configure database new OrientGraph( (ODatabaseDocumentInternal) orientDB.get() .open(database, userManager.getUser(), userManager.getPassword())) .getRawGraph().close(); logger.debug("Pool {} started for database '{}'", getType(), database); }
Example #13
Source File: ObjectPool.java From guice-persist-orient with MIT License | 5 votes |
@Override public void start(final String database) { // test connection and let orient configure database new OObjectDatabaseTx( (ODatabaseDocumentInternal) orientDB.get() .open(database, userManager.getUser(), userManager.getPassword())) .close(); logger.debug("Pool {} started for database '{}'", getType(), database); }
Example #14
Source File: TransactionRequestCycleListener.java From wicket-orientdb with Apache License 2.0 | 5 votes |
@Override public void start(RequestCycle cycle) { OrientDbWebSession session = OrientDbWebSession.get(); ODatabaseDocumentInternal db = session.getDatabase(); //It's required to have ability to check security rights locally OSecurityUser oUser = session.getUser(); OSecurityUser dbUser = db.getUser(); if(oUser!=null && oUser.getDocument()!=null && oUser.getDocument().getIdentity()!=null && (!oUser.getDocument().getIdentity().isValid() || dbUser==null || !Objects.equal(dbUser.getName(), oUser.getName()))) { db.setUser(db.getMetadata().getSecurity().getUser(oUser.getName())); } db.begin(); }
Example #15
Source File: OrientDbWebSession.java From wicket-orientdb with Apache License 2.0 | 5 votes |
@Override public boolean authenticate(String username, String password) { ODatabaseDocumentInternal currentDB = getDatabase(); try { boolean inTransaction = currentDB.getTransaction().isActive(); IOrientDbSettings settings = OrientDbWebApplication.get().getOrientDbSettings(); ODatabaseDocumentInternal newDB = settings.getDatabasePoolFactory().get(settings.getDBUrl(), username, password).acquire(); if(newDB!=currentDB) { currentDB.activateOnCurrentThread(); currentDB.commit(); currentDB.close(); newDB.activateOnCurrentThread(); } setUser(username, password); userModel.setObject(newDB.getUser().getDocument()); // user = newDB.getMetadata().getSecurity().getUser(username); // newDB.setUser(user); if(inTransaction && !newDB.getTransaction().isActive()) newDB.begin(); return true; } catch (OSecurityAccessException e) { currentDB.activateOnCurrentThread(); return false; } }
Example #16
Source File: DatabaseThreadUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Utility function for working around "ODatabaseException: Database instance is not set in current thread" issues. * The current database ThreadLocal is preserved and restored after calling the lambda. */ public static <T> T withOtherDatabase(Callable<T> function) { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined(); try { return function.call(); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } finally { ODatabaseRecordThreadLocal.INSTANCE.set(db); } }
Example #17
Source File: EntityLog.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private OLocalPaginatedStorage storage() { if (storage == null || storage.isClosed()) { // use temp TX to get local storage; note we don't need a TX when reading write-ahead-log ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.instance().getIfDefined(); try (ODatabaseDocumentInternal db = databaseProvider.get().acquire()) { storage = (OLocalPaginatedStorage) db.getStorage().getUnderlying(); } finally { ODatabaseRecordThreadLocal.instance().set(currentDb); } } return storage; }
Example #18
Source File: EntityHook.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Returns the current DB connection. Normally this is whichever connection is active on the thread. * But when performing a commit we always return the connection which is being committed, so we can * track changes even when another connection is used to "fix" records during that commit. */ private ODatabaseDocumentInternal getCurrrentDb() { ODatabase db = commitDb.get(); if (db == null) { db = ODatabaseRecordThreadLocal.instance().get(); } return (ODatabaseDocumentInternal) db; }
Example #19
Source File: OrientDbWebSession.java From wicket-orientdb with Apache License 2.0 | 4 votes |
/** * @return {@link ODatabaseDocument} for current request */ public ODatabaseDocumentInternal getDatabase() { return ODatabaseRecordThreadLocal.instance().get(); }
Example #20
Source File: OPropertyValueValidator.java From wicket-orientdb with Apache License 2.0 | 4 votes |
protected ODatabaseDocumentInternal getDatabase() { return (ODatabaseDocumentInternal)OrientDbWebSession.get().getDatabase(); }
Example #21
Source File: OLuceneIndexManagerAbstract.java From orientdb-lucene with Apache License 2.0 | 4 votes |
protected ODatabaseDocumentInternal getDatabase() { return ODatabaseRecordThreadLocal.INSTANCE.get(); }
Example #22
Source File: OLuceneTextOperator.java From orientdb-lucene with Apache License 2.0 | 4 votes |
protected static ODatabaseDocumentInternal getDatabase() { return ODatabaseRecordThreadLocal.INSTANCE.get(); }
Example #23
Source File: OLuceneClassIndexManager.java From orientdb-lucene with Apache License 2.0 | 4 votes |
private ODatabaseDocumentInternal getDatabase() { return ODatabaseRecordThreadLocal.INSTANCE.get(); }
Example #24
Source File: OLuceneIndexFactory.java From orientdb-lucene with Apache License 2.0 | 4 votes |
@Override public OIndexInternal<?> createIndex(String name, ODatabaseDocumentInternal database, String indexType, String algorithm, String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException { return createIndex(name, database, indexType, algorithm, valueContainerAlgorithm, metadata); }
Example #25
Source File: OLuceneIndexFactory.java From orientdb-lucene with Apache License 2.0 | 4 votes |
protected OIndexInternal<?> createIndex(String name, ODatabaseDocumentInternal oDatabaseRecord, String indexType, String algorithm, String valueContainerAlgorithm, ODocument metadata) throws OConfigurationException { return createLuceneIndex(name, oDatabaseRecord, indexType, valueContainerAlgorithm, metadata); }