public ODocument getPerspectiveByName(ODatabaseDocument db, String name) { List<ODocument> perspectives = db.query(new OSQLSynchQuery<ODocument>("select from "+OCLASS_PERSPECTIVE+" where name CONTAINSVALUE ?"), name); if(perspectives!=null && !perspectives.isEmpty()) { return perspectives.get(0); } else { return null; } }
protected List<T> queryList(final OPersistenceSession session, String sql, Object... args) { ODatabaseDocument db = session.getDatabase(); List<ODocument> ret = db.query(new OSQLSynchQuery<>(sql), args); if(ret==null) return Collections.emptyList(); return new ArrayList<T>(Lists.transform(ret, new Function<ODocument, T>() { @Override public T apply(ODocument input) { return mapToEntity(input, null, session); } })); }
@Override public ODocument getExistingDashboard(String domain, String tab, IModel<?> dataModel) { ODatabaseDocument db = getDatabase(); List<ODocument> dashboards = db.query(new OSQLSynchQuery<ODocument>("select from "+OCLASS_DASHBOARD+ " where "+OPROPERTY_DOMAIN+" = ?"+ " and "+OPROPERTY_TAB+" = ?"), domain, tab); if(dashboards==null || dashboards.isEmpty()) return null; else return dashboards.get(0); }
protected T querySingle(OPersistenceSession session, String sql, Object... args) { ODatabaseDocument db = session.getDatabase(); List<ODocument> ret = db.query(new OSQLSynchQuery<>(sql, 1), args); return ret==null || ret.isEmpty()?null:mapToEntity(ret.get(0), null, session); }
/** * Search {@link OMail} by given name * @param name {@link String} mail name * @return {@link Optional<OMail>} mail or empty optional if mail with given name doesn't exists */ public static Optional<OMail> getOMailByName(String name) { return DBClosure.sudo(db -> { String sql = String.format("select from %s where %s = ?", OMail.CLASS_NAME, OMail.OPROPERTY_NAME); List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql, 1), name); return getFromIdentifiables(identifiables, OMail::new); }); }
/** * Search user by given field and value * @param field {@link String} field * @param value {@link String} value * @return {@link Optional<OrienteerUser>} user which field contains given value */ private static Optional<OrienteerUser> getUserBy(String field, String value) { return DBClosure.sudo(db -> { String sql = String.format("select from %s where %s = ?", OrienteerUser.CLASS_NAME, field); List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql, 1), value); return getFromIdentifiables(identifiables, OrienteerUser::new); }); }
public static ODocument getOrCreatePerspectiveItem(ODatabaseDocument db, ODocument perspective, String key, List<String> tags) { Map<String, String> localizedStrings = getLocalizedStrings(OrienteerWebApplication.get(), key, tags); List<ODocument> docs = db.query(new OSQLSynchQuery<>("select from " + PerspectivesModule.OCLASS_ITEM + " where name.values() contains ? and perspective = ?"), localizedStrings.get("en"), perspective); ODocument doc = docs != null && !docs.isEmpty() ? docs.get(0) : null; if (doc == null) { doc = new ODocument(PerspectivesModule.OCLASS_ITEM); doc.field("name", localizedStrings); } return doc; }
public static ODocument getOrCreateDashboard(ODatabaseDocument db, String className, String domain, String tab) { String sql = String.format("select from %s where %s = ?", OCLASS_DASHBOARD, OPROPERTY_CLASS); List<ODocument> docs = db.query(new OSQLSynchQuery<>(sql, 1), className); ODocument doc; if (docs == null || docs.isEmpty()) { doc = new ODocument(OCLASS_DASHBOARD); doc.field(OPROPERTY_DOMAIN, domain); doc.field(OPROPERTY_TAB, tab); doc.field(OPROPERTY_CLASS, className); doc.save(); } else doc = docs.get(0); return doc; }
@Override protected Boolean execute(ODatabaseDocument db) { List<ODocument> pages = db.query(new OSQLSynchQuery<ODocument>("select from "+PagesModule.OCLASS_PAGE)); for (ODocument pageDoc : pages) { if(pageDoc.field(PagesModule.OPROPERTY_PATH)!=null) add(pageDoc); } return true; } }.execute();
@Statement public List<String> selectHistoricProcessInstanceIdsByProcessDefinitionId(OPersistenceSession session, ListQueryParameterObject parameter) { ODatabaseDocument db = session.getDatabase(); List<ODocument> resultSet = db.query(new OSQLSynchQuery<>("select id from "+getSchemaClass()+" where processDefinition.id = ?"), parameter.getParameter()); return Lists.transform(resultSet, GET_ID_FUNCTION); }
/** * @return {@link Optional<ODocument>} which contains perspective {@link OrienteerUsersModule#ORIENTEER_USER_PERSPECTIVE} */ public static Optional<ODocument> getDefaultOrienteerUserPerspective() { return DBClosure.sudo(db -> { String sql = String.format("select from %s where name.en = ?", PerspectivesModule.OCLASS_PERSPECTIVE); String name = OUsersCommonUtils.getString(OrienteerWebApplication.lookupApplication(), OrienteerUsersModule.ORIENTEER_USER_PERSPECTIVE, Locale.ENGLISH); List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql, 1), name); return getDocument(identifiables); }); }
@Statement public List<String> selectProcessInstanceIdsByProcessDefinitionId(OPersistenceSession session, ListQueryParameterObject parameter) { ODatabaseDocument db = session.getDatabase(); List<ODocument> resultSet = db.query(new OSQLSynchQuery<>("select id from "+getSchemaClass()+" where processDefinition.id = ?"), parameter.getParameter()); return Lists.transform(resultSet, GET_ID_FUNCTION); }
@Statement public List<String> selectHistoricCaseInstanceIdsByCaseDefinitionId(OPersistenceSession session, ListQueryParameterObject parameter) { ODatabaseDocument db = session.getDatabase(); List<ODocument> resultSet = db.query(new OSQLSynchQuery<>("select id from "+getSchemaClass()+" where caseDefinitionId = ?"), parameter.getParameter()); return Lists.transform(resultSet, GET_ID_FUNCTION); } }
@Override public ODocument readAsDocument(String id, OPersistenceSession session) { String oid = (String) convertValueFromEntity("id", id); OIdentifiable oIdentifiable = session.lookupOIdentifiableForIdInCache(oid); if(oIdentifiable!=null) return oIdentifiable.getRecord(); else { ODatabaseDocument db = session.getDatabase(); List<ODocument> ret = db.query(new OSQLSynchQuery<>("select from "+getSchemaClass()+" where "+getPkField()+" = ?", 1), oid); return ret==null || ret.isEmpty()? null : ret.get(0); } }
@SuppressWarnings("unchecked") protected List<K> load() { ODatabaseDocument db = OrientDbWebSession.get().getDatabase(); OSQLSynchQuery<K> query = new OSQLSynchQuery<K>(prepareSql(null, null)); List<?> ret = db.query(enhanceContextByVariables(query), prepareParams()); return transformer==null?(List<K>)ret:Lists.transform(ret, (Function<Object, K>)transformer); }
@SuppressWarnings("unchecked") protected List<K> load() { ODatabaseDocument db = OrientDbWebSession.get().getDatabase(); OSQLSynchQuery<K> query = new OSQLSynchQuery<K>(prepareSql(null, null)); List<?> ret = db.query(enhanceContextByVariables(query), prepareParams()); return transformer==null?(List<K>)ret:Lists.transform(ret, (Function<Object, K>)transformer); }
public OGremlinResultSet querySql(String sql, Object... params) { this.tx().readWrite(); return executeWithConnectionCheck(() -> { makeActive(); OResultSet resultSet = database.query(sql, params); return new OGremlinResultSet(this, resultSet); }); }
@Override public void onRecordAfterRead(ODocument iDocument) { String script = "select sum(a, b) as value from "+iDocument.getIdentity(); List<ODocument> calculated = database.query(new OSQLSynchQuery<Object>(script)); if(calculated!=null && !calculated.isEmpty()) { iDocument.field("c", (Object) calculated.get(0).field("value")); } }
@Override public RESULT onTrigger(ODatabaseDocument db, ODocument doc, TYPE iType) { if(iType.equals(TYPE.AFTER_CREATE) || iType.equals(TYPE.AFTER_UPDATE) || iType.equals(TYPE.AFTER_DELETE)) { String name = doc.field("name"); List<ODocument> pds = db.query(new OSQLSynchQuery<ODocument>("select from "+ProcessDefinitionEntityHandler.OCLASS_NAME+" where resourceName = ?"), name); if(pds!=null) { DeploymentCache dc = OProcessEngineConfiguration.get().getDeploymentCache(); for(ODocument pd : pds) { dc.removeProcessDefinition((String) pd.field("id")); } } } return RESULT.RECORD_NOT_CHANGED; }
@Test public void testInstallingHooks() { ODatabaseDocument db = wicket.getTester().getDatabase(); OClass clazz = db.getMetadata().getSchema().getClass("TestHooks"); assertNotNull(clazz); List<ODocument> ret = db.query(new OSQLSynchQuery<ODocument>("select from TestHooks")); assertTrue(ret.size()>0); ODocument doc = ret.get(0); assertEquals("HOOK", doc.field("name")); } }