Home » Modeling » EMF » [CDO] query cdo objects on server side for ReadAccess
|
Re: [CDO] query cdo objects on server side for ReadAccess [message #703476 is a reply to message #703326] |
Wed, 27 July 2011 15:47 |
|
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
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 #703996 is a reply to message #703971] |
Thu, 28 July 2011 06:30 |
|
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();
>
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 #704025 is a reply to message #703996] |
Thu, 28 July 2011 07:39 |
Erdal Karaca 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...
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 09:03:19 GMT 2024
Powered by FUDForum. Page generated in 0.02991 seconds
|