List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:itensil.security.web.UserSpaceServlet.java
License:Open Source License
/** * /orgList// ww w.java 2 s. co m * * Output: * Group/User List XML * */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webOrgList(HttpServletRequest request, HttpServletResponse response) throws Exception { AuthenticatedUser self = (AuthenticatedUser) request.getUserPrincipal(); HibernateUtil.beginTransaction(); HibernateUtil.readOnlySession(); UserSpaceEntity uspace = (UserSpaceEntity) self.getUserSpace(); if (!uspace.getFeatures().contains("orgs")) throw new UserSpaceException("Org feature required"); //HibernateUtil.getSession().refresh(uspace); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("list"); Query qry = HibernateUtil.getSession().getNamedQuery("USpace.groupsByType"); qry.setInteger("gtype", 1); qry.setEntity("uspace", uspace); for (GroupEntity grp : (List<GroupEntity>) qry.list()) { Element gElem = root.addElement("group"); gElem.addAttribute("id", grp.getGroupId()); gElem.addAttribute("name", grp.getSimpleName()); gElem.addAttribute("fullName", grp.getGroupName()); gElem.addAttribute("remoteKey", grp.getRemoteKey()); gElem.addAttribute("parentId", grp.getParentGroupId()); } HibernateUtil.commitTransaction(); ServletUtil.noCache(response); doc.write(response.getWriter()); }
From source file:itensil.security.web.UserSpaceServlet.java
License:Open Source License
/** * /addOrg//from ww w.ja v a2 s. c om * * Input: * name * fullName * remoteKey * parentId or parentRemoteKey * */ @SuppressWarnings("unchecked") @ContentType("text/xml") public void webAddOrg(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, String> params = RequestUtil.readParameters(request, new String[] { "name", "fullName", "remoteKey", "parentId", "parentRemoteKey" }); HibernateUtil.beginTransaction(); AuthenticatedUser self = (AuthenticatedUser) request.getUserPrincipal(); UserSpaceEntity uspace = (UserSpaceEntity) self.getUserSpace(); if (!uspace.getFeatures().contains("orgs")) throw new UserSpaceException("Org feature required"); HibernateUtil.getSession().refresh(uspace); GroupEntity grp = new GroupEntity(); grp.initNew(); grp.setUserSpaceEntity(uspace); grp.setGroupType(1); grp.setSimpleName(params.get("name")); grp.setGroupName(params.get("fullName")); if (Check.isEmpty(grp.getGroupName())) grp.setGroupName(grp.getSimpleName()); grp.setRemoteKey(params.get("remoteKey")); GroupEntity parGrp = null; if (!Check.isEmpty(params.get("parentId"))) { parGrp = (GroupEntity) uspace.resolve(new DefaultGroup(params.get("parentId"))); } else if (!Check.isEmpty(params.get("parentRemoteKey"))) { Query qry = HibernateUtil.getSession().getNamedQuery("USpace.groupByRemote"); qry.setString("rkey", params.get("parentRemoteKey")); qry.setEntity("uspace", uspace); parGrp = (GroupEntity) qry.uniqueResult(); } if (parGrp != null) { grp.setParentGroupId(parGrp.getGroupId()); } HibernateUtil.getSession().save(grp); HibernateUtil.commitTransaction(); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("ok"); root.addAttribute("id", grp.getGroupId()); ServletUtil.noCache(response); doc.write(response.getWriter()); }
From source file:itensil.workflow.activities.state.Activity.java
License:Open Source License
@SuppressWarnings("unchecked") public Set<Activity> getActiveChildren() { if (activeChildren == null) { Query qry = HibernateUtil.getSession().getNamedQuery("Activity.getActiveChildren"); qry.setEntity("parent", this); activeChildren = new LinkedHashSet<Activity>(qry.list()); }//w w w . j av a 2 s .c o m return activeChildren; }
From source file:itensil.workflow.activities.state.ActivityStateStore.java
License:Open Source License
public Collection<StepState<Activity>> getActiveSteps(SubState[] sStates) throws StateException { Integer sStateInts[] = new Integer[sStates.length]; for (int ii = 0; ii < sStates.length; ii++) sStateInts[ii] = sStates[ii].ordinal(); Query qry = getSession().getNamedQuery("FlowState.getActiveSteps"); qry.setEntity("flow", getFlow()); qry.setParameterList("subStates", sStateInts); List items = qry.list();//from w ww .j a va2 s . c o m ArrayList<StepState<Activity>> states = new ArrayList<StepState<Activity>>(items.size()); for (Object os : items) { states.addAll(((Activity) os).getStates().values()); } return states; }
From source file:itensil.workflow.activities.state.ActivityStateStore.java
License:Open Source License
protected ActivityTimer getActivityTimer(Timer timer, Activity token, boolean create) throws StateException { ActivityTimer att = null;/*from w ww.j a va 2s . c o m*/ Query qry = getSession().getNamedQuery("Timer.getTimer"); qry.setString("tid", timer.getId()); qry.setEntity("act", token); att = (ActivityTimer) qry.uniqueResult(); if (att == null && create) { att = new ActivityTimer(); att.setActivity(token); att.setTimerId(timer.getId()); } return att; }
From source file:itensil.workflow.activities.state.ActivityStateStore.java
License:Open Source License
public void clearAllTimers() throws StateException { Query qry = getSession().getNamedQuery("Timer.clearTimers"); qry.setEntity("flow", getFlow()); qry.executeUpdate();// w w w . j a va2 s . c o m }
From source file:itensil.workflow.activities.state.ActivityStateStore.java
License:Open Source License
/** * This implementations assumes log ids always count up * @param token/*from www. j a v a 2 s .c o m*/ * @throws StateException */ @SuppressWarnings("unchecked") public void rollbackTx(Activity token, String txId) throws StateException { if (!token.getStates().isEmpty()) { Session sess = getSession(); ActivityStepState state = null; // clear all states from this TX for (ActivityStepState ast : new ArrayList<ActivityStepState>(token.getStates().values())) { if (txId.equals(ast.getTxId())) { token.getStates().remove(ast.getStepId()); sess.delete(ast); } } // may instert sess.flush(); Query qry = sess.getNamedQuery("FlowState.lastLogTx"); qry.setEntity("flow", getFlow()); qry.setEntity("token", token); qry.setString("txId", txId); List<FlowStepLog> rLogs = qry.list(); FlowStepLog exLog = null; if (rLogs.isEmpty()) { throw new StateException("Cannot rollback, no previous logs"); } // find the oldest (initial) exit for (FlowStepLog rLog : rLogs) { if (rLog.getSubState().isExit()) { exLog = rLog; break; } } if (exLog == null) { // let the state removal be the end result return; } /* * Find the tx that matches an exit from the rolledback tx */ qry = sess.getNamedQuery("FlowState.nextToLastLogTx"); qry.setEntity("flow", getFlow()); qry.setEntity("token", token); qry.setLong("lastId", exLog.getId()); qry.setString("enterStepId", exLog.getStepId()); qry.setMaxResults(1); List<FlowStepLog> pLogs = qry.list(); String reTxId; if (pLogs.isEmpty()) { reTxId = generateTx(); } else { reTxId = pLogs.get(0).getTxId(); } if (!token.getStates().containsKey(exLog.getStepId())) { state = (ActivityStepState) createStepState(); state.setToken(token); state.setStepId(exLog.getStepId()); state.setTxId(reTxId); state.setSubState(exLog.getSubState().exitToEnter()); state.setTimeStamp(exLog.getTimeStamp()); state.setExpireTime(exLog.getExpireTime()); state.setAssignId(exLog.getUserId()); sess.save(state); token.getStates().put(state.getStepId(), (ActivityStepState) state); } } }
From source file:itensil.workflow.activities.state.ActivityStateStore.java
License:Open Source License
public Collection<StepState<Activity>> getActiveSteps(String stepId) throws StateException { Query qry = getSession().getNamedQuery("FlowState.getActiveStepsByStep"); qry.setEntity("flow", getFlow()); qry.setString("stepId", stepId); List items = qry.list();/*w ww . ja v a 2s . co m*/ ArrayList<StepState<Activity>> states = new ArrayList<StepState<Activity>>(items.size()); for (Object os : items) { states.addAll(((Activity) os).getStates().values()); } return states; }
From source file:itensil.workflow.activities.state.ActivityStateStore.java
License:Open Source License
public int countStepTokens(String stepId) throws StateException { Query qry = getSession().getNamedQuery("FlowState.countStepTokens"); qry.setEntity("flow", getFlow()); qry.setString("stepId", stepId); return ((Long) qry.iterate().next()).intValue(); }
From source file:itensil.workflow.activities.state.ActivityStateStore.java
License:Open Source License
public Collection<StepState<Activity>> getAllActiveSteps() throws StateException { Query qry = getSession().getNamedQuery("FlowState.getTokens"); qry.setEntity("flow", getFlow()); List items = qry.list();/*from ww w .jav a2s .c om*/ ArrayList<StepState<Activity>> states = new ArrayList<StepState<Activity>>(items.size()); for (Object itm : items) { states.addAll(((Activity) itm).getStates().values()); } return states; }