Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] query cdo objects on server side for ReadAccess
[CDO] query cdo objects on server side for ReadAccess [message #703326] Wed, 27 July 2011 12:57 Go to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I am trying to check whether a user has read access to an object.
I added a RepositoryReadAccessValidator to the repository, but I am missing any clues on how to query objects from the store.
In a WriteAccessHandler this seems to be possible, e.g.:
CDOView view = CDOServerUtil.openView(commitContext, isConfig(LEGACY));

Is there a way to query the store when org.eclipse.emf.cdo.server.CDOServerUtil.RepositoryReadAccessValidator.handleRevisionsBeforeSending(ISession, CDORevision[], List<CDORevision>) is being executed on the server side?
Re: [CDO] query cdo objects on server side for ReadAccess [message #703476 is a reply to message #703326] Wed, 27 July 2011 15:47 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 27.07.2011 14:57, schrieb Erdal Karaca:
> I am trying to check whether a user has read access to an object.
> I added a RepositoryReadAccessValidator to the repository, but I am missing any clues on how to query objects from the store.
> In a WriteAccessHandler this seems to be possible, e.g.:
> CDOView view = CDOServerUtil.openView(commitContext, isConfig(LEGACY));
>
> Is there a way to query the store when org.eclipse.emf.cdo.server.CDOServerUtil.RepositoryReadAccessValidator.handleRevisionsBeforeSending(ISession, CDORevision[], List<CDORevision>) is being executed on the server side?

You should be able to use any of these:

CDOServerUtil.openView(ISession, CDOBranchPoint, boolean, CDORevisionProvider)
CDOServerUtil.openView(ISession, CDOBranchPoint, boolean)

If you have an IView at hand, you can also use this one:

CDOServerUtil.openView(IView, boolean)

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] query cdo objects on server side for ReadAccess [message #703597 is a reply to message #703476] Wed, 27 July 2011 18:33 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
May I "extract" an IView from the ISession provided in the method args?
I.e., can I use any of the views available through ISession.getViews(), or the like?
Would that be ok?

And, how would I create/obtain a CDOBranchPoint (not even sure what that is)?

[Updated on: Wed, 27 July 2011 18:34]

Report message to a moderator

Re: [CDO] query cdo objects on server side for ReadAccess [message #703906 is a reply to message #703597] Thu, 28 July 2011 03:26 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 27.07.2011 20:33, schrieb Erdal Karaca:
> May I "extract" an IView from the ISession provided in the method args?
> I.e., can I use any of the views available through ISession.getViews(), or the like?
> Would that be ok?
The IView is, in this case, only used to determine a CDOBranchPoint, which, in turn, is only needed to configure the ManagedRevisionProvider. If your repository is for example in non-branching mode then you already know that the branch is always implicitely the main branch (accessible through session.getManager().getRepository().getBranchManager().getMainBranch()) and you can use any mainBranch.getPoint(x). If your repository is in non-auditing mode then you already know that the branch point is always implicitely mainBranch.getHead().

Does that help?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] query cdo objects on server side for ReadAccess [message #703971 is a reply to message #703906] Thu, 28 July 2011 06:14 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
So, this is how my code looks like:

CDOView view = CDOServerUtil.openView(session,
		session.getManager().getRepository()
				.getBranchManager().getMainBranch()
				.getPoint(System.currentTimeMillis()),
		false);


If I create a sql query and execute it, I will get an UnsupportedOperationException:

java.lang.UnsupportedOperationException
	at org.eclipse.emf.cdo.internal.server.ServerCDOView$ServerCDOSession.getSessionProtocol(ServerCDOView.java:358)
	at org.eclipse.emf.internal.cdo.query.CDOQueryImpl.getResult(CDOQueryImpl.java:86)
	at org.eclipse.emf.internal.cdo.query.CDOQueryImpl.getResult(CDOQueryImpl.java:92)
...


My query is created and executed like this:

CDOQuery q = view
		.createQuery("sql", "select 1+1 from dual");
q.setParameter("cdoObjectQuery", Boolean.FALSE);
Object result = q.getResult();
Re: [CDO] query cdo objects on server side for ReadAccess [message #703996 is a reply to message #703971] Thu, 28 July 2011 06:30 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 28.07.2011 08:14, schrieb Erdal Karaca:
> So, this is how my code looks like:
>
>
> CDOView view = CDOServerUtil.openView(session,
> session.getManager().getRepository()
> .getBranchManager().getMainBranch()
> .getPoint(System.currentTimeMillis()),
getPoint(System.currentTimeMillis()) only works properly if at least auditing is enabled. Otherwise you better use getPoint(CDOBranchPoint.UNSPECIFIED_DATE), which is equivalent to getHead().

> false);
>
>
> If I create a sql query and execute it, I will get an UnsupportedOperationException:
>
> java.lang.UnsupportedOperationException
> at org.eclipse.emf.cdo.internal.server.ServerCDOView$ServerCDOSession.getSessionProtocol(ServerCDOView.java:358)
> at org.eclipse.emf.internal.cdo.query.CDOQueryImpl.getResult(CDOQueryImpl.java:86)
> at org.eclipse.emf.internal.cdo.query.CDOQueryImpl.getResult(CDOQueryImpl.java:92)
ServerCDOView is a very restricted implementation of CDOView. Many operations are not supported in this light weight kind of view. Queries are not supported as of now. You can submit an enhancement request but I'm not sure when I will be able to work on it. Note that you can always open a full blown client session whereever and whenever you want. From there you can open a full blown CDOView and do what you want. Another option is to use the datasource of your DBStore directly to open a JDBC connection on your database. Then you could use the light-weight ServerCDOView to turn the CDOIDs from the JDBC result set into CDOObjects.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


> ..
>
>
> My query is created and executed like this:
>
>
> CDOQuery q = view
> .createQuery("sql", "select 1+1 from dual");
> q.setParameter("cdoObjectQuery", Boolean.FALSE);
> Object result = q.getResult();
>


Re: [CDO] query cdo objects on server side for ReadAccess [message #704025 is a reply to message #703996] Thu, 28 July 2011 07:39 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Thanks very much! I have decided to use the DBStore's JDBC Connection to query the db, this seems to work. Maybe, that is the best (performance) way as I just need to return a boolean value from the query...

For those being interested in how I did this, here is my code:


	@SuppressWarnings("restriction")
	public boolean checkObjectReadAccessJDBC(ISession session,
			CDORevision revision) {
		DBStore store = (DBStore) session.getManager().getRepository()
				.getStore();
		Connection c = store.getConnection();

		String userId = session.getUserID();
		String type = "object";
		String instance = revision.getID().toString();
		String permission = "'READ'";
		String query = "select 'true' from User0 u "
				+ " inner join Grant0 g on g.cdo_container = u.cdo_id "
				+ " inner join Permission p on g.permission = p.cdo_id"
				+ " where u.name=:USER_ID and instr(g.permissions, :PERMISSION)>0 "
				+ " and p.type = :TYPE and p.instance = :INSTANCE";

		PreparedStatement ps = null;
		ResultSet rs = null;

		try {
			ps = c.prepareStatement(query);
			ps.setString(1, userId);
			ps.setString(2, permission);
			ps.setString(3, type);
			ps.setString(4, instance);
			rs = ps.executeQuery();

			if (rs.next()) {
				String ok = rs.getString(1);
				return "true".equals(ok);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
			} catch (Exception e) {
				;
			}

			try {
				if (ps != null) {
					ps.close();
				}
			} catch (Exception e) {
				;
			}
		}

		return false;
	}


You would have to change the underlying query to your needs, of course...
Re: [CDO] query cdo objects on server side for ReadAccess [message #704033 is a reply to message #704025] Thu, 28 July 2011 07:48 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 28.07.2011 09:39, schrieb Erdal Karaca:
> Thanks very much! I have decided to use the DBStore's JDBC Connection to query the db, this seems to work.
Great ;-)

> Maybe, that is the best (performance) way as I just need to return a boolean value from the query...
>
> For those being interested in how I did this, here is my code:
>
>
>
> @SuppressWarnings("restriction")
> public boolean checkObjectReadAccessJDBC(ISession session,
> CDORevision revision) {
> DBStore store = (DBStore) session.getManager().getRepository()
> .getStore();
Casting to IDBStore would be better; functionally equivalent.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Previous Topic:[EMF] Latest EMF API documentation javadoc location
Next Topic:Problem resolving reference to another ecore file (null fields) [SOLVED]
Goto Forum:
  


Current Time: Thu Apr 25 09:03:19 GMT 2024

Powered by FUDForum. Page generated in 0.02991 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top