Example usage for org.hibernate.type StandardBasicTypes STRING

List of usage examples for org.hibernate.type StandardBasicTypes STRING

Introduction

In this page you can find the example usage for org.hibernate.type StandardBasicTypes STRING.

Prototype

StringType STRING

To view the source code for org.hibernate.type StandardBasicTypes STRING.

Click Source Link

Document

The standard Hibernate type for mapping String to JDBC java.sql.Types#VARCHAR VARCHAR .

Usage

From source file:debop4k.data.orm.hibernate.usertypes.jodatime.TimestampAndTimeZoneUserType.java

License:Apache License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    DateTime time = (DateTime) value;// ww w.j ava2 s.c o m
    if (time == null) {
        StandardBasicTypes.TIMESTAMP.nullSafeSet(st, null, index, session);
        StandardBasicTypes.STRING.nullSafeSet(st, null, index + 1, session);
    } else {
        StandardBasicTypes.TIMESTAMP.nullSafeSet(st, new Timestamp(time.getMillis()), index, session);
        StandardBasicTypes.STRING.nullSafeSet(st, time.getZone().getID(), index + 1, session);
    }
}

From source file:debop4k.data.orm.hibernate.usertypes.KoreanChosungUserType.java

License:Apache License

@Override
public int[] sqlTypes() {
    return new int[] { StandardBasicTypes.STRING.sqlType(), StandardBasicTypes.STRING.sqlType() };
}

From source file:debop4k.data.orm.hibernate.usertypes.KoreanChosungUserType.java

License:Apache License

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    return StandardBasicTypes.STRING.nullSafeGet(rs, names[0], session, owner);
}

From source file:debop4k.data.orm.hibernate.usertypes.KoreanChosungUserType.java

License:Apache License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    if (value == null) {
        StandardBasicTypes.STRING.nullSafeSet(st, null, index, session);
        StandardBasicTypes.STRING.nullSafeSet(st, null, index + 1, session);
    } else {//from   w  ww.  java  2 s.c o  m
        String text = (String) value;
        String chosung = CharArrayList.newListWith(KoreanString.getChosung(text)).makeString("");
        StandardBasicTypes.STRING.nullSafeSet(st, text, index, session);
        StandardBasicTypes.STRING.nullSafeSet(st, chosung, index + 1, session);
    }
}

From source file:edu.psu.iam.cpr.core.database.Database.java

License:Apache License

/**
 * This method is used to find a registration authority based on a server principal.
 * @param principalId contains the ra server principal.
 * @param serviceName contains the name of the calling service.
 * @return will return a list of longs contains the registration authority key and the ra server principal key.
 * @throws CprException will be thrown if there are any CPR Related problems.
 *///from ww w  .jav a2s.c o m
private List<Long> findRegistrationAuthority(final String principalId, final String serviceName)
        throws CprException {

    Long localRegistrationAuthoritykey = NOT_FOUND_VALUE;
    Long raServerPrincipalKey = NOT_FOUND_VALUE;

    String suspendFlag = "Y";

    // Build the query.
    final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
    sb.append("SELECT ra.registration_authority_key, ra.suspend_flag, rasrvrprinc.ra_server_principal_key ");
    sb.append("FROM {h-schema}registration_authority ra JOIN {h-schema}ra_server_principals rasrvrprinc ");
    sb.append("ON ra.registration_authority_key = rasrvrprinc.registration_authority_key ");
    sb.append("WHERE rasrvrprinc.ra_server_principal = :ra_server_principal_in ");
    sb.append("AND ra.end_date IS NULL ");
    sb.append("AND rasrvrprinc.end_date IS NULL");

    // Create the query, bind the input parameters and determine the output parameters.
    SQLQuery query = session.createSQLQuery(sb.toString());
    query.setParameter("ra_server_principal_in", principalId);
    query.addScalar("registration_authority_key", StandardBasicTypes.LONG);
    query.addScalar("suspend_flag", StandardBasicTypes.STRING);
    query.addScalar("ra_server_principal_key", StandardBasicTypes.LONG);

    // See if a record is found, if so get its data.
    Iterator<?> it = query.list().iterator();
    if (it.hasNext()) {
        Object[] res = (Object[]) it.next();
        localRegistrationAuthoritykey = (Long) res[RA_KEY_INDEX];
        suspendFlag = (String) res[RA_SUSPEND_FLAG];
        raServerPrincipalKey = (Long) res[RA_SERVER_PRINCIPAL_KEY_INDEX];
    }

    // Is the RA suspended?
    if (localRegistrationAuthoritykey.equals(NOT_FOUND_VALUE) || raServerPrincipalKey.equals(NOT_FOUND_VALUE)
            || Utility.isOptionYes(suspendFlag)) {
        throw new CprException(ReturnType.NOT_AUTHORIZED_EXCEPTION, serviceName);
    }

    List<Long> methodReturn = new ArrayList<Long>();
    methodReturn.add(localRegistrationAuthoritykey);
    methodReturn.add(raServerPrincipalKey);
    return methodReturn;

}

From source file:edu.psu.iam.cpr.core.database.Database.java

License:Apache License

/**
 * This routine will determine if a particular server principal is authorized to call a service.
 * @param principalId contains the requestor's principal identifier.
 * @param requestor contains the userid of the person requesting access.
 * @param serviceName contains the name of the service.
 * @param clientIpAddress contains the client ip address.
 * @throws CprException //from  www  .jav a 2 s  .c  o  m
 */
public void requestorAuthorized(final String principalId, final String requestor, final String serviceName,
        final String clientIpAddress) throws CprException {

    String grpMbrsSuspendFlag = "Y";
    String cprAccGrpsSuspendFlag = "Y";
    String webSrvAccSuspendFlag = "Y";
    Long localCprAccessGroupsKey = NOT_FOUND_VALUE;

    // Get the RA information.
    List<Long> methodReturn = findRegistrationAuthority(principalId, serviceName);
    Long localRegistrationAuthorityKey = methodReturn.get(0);
    Long raServerPrincipalKey = methodReturn.get(1);

    // Determine if the client ip address is valid for the particular RA.
    verifyClientIpAddress(raServerPrincipalKey, serviceName, clientIpAddress);

    // Determine the user's status and group for the particular RA.

    // Build the query.
    final StringBuilder sb = new StringBuilder();
    sb.append(
            "SELECT cpr_access_groups_key, grpmbrs_suspend_flag, cpraccgprs_suspend_flag, websrvacc_suspend_flag ");
    sb.append("FROM {h-schema}v_ra_group_web_service ");
    sb.append("WHERE registration_authority_key = :l_ra_key ");
    sb.append("AND ra_server_principal_key = :ra_sp_key ");
    sb.append("AND web_service = :web_service_in ");
    sb.append("AND userid = :requested_by_in");

    // Create the query, bind the parameters and determine the returns.
    SQLQuery query = session.createSQLQuery(sb.toString());
    query.setParameter("l_ra_key", localRegistrationAuthorityKey);
    query.setParameter("ra_sp_key", raServerPrincipalKey);
    query.setParameter("web_service_in", serviceName);
    query.setParameter("requested_by_in", requestor);
    query.addScalar("cpr_access_groups_key", StandardBasicTypes.LONG);
    query.addScalar("grpmbrs_suspend_flag", StandardBasicTypes.STRING);
    query.addScalar("cpraccgprs_suspend_flag", StandardBasicTypes.STRING);
    query.addScalar("websrvacc_suspend_flag", StandardBasicTypes.STRING);

    // Perform the query.
    for (Iterator<?> it = query.list().iterator(); it.hasNext();) {
        Object[] res = (Object[]) it.next();
        localCprAccessGroupsKey = (Long) res[CPR_ACCESS_GROUPS_KEY];
        grpMbrsSuspendFlag = (String) res[GRP_MBRS_SUSPEND_FLAG];
        cprAccGrpsSuspendFlag = (String) res[CPR_GRPS_SUSPEND_FLAG];
        webSrvAccSuspendFlag = (String) res[WEB_SRV_SUSPEND_FLAG];
    }

    // If any of the suspend flags is set to Yes, we need to throw an exception.
    if (localCprAccessGroupsKey.equals(NOT_FOUND_VALUE) || Utility.isOptionYes(grpMbrsSuspendFlag)
            || Utility.isOptionYes(cprAccGrpsSuspendFlag) || Utility.isOptionYes(webSrvAccSuspendFlag)) {
        throw new CprException(ReturnType.NOT_AUTHORIZED_EXCEPTION, serviceName);
    }

    setCprAccessGroupsKey(localCprAccessGroupsKey);
    setRegistrationAuthorityKey(localRegistrationAuthorityKey);

}

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 dataResource contains the data source that is being checked.
 * @param action contains the action that is being checked.
 * @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.
 *///from   www .  j a va  2 s  .  c om
public boolean isDataActionAuthorized(final String dataResource, final String action, final String requestedBy)
        throws CprException {

    // Verify that the operation being checked is against a valid data key.
    final Long dataTypeKey = AccessType.valueOf(dataResource.toUpperCase().trim()).index();
    final Long accessOperationKey = AccessType.valueOf(action.toUpperCase().trim()).index();
    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);

        for (final Iterator<?> it = query.list().iterator(); it.hasNext();) {
            it.next();
            dataKeyValid = true;
        }
    } finally {
        if (!dataKeyValid) {
            throw new CprException(ReturnType.DATA_CHANGE_EXCEPTION, dataResource);
        }
    }

    // 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.cpr_access_groups_key = :cpr_access_groups_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("cpr_access_groups_key_in", getCprAccessGroupsKey());
    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);

    for (final Iterator<?> it = query.list().iterator(); 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 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.
 *//* w  w w .  jav  a 2 s  . co 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.helpers.PsuIdHelper.java

License:Apache License

/**
 * This routine will generate a new PSU ID for a person and assign it.
 * @param session contains a database session.
 * @param bean contains the PSU ID database bean where the resultant PSU ID will be placed.
 *//* w  ww .j ava  2s.  c  o m*/
public void generatePSUIdNumber(final Session session, final PsuId bean) {

    boolean done = false;

    while (!done) {

        // Obtain a new PSU ID.
        String psuId = Integer.toString(getRandomPSUIdNumber());

        // Determine if the new PSU ID is not already used, in the exception list or tagged for assignment. 
        StringBuilder sb = new StringBuilder(BUFFER_SIZE);
        sb.append("SELECT psu_id FROM {h-schema}psu_id WHERE psu_id = :psu_id_1");
        sb.append(" UNION ");
        sb.append("SELECT psu_id FROM {h-schema}psu_id_exceptions WHERE psu_id = :psu_id_2");
        sb.append(" UNION ");
        sb.append(
                "SELECT generated_identity AS psu_id from {h-schema}generated_identity WHERE generated_identity = :psu_id_3");
        final SQLQuery query = session.createSQLQuery(sb.toString());
        query.addScalar("psu_id", StandardBasicTypes.STRING);
        query.setParameter("psu_id_1", psuId);
        query.setParameter("psu_id_2", psuId);
        query.setParameter("psu_id_3", psuId);

        // Not found, so we can assign it to the user.
        if (query.list().size() == 0) {

            bean.setPsuId(psuId);

            done = true;
        }
    }
}

From source file:edu.psu.iam.cpr.core.database.tables.AddressesTable.java

License:Apache License

/**
 * This routine will obtain a list of addresses for a person id
 * @param db contains the Database object
 * @param personId   contains the personID
 * //from www.ja  v a  2s . c  o m
 * @return list of addresses
 */
public AddressReturn[] getAddress(final Database db, final long personId) {

    final Session session = db.getSession();
    final List<AddressReturn> results = new ArrayList<AddressReturn>();

    final StringBuilder sb = new StringBuilder(BUFFER_SIZE);

    sb.append(
            "SELECT addresses.address_key, addresses.data_type_key, addresses.document_type_key, addresses.group_id,");
    sb.append("addresses.primary_flag,addresses.address1, addresses.address2, addresses.address3, ");
    sb.append("addresses.city, addresses.state, addresses.postal_code, addresses.province, verified_flag, ");
    sb.append("addresses.start_date, ");
    sb.append("addresses.end_date, ");
    sb.append("addresses.last_update_by, ");
    sb.append("addresses.last_update_on, ");
    sb.append("addresses.created_by, ");
    sb.append("addresses.created_on, ");
    sb.append("campus_cs.campus_code, campus_cs.campus, ");
    sb.append("country.country_code_three, country.country ");
    sb.append("FROM {h-schema}addresses ");
    sb.append("LEFT JOIN {h-schema}campus_cs ON addresses.campus_code_key = campus_cs.campus_code_key ");
    sb.append("LEFT JOIN {h-schema}country ON addresses.country_key = country.country_key ");
    sb.append("WHERE addresses.person_id = :person_id_in ");

    if (getAddressType() != null) {
        sb.append("AND addresses.data_type_key = :data_type_key_in ");
    }

    // If we are not returning all records, we need to just return the active ones.
    if (!isReturnHistoryFlag()) {
        sb.append("AND addresses.end_date IS NULL ");
    }

    if (getAddressKey() > 0L) {
        sb.append("AND addresses.address_key = :address_key_in ");
    }

    sb.append("ORDER BY addresses.data_type_key ASC, addresses.start_date ASC ");

    final SQLQuery query = session.createSQLQuery(sb.toString());
    query.setParameter("person_id_in", personId);

    if (getAddressType() != null) {
        query.setParameter("data_type_key_in", getAddressType().index());
    }

    if (getAddressKey() > 0L) {
        query.setParameter("address_key_in", getAddressKey());
    }

    query.addScalar(ADDRESS_KEY_STRING, StandardBasicTypes.LONG);
    query.addScalar(DATA_TYPE_KEY_STRING, StandardBasicTypes.LONG);
    query.addScalar(DOCUMENT_TYPE_KEY_STRING, StandardBasicTypes.LONG);
    query.addScalar(GROUP_ID_STRING, StandardBasicTypes.LONG);
    query.addScalar("primary_flag", StandardBasicTypes.STRING);
    query.addScalar("address1", StandardBasicTypes.STRING);
    query.addScalar("address2", StandardBasicTypes.STRING);
    query.addScalar("address3", StandardBasicTypes.STRING);
    query.addScalar("city", StandardBasicTypes.STRING);
    query.addScalar("state", StandardBasicTypes.STRING);
    query.addScalar("postal_code", StandardBasicTypes.STRING);
    query.addScalar("province", StandardBasicTypes.STRING);
    query.addScalar("verified_flag", StandardBasicTypes.STRING);
    query.addScalar("start_date", StandardBasicTypes.TIMESTAMP);
    query.addScalar("end_date", StandardBasicTypes.TIMESTAMP);
    query.addScalar("last_update_by", StandardBasicTypes.STRING);
    query.addScalar("last_update_on", StandardBasicTypes.TIMESTAMP);
    query.addScalar("created_by", StandardBasicTypes.STRING);
    query.addScalar("created_on", StandardBasicTypes.TIMESTAMP);
    query.addScalar("campus_code", StandardBasicTypes.STRING);
    query.addScalar("campus", StandardBasicTypes.STRING);
    query.addScalar("country_code_three", StandardBasicTypes.STRING);
    query.addScalar("country", StandardBasicTypes.STRING);

    for (final Iterator<?> it = query.list().iterator(); it.hasNext();) {
        Object[] res = (Object[]) it.next();

        AddressReturn anAddress = new AddressReturn();
        anAddress.setAddressKey(((Long) res[ADDRESS_KEY]).toString());
        anAddress.setAddressType(AddressType.get((Long) res[ADDRESS_TYPE]).toString());
        if (res[DOCUMENT_TYPE] != null) {
            anAddress.setDocumentType(DocumentType.get((Long) res[DOCUMENT_TYPE]).toString());
        } else {
            anAddress.setDocumentType(null);
        }
        anAddress.setGroupId((Long) res[GROUP_ID]);
        anAddress.setPrimaryFlag((String) res[PRIMARY_FLAG]);
        anAddress.setAddress1((String) res[ADDRESS1]);
        anAddress.setAddress2((String) res[ADDRESS2]);
        anAddress.setAddress3((String) res[ADDRESS3]);
        anAddress.setCity((String) res[CITY]);
        String tempState = (String) res[STATE];
        anAddress.setPostalCode((String) res[POSTAL_CODE]);
        String tempProvince = (String) res[PROVINCE];
        anAddress.setVerifiedFlag((String) res[VERIFIED_FLAG]);
        anAddress.setStartDate(Utility.formatDateToISO8601((Date) res[START_DATE]));
        anAddress.setEndDate(Utility.formatDateToISO8601((Date) res[END_DATE]));
        anAddress.setLastUpdateBy((String) res[LAST_UPDATE_BY]);
        anAddress.setLastUpdateOn(Utility.formatDateToISO8601((Date) res[LAST_UPDATE_ON]));
        anAddress.setCreatedBy((String) res[CREATED_BY]);
        anAddress.setCreatedOn(Utility.formatDateToISO8601((Date) res[CREATED_ON]));
        anAddress.setCampusCode((String) res[CAMPUS_CODE]);
        anAddress.setCampusName((String) res[CAMPUS_NAME]);
        anAddress.setCountryCode((String) res[COUNTRY_CODE]);
        anAddress.setCountryName((String) res[COUNTRY_NAME]);

        if (tempState != null) {
            anAddress.setStateOrProvince(tempState);
        } else if (tempProvince != null) {
            anAddress.setStateOrProvince(tempProvince);
        } else {
            anAddress.setStateOrProvince(null);
        }

        results.add(anAddress);
    }

    return results.toArray(new AddressReturn[results.size()]);
}