List of usage examples for org.hibernate SQLQuery addScalar
SQLQuery<T> addScalar(String columnAlias, Type type);
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine is used to verify that the requester is allowed to perform an operation on a particular data type. * This routine will return true if the operation is allowed, otherwise it will throw an exception. * @param iamGroupKey contains the iam group key which indicates which group the user is a member of. * @param dataTypeKey contains the data type key associated with the data element. * @param accessOperationKey contains the access operation key which indicates the type of operation. * @param requestedBy contains the access id of the perform who requested this operation. * @return will return true if successful. * @throws CprException will be thrown if the access is denied. */// www.j a v a 2 s. c o m public boolean isDataActionAuthorizedOldCode(final long iamGroupKey, final long dataTypeKey, final long accessOperationKey, final String requestedBy) throws CprException { // Verify that the operation being checked is against a valid data key. boolean dataKeyValid = false; try { // Build the query. final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append("SELECT data_types.data_type_key "); sb.append("FROM {h-schema}data_types "); sb.append("WHERE data_types.data_type_key = :data_type_key_in "); sb.append("AND data_types.active_flag = 'Y' "); // Create the query, bind the parameters and set the return type. final SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("data_type_key_in", dataTypeKey); query.addScalar("data_type_key", StandardBasicTypes.LONG); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { dataKeyValid = true; } } finally { if (!dataKeyValid) { throw new CprException(ReturnType.DATA_CHANGE_EXCEPTION, AccessType.get(dataTypeKey).toString()); } } // Do the query to determine if they have access. String readFlag = "N"; String writeFlag = "N"; String archiveFlag = "N"; final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append("SELECT v_group_data_type_access.read_flag, v_group_data_type_access.write_flag, "); sb.append("v_group_data_type_access.archive_flag "); sb.append("FROM {h-schema}v_group_data_type_access "); sb.append("WHERE v_group_data_type_access.iam_group_key = :iam_group_key_in "); sb.append("AND v_group_data_type_access.data_type_key = :data_type_key_in"); // Create the query, bind the parameters and set the return type. final SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("iam_group_key_in", iamGroupKey); query.setParameter("data_type_key_in", dataTypeKey); query.addScalar("read_flag", StandardBasicTypes.STRING); query.addScalar("write_flag", StandardBasicTypes.STRING); query.addScalar("archive_flag", StandardBasicTypes.STRING); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { Object[] res = (Object[]) it.next(); readFlag = (String) res[0]; writeFlag = (String) res[1]; archiveFlag = (String) res[2]; } boolean hasAccess = false; if (accessOperationKey == AccessType.ACCESS_OPERATION_ARCHIVE.index()) { hasAccess = Utility.isOptionYes(archiveFlag); } else if (accessOperationKey == AccessType.ACCESS_OPERATION_READ.index()) { hasAccess = Utility.isOptionYes(readFlag); } else if (accessOperationKey == AccessType.ACCESS_OPERATION_WRITE.index()) { hasAccess = Utility.isOptionYes(writeFlag); } if (!hasAccess) { throw new CprException(ReturnType.DATA_CHANGE_EXCEPTION, AccessType.get(dataTypeKey).toString()); } return hasAccess; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine is used to determine if an RA is authorize to assign an affiliation. * @param affiliationType - contains the affiliation * @param requestedBy - userid of the requestor * /* w ww . j av a 2 s . c o m*/ * @return true if ra is authorized for affiliation * * @throws CprException */ public boolean isAffiliationAccessAuthorized(final String affiliationType, final String requestedBy) throws CprException { final Long affiliationKey = AffiliationsType.valueOf(affiliationType.toUpperCase().trim()).index(); boolean affiliationKeyValid = false; final StringBuilder sb = new StringBuilder(BUFFER_SIZE); // Build the query. sb.append("SELECT affiliations.affiliation_key "); sb.append("FROM {h-schema}affiliations "); sb.append("WHERE affiliations.affiliation_key = :affiliation_key_in "); sb.append("AND affiliations.active_flag = 'Y' "); SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("affiliation_key_in", affiliationKey); query.addScalar("affiliation_key", StandardBasicTypes.LONG); Iterator<?> it = query.list().iterator(); if (it.hasNext()) { affiliationKeyValid = true; } if (!affiliationKeyValid) { throw new CprException(ReturnType.DATA_CHANGE_EXCEPTION, AffiliationsType.get(affiliationKey).toString()); } sb.setLength(0); sb.append("select * FROM {h-schema}ra_affiliation "); sb.append("WHERE affiliation_key = :affiliation_key_in "); sb.append("AND registration_authority_key= :ra_type_key_in "); sb.append("AND end_date is null "); // Create the query, bind the parameters and set the return type. query = session.createSQLQuery(sb.toString()); query.setParameter("affiliation_key_in", affiliationKey); query.setParameter("ra_type_key_in", getRegistrationAuthorityKey()); it = query.list().iterator(); if (!it.hasNext()) { affiliationKeyValid = false; } if (!affiliationKeyValid) { throw new CprException(ReturnType.DATA_CHANGE_EXCEPTION, AffiliationsType.get(affiliationKey).toString()); } return affiliationKeyValid; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine is used to obtain a person identifier using a psu id number. * @param psuId contains the psu id number. * @return person id if the psu id can be found, otherwise it will return a -1 to indicate an error. * @throws CprException // w w w. ja va2s.com */ public long getPersonIdUsingPsuId(final String psuId) throws CprException { Long personId = NOT_FOUND_VALUE; final String sqlQuery = "SELECT person_id FROM {h-schema}psu_id WHERE psu_id = :psuid AND end_date IS NULL"; final SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("psuid", psuId); query.addScalar("person_id", StandardBasicTypes.LONG); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { personId = (Long) it.next(); } if (personId.equals(NOT_FOUND_VALUE)) { throw new CprException(ReturnType.PERSON_NOT_FOUND_EXCEPTION); } return personId; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine is used to obtain a person identifier using a userid. * @param userid contains the userid to be used in the search. * @return person id if the userid can be found, otherwise it will return a -1 to indicate an error. * @throws CprException exception indicates a cpr specific java exception. */// w w w . j a v a 2s . c o m public long getPersonIdUsingUserid(final String userid) throws CprException { Long personId = NOT_FOUND_VALUE; final String sqlQuery = "SELECT person_id FROM {h-schema}userid WHERE userid = :userid"; final SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("userid", userid); query.addScalar("person_id", StandardBasicTypes.LONG); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { personId = (Long) it.next(); } if (personId.equals(NOT_FOUND_VALUE)) { throw new CprException(ReturnType.PERSON_NOT_FOUND_EXCEPTION); } return personId; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine is used to find a person using their id card number. * @param idCard contains the id card that is used to be search for. * @return will return the person identifier if a user was found with the correct id. * @throws CprException will be thrown if there are any CPR specific problems. */// w w w . j a va 2 s . c o m public long getPersonIdUsingIdCard(final String idCard) throws CprException { Long personId = NOT_FOUND_VALUE; final String sqlQuery = "SELECT person_id FROM {h-schema}person_id_card WHERE id_card_number = :idcard AND end_date IS NULL"; final SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("idcard", idCard); query.addScalar("person_id", StandardBasicTypes.LONG); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { personId = (Long) it.next(); } if (personId.equals(NOT_FOUND_VALUE)) { throw new CprException(ReturnType.PERSON_NOT_FOUND_EXCEPTION); } return personId; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine is used to determine whether a userid/person id is valid and whether the userid is still active. * @param personId contains the person identifier to do the query for. * @param userid contains the userid to do the query for. * @return will return true if valid, otherwise it will return false. *//*from ww w . j a v a 2 s . c om*/ public boolean isValidUserid(final Long personId, final String userid) { boolean found = false; final String sqlQuery = "SELECT person_id FROM {h-schema}userid WHERE userid = :userid AND person_id = :person_id AND end_date IS NULL"; final SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("person_id", personId); query.setParameter("userid", userid); query.addScalar("person_id", StandardBasicTypes.LONG); found = (query.list().size() == 0) ? false : true; return found; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine is used to determine if a person with a person identifier exists in the CPR or not. * @param personId contains the person identifier to do a search for. * @return returns the person identifier found. * @throws CprException exception indicates a cpr specific java exception. *//*w ww . j av a 2 s. c om*/ public long getPersonIdUsingPersonId(final long personId) throws CprException { Long personIdOut = NOT_FOUND_VALUE; final String sqlQuery = "SELECT person_id FROM {h-schema}person WHERE person_id = :personid"; final SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("personid", personId); query.addScalar("person_id", StandardBasicTypes.LONG); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { personIdOut = (Long) it.next(); } if (personIdOut.equals(NOT_FOUND_VALUE)) { throw new CprException(ReturnType.PERSON_NOT_FOUND_EXCEPTION); } return personId; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine is used to obtain a person identifier using a SOR identifier. * @param identifierType contains the identifier type. * @param identifier contains the identifier value. * @return will return the person identifier or throw an exception. * @throws CprException will be thrown if there is a CPR specific problem. *//*from w w w .jav a2s . c o m*/ public long getPersonIdUsingPersonIdentifier(final IdentifierType identifierType, final String identifier) throws CprException { Long personId = NOT_FOUND_VALUE; final StringBuilder sb = new StringBuilder(BUFFER_SIZE); sb.append("SELECT person_id FROM {h-schema}person_identifier WHERE type_key = :type_key "); sb.append("AND identifier_value = :identifier_value "); sb.append("AND end_date IS NULL"); final SQLQuery query = session.createSQLQuery(sb.toString()); query.setParameter("type_key", identifierType.getTypeKey()); query.setParameter("identifier_value", identifier); query.addScalar("person_id", StandardBasicTypes.LONG); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { personId = (Long) it.next(); } if (personId.equals(NOT_FOUND_VALUE)) { throw new CprException(ReturnType.PERSON_NOT_FOUND_EXCEPTION); } return personId; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * This routine will called a stored function to determine if a person is active in the CPR or not. * @param personId person identifier from the Central Person Registry. * @return true if the person is active. * @throws CprException exception indicates a cpr specific java exception. *///from w w w . j ava2 s . c om public boolean isPersonActive(final long personId) throws CprException { long personIdOut = NOT_FOUND_VALUE; final String sqlQuery = "SELECT person_id FROM {h-schema}person WHERE person_id = :personid AND end_date IS NULL"; final SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("personid", personId); query.addScalar("person_id", StandardBasicTypes.LONG); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { personIdOut = (Long) it.next(); } if (personId != personIdOut) { throw new CprException(ReturnType.PERSON_NOT_ACTIVE_EXCEPTION); } return true; }
From source file:edu.psu.iam.cpr.core.database.Database.java
License:Apache License
/** * doesPsuIdExist accepts a single parameter the psuId and checks to see if it exists in the CPR. * @param psuId contains the psu id to check for existence. * @throws CprException exception indicates a cpr specific java exception. *///from w ww . ja v a 2 s . c om public void doesPsuIdExist(final String psuId) throws CprException { Long personId = NOT_FOUND_VALUE; final String sqlQuery = "SELECT person_id FROM {h-schema}psu_id WHERE psu_id = :psuid AND end_date IS NULL"; final SQLQuery query = session.createSQLQuery(sqlQuery); query.setParameter("psuid", psuId); query.addScalar("person_id", StandardBasicTypes.LONG); final Iterator<?> it = query.list().iterator(); if (it.hasNext()) { personId = (Long) it.next(); } if (personId.equals(NOT_FOUND_VALUE)) { throw new CprException(ReturnType.PSUID_NOT_FOUND_EXCEPTION); } }