Example usage for org.hibernate SQLQuery setString

List of usage examples for org.hibernate SQLQuery setString

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setString.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setString(int position, String val) 

Source Link

Document

Bind a positional String-valued parameter.

Usage

From source file:com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl.java

License:Apache License

private <T extends ObjectType> String nonOverwriteAddObjectAttempt(PrismObject<T> object, ObjectType objectType,
        RObject rObject, String originalOid, Session session)
        throws ObjectAlreadyExistsException, SchemaException, DtoTranslationException {

    // check name uniqueness (by type)
    if (StringUtils.isNotEmpty(originalOid)) {
        LOGGER.trace("Checking oid uniqueness.");
        //todo improve this table name bullshit
        Class hqlType = ClassMapper.getHQLTypeClass(object.getCompileTimeClass());
        SQLQuery query = session
                .createSQLQuery("select count(*) from " + RUtil.getTableName(hqlType) + " where oid=:oid");
        query.setString("oid", object.getOid());

        Number count = (Number) query.uniqueResult();
        if (count != null && count.longValue() > 0) {
            throw new ObjectAlreadyExistsException("Object '" + object.getCompileTimeClass().getSimpleName()
                    + "' with oid '" + object.getOid() + "' already exists.");
        }//from   w  w  w. j av a 2s  .com
    }

    updateFullObject(rObject, object);

    LOGGER.trace("Saving object (non overwrite).");
    String oid = (String) session.save(rObject);

    //todo finish orgClosureManager
    //Collection<ReferenceDelta> modifications = createAddParentRefDelta(object);
    //orgClosureManager.updateOrgClosure(modifications, session, oid, object.getCompileTimeClass(),
    //        OrgClosureManager.Operation.ADD);

    if (objectType instanceof OrgType || !objectType.getParentOrgRef().isEmpty()) {
        long time = System.currentTimeMillis();
        LOGGER.trace("Org. structure closure table update started.");
        objectType.setOid(oid);
        fillHierarchy(rObject, session, true);
        LOGGER.trace("Org. structure closure table update finished ({} ms).",
                new Object[] { (System.currentTimeMillis() - time) });
    }

    return oid;
}

From source file:com.formkiq.core.dao.ClientDaoImpl.java

License:Apache License

@SuppressWarnings("resource")
@Override/*from   w w w .jav  a 2  s . c  om*/
public ClientDTO findClient(final User user, final String client) {

    String sql = "select fl.client_id as client, " + " additional_information as clientname, "
            + " authorized_grant_types as granttypesasstring" + " from oauth_client_details fl "
            + " where fl.client_id=:client";

    Session session = getEntityManager().unwrap(Session.class);

    SQLQuery query = session.createSQLQuery(sql.toString());

    ClientDTO dto = (ClientDTO) query.setString("client", client)
            .setResultTransformer(new AliasToBeanResultTransformer(ClientDTO.class)).uniqueResult();

    if (dto != null) {
        dto.setClientname(getClientnameFromString(dto.getClientname()));
    }

    return dto;
}

From source file:com.globalsight.everest.permission.PermissionManagerLocal.java

License:Apache License

/**
 * Queries all permissiongroups for this user.
 * // w w  w.  ja v  a2 s  . com
 * @param p_userId
 *            user
 * @return Collection of PermissionGroups
 */
@SuppressWarnings("unchecked")
public Collection<PermissionGroup> getAllPermissionGroupsForUser(String p_userId)
        throws PermissionException, RemoteException {
    String sql = "select p.* from permissiongroup p, "
            + " permissiongroup_user pu where p.id = pu.permissiongroup_id "
            + " and pu.user_id = :USER_ID_ARG ";

    Session session = HibernateUtil.getSession();
    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(PermissionGroupImpl.class);
    query.setString("USER_ID_ARG", p_userId);

    try {
        return query.list();
    } catch (Exception e) {
        throw new PermissionException(e);
    }
}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the task instances in all status.
  * /*  w  ww  .j  a  v a 2  s .  c o  m*/
  * @param p_userId
  *            the user id.
  * @param p_session
  *            the hibernate session.
  * @param p_pm
  *            is pm or not (true:PM|false:user).
  * 
  * @return the task instances in all status.
  */
@SuppressWarnings("unchecked")
private static List<TaskInstance> allTaskInstances(String p_userId, Session p_session, boolean p_pm) {
    SQLQuery query = null;
    if (p_pm) {
        query = p_session.createSQLQuery(ALL_TASK_INSTANCES_PM);
        query.setString(PM, p_userId);
    } else {
        query = p_session.createSQLQuery(SqlHolder.allTask);
        query.setString(ACTOR_ID, p_userId);
        query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
        query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);

    }
    query.addEntity(TaskInstance.class);

    return query.list();
}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the completed task instances.//from  ww w.j a v a  2 s . c o  m
  * 
  * @param p_userId
  *            the user id.
  * @param p_session
  *            the hibernate session.
  * @param p_pm
  *            is pm or not (true:PM|false:user).
  * 
  * @return the completed task instances.
  */
@SuppressWarnings("unchecked")
private static List<TaskInstance> completedTaskInstances(String p_userId, Session p_session, boolean p_pm) {
    SQLQuery query = null;
    if (p_pm) {
        query = p_session.createSQLQuery(COMPLETED_TASK_INSTANCES_PM);
        query.setString(PM, p_userId);
    } else {
        query = p_session.createSQLQuery(COMPLETED_TASK_INSTANCES);
        query.setString(ACTOR_ID, p_userId);
    }
    query.addEntity(TaskInstance.class);

    return query.list();
}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the accepted task instances./*from ww w  .j a v a2s. c  o  m*/
  * 
  * @param p_userId
  *            the user id.
  * @param p_session
  *            the hibernate session.
  * @param p_pm
  *            is pm or not (true:PM|false:user).
  * 
  * @return the accepted task instances.
  */
@SuppressWarnings("unchecked")
private static List<TaskInstance> acceptedTaskInstances(String p_userId, Session p_session, boolean p_pm) {
    SQLQuery query = null;
    if (p_pm) {
        query = p_session.createSQLQuery(ACCEPTED_TASK_INSTANCES_PM);
        query.setString(PM, p_userId);
    } else {
        query = p_session.createSQLQuery(ACCEPTED_TASK_INSTANCES);
        query.setString(ACTOR_ID, p_userId);

    }
    query.addEntity(TaskInstance.class);

    return query.list();
}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the active(available) task instances.
  * /*from  w  w  w  .  j a v a 2  s . c  om*/
  * @param p_userId
  *            the user id.
  * @param p_session
  *            the hibernate session.
  * @param p_pm
  *            is pm or not (true:PM|false:user).
  * 
  * @return the active(available) task instances.
  */
@SuppressWarnings("unchecked")
private static List<TaskInstance> activeTaskInstances(String p_userId, Session p_session, boolean p_pm) {
    SQLQuery query = null;
    if (p_pm) {
        query = p_session.createSQLQuery(SqlHolder.activeTaskPm);
        query.setString(PM, p_userId);
        if (c_logger.isDebugEnabled()) {
            c_logger.debug("The query sql is " + SqlHolder.activeTaskPm);
        }
    } else {
        query = p_session.createSQLQuery(SqlHolder.activeTask);
        if (c_logger.isDebugEnabled()) {
            c_logger.debug("The query sql is " + SqlHolder.activeTask);
        }
        query.setString(ACTOR_ID, p_userId);
    }

    query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
    query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);
    query.addEntity(TaskInstance.class);

    return query.list();
}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Gets the rejected task instances.//from   w  w w .j ava  2  s  .  c om
  * 
  * @param p_userId
  *            the user id.
  * @param p_session
  *            the hibernate session.
  * @param p_pm
  *            is pm or not (true:PM|false:user).
  * 
  * @return the rejected task instances.
  */
@SuppressWarnings("unchecked")
private static List<TaskInstance> rejectedTaskInstances(String p_userId, Session p_session, boolean p_pm) {
    SQLQuery query = null;
    if (p_pm) {
        query = p_session.createSQLQuery(SqlHolder.rejectTaskPm);
        query.setString(PM, p_userId);
    } else {
        query = p_session.createSQLQuery(SqlHolder.rejectTask);
        query.setString(USER_ID, p_userId);
    }
    query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
    query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);
    query.addEntity(TaskInstance.class);

    return query.list();
}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
  * Judges whether the user is rejected for the specified
  * <code>TaskInstance</code>. <br>
  * The rejected user will be stored in the table
  * <code>JBPM_GS_VARIABLE</code>.
  * //from ww w  .  j  a v a2s  . co  m
  * @param ctx
  *            {@code JbpmContext}
  * @param userId
  *            the user id.
  * @param taskInstance
  *            {@code TaskInstance}
  * @return <code>true</code> when the user is reject by the specified
  *         taskinstance.
  */
public static boolean isUserRejected(JbpmContext ctx, String userId, TaskInstance taskInstance) {

    SQLQuery query = null;
    Session session = ctx.getSession();

    query = session.createSQLQuery(SqlHolder.isUserReject);

    query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
    query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);
    query.setString(ACTOR_ID, userId);
    query.setLong(TASK_ID, taskInstance.getId());

    Number num = (Number) query.uniqueResult();

    return num == null ? false : num.longValue() > 0;

}

From source file:com.globalsight.everest.workflow.WorkflowJbpmPersistenceHandler.java

License:Apache License

/**
 * Fix for GBS-1470//from ww  w.ja v  a 2 s  . c  o  m
  * Judges whether the user is rejected for (This user Rejected the task first, then reassign to this user) 
  * 
  * @param ctx
  *            {@code JbpmContext}
  * @param userId
  *            the user id.
  * @param taskInstance
  *            {@code TaskInstance}
  * @return <code>true</code> The user reject, and not been reassigned.
  */
public static boolean isUserRejectedForReassign(JbpmContext ctx, String userId, TaskInstance taskInstance) {

    SQLQuery query = null;
    Session session = ctx.getSession();

    query = session.createSQLQuery(SqlHolder.isUserRejectForReassign);

    query.setString(VARIABLE_NAME, WorkflowConstants.VARIABLE_IS_REJECTED);
    query.setString(CATEGORY, VARIABLE_CATEGORY_REJECT);
    query.setString(ACTOR_ID, userId);
    query.setLong(TASK_ID, taskInstance.getId());
    long id = taskInstance.getId();
    Number num = (Number) query.uniqueResult();

    return num == null ? false : num.longValue() > 0;

}