Java Code Examples for com.orientechnologies.orient.core.db.document.ODatabaseDocument#query()

The following examples show how to use com.orientechnologies.orient.core.db.document.ODatabaseDocument#query() . 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: OQueryModel.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
/**
 * Get the size of the data
 * @return results size
 */
public long size()
{
	if(size==null)
	{
 	ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
 	OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(queryManager.getCountSql());
 	List<ODocument> ret = db.query(enhanceContextByVariables(query), prepareParams());
 	if(ret!=null && ret.size()>0)
 	{
 		Number sizeNumber = ret.get(0).field("count");
 		size = sizeNumber!=null?sizeNumber.longValue():0;
 	}
 	else
 	{
 		size = 0L;
 	}
	}
	return size;
}
 
Example 2
Source File: DefaultDashboardManager.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public List<String> listExistingTabs(String domain, IModel<?> dataModel, OClass oClass) {
	if(oClass==null) return listExistingTabs(domain, dataModel);
	ODatabaseDocument db = getDatabase();
	List<String> ret = new ArrayList<String>();
	List<String> oClassAndSuper = new ArrayList<>();
	oClassAndSuper.add(oClass.getName());
	oClassAndSuper.addAll(oClass.getSuperClassesNames());
	List<ODocument>  dashboards = db.query(
			new OSQLSynchQuery<ODocument>("select distinct("+OPROPERTY_TAB+") as "+OPROPERTY_TAB+" from "+OCLASS_DASHBOARD+
									" where "+OPROPERTY_DOMAIN+" = ?"+
									" and "+OPROPERTY_CLASS+" IN ?"), domain, oClassAndSuper);
	if(dashboards!=null && !dashboards.isEmpty()) {
		ret.addAll(Lists.transform(dashboards, new GetODocumentFieldValueFunction<String>(OPROPERTY_TAB)));
	}
	return ret;
}
 
Example 3
Source File: OrientDBSettingsTest.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 4
Source File: OQueryModel.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@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);
   }
 
Example 5
Source File: DefaultDashboardManager.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: AbstractEntityHandler.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
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);
		}
	}));
}
 
Example 7
Source File: OrienteerUsersModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private ODocument updateAndGetUserReader(ODatabaseDocument db) {
    String sql = String.format("select from %s where name = ?", OUser.CLASS_NAME);
    List<ODocument> docs = db.query(new OSQLSynchQuery<>(sql, 1), "reader");
    ODocument reader = docs.get(0);
    Set<OIdentifiable> users = reader.field(ORestrictedOperation.ALLOW_READ.getFieldName(), Set.class);
    if (users == null || users.isEmpty()) {
        reader.field(ORestrictedOperation.ALLOW_READ.getFieldName(), Collections.singleton(reader));
    } else {
        users.add(reader);
        reader.field(ORestrictedOperation.ALLOW_READ.getFieldName(), users);
    }
    reader.save();
    return reader;
}
 
Example 8
Source File: DefaultDashboardManager.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listExistingTabs(String domain, IModel<?> dataModel) {
	ODatabaseDocument db = getDatabase();
	List<String> ret = new ArrayList<String>();
	List<ODocument>  dashboards = db.query(new OSQLSynchQuery<ODocument>("select from "+OCLASS_DASHBOARD+
													" where "+OPROPERTY_DOMAIN+" = ?"), domain);
	if(dashboards!=null && !dashboards.isEmpty()) {
		ret.addAll(Lists.transform(dashboards, new GetODocumentFieldValueFunction<String>(OPROPERTY_TAB)));
	}
	return ret;
}
 
Example 9
Source File: HistoricCaseInstanceEventEntityHandler.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 10
Source File: HistoricProcessInstanceEventEntityHandler.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 11
Source File: AbstractEntityHandler.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 12
Source File: OAuth2Repository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static List<OAuth2Service> getOAuth2Services(ODatabaseDocument db, boolean active) {
    String sql = selectFromBy(OAuth2Service.CLASS_NAME, OAuth2Service.PROP_ACTIVE);
    List<OIdentifiable> services = db.query(new OSQLSynchQuery<>(sql), active);
    return CommonUtils.mapIdentifiables(services, OAuth2Service::new);
}
 
Example 13
Source File: OAuth2Repository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static Optional<OAuth2ServiceContext> getServiceContextByState(ODatabaseDocument db, String state) {
    String sql = String.format("select from %s where %s = ?",
            OAuth2ServiceContext.CLASS_NAME, OAuth2ServiceContext.PROP_STATE);
    List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql, 1), state);
    return CommonUtils.getFromIdentifiables(identifiables, OAuth2ServiceContext::new);
}
 
Example 14
Source File: OSmsRepository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static Optional<ODocument> getSmsByNameAsDocument(ODatabaseDocument db, String name) {
  String sql = String.format("select from %s where %s = ?", OSMS.CLASS_NAME, OSMS.PROP_NAME);
  List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql, 1), name);
  return CommonUtils.getDocument(identifiables);
}
 
Example 15
Source File: OPageRepository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static List<ODocument> getPages(ODatabaseDocument db) {
    String sql = String.format("select from %s", PagesModule.OCLASS_PAGE);
    List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql));
    return CommonUtils.getDocuments(identifiables);
}
 
Example 16
Source File: OAuth2Repository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static List<OAuth2Service> getOAuth2Services(ODatabaseDocument db) {
    String sql = String.format("select from %s", OAuth2Service.CLASS_NAME);
    List<OIdentifiable> services = db.query(new OSQLSynchQuery<>(sql));
    return CommonUtils.mapIdentifiables(services, OAuth2Service::new);
}
 
Example 17
Source File: ONotificationModuleRepository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static ODocument getModuleAsDocument(ODatabaseDocument db) {
  String sql = String.format("select from %s where %s = ?", ONotificationModule.OMODULE_CLASS, ONotificationModule.OMODULE_NAME);
  List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql, 1), ONotificationModule.NAME);
  return CommonUtils.getDocument(identifiables)
          .orElseThrow(() -> new IllegalStateException("There is no module with name: " + ONotificationModule.NAME));
}
 
Example 18
Source File: OLoggerRepository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static Optional<ODocument> getOCorrelationIdGeneratorAsDocument(ODatabaseDocument db, String alias) {
    String sql = String.format("select from %s where %s = ?", OCorrelationIdGeneratorModel.CLASS_NAME,
            OCorrelationIdGeneratorModel.PROP_ALIAS);
    List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql, 1), alias);
    return CommonUtils.getDocument(identifiables);
}
 
Example 19
Source File: OLoggerRepository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static List<OLoggerEventModel> getEventsByCorrelationId(ODatabaseDocument db, String correlationId) {
    String sql = String.format("select from %s where %s = ?", OLoggerEventModel.CLASS_NAME,
            OLoggerEventModel.PROP_CORRELATION_ID);
    List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql), correlationId);
    return CommonUtils.mapIdentifiables(identifiables, OLoggerEventModel::new);
}
 
Example 20
Source File: OAuth2Repository.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public static Optional<OAuth2Service> getOAuth2ServiceByProvider(ODatabaseDocument db, String provider, boolean active) {
    String sql = String.format("select from %s where %s = ? and %s = ?", OAuth2Service.CLASS_NAME,
            OAuth2Service.PROP_PROVIDER, OAuth2Service.PROP_ACTIVE);
    List<OIdentifiable> identifiables = db.query(new OSQLSynchQuery<>(sql, 1), provider, active);
    return CommonUtils.getFromIdentifiables(identifiables, OAuth2Service::new);
}