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:edu.psu.iam.cpr.core.database.tables.UseridTable.java

License:Apache License

/**
 * This routine is used to determine if the passed in userid is valid.
 * @param db contains a reference to the database handle.
 * @param userid contains the userid to valid.
 * @return will return true if the userid is valid, otherwise it will return false.
 *///from  w  w w.j  a v a 2 s  . com
public boolean isUseridValid(final Database db, final String userid) {

    final Session session = db.getSession();
    // Verify that the userid does not contain spaces.
    if (userid.contains(" ")) {
        return false;
    }
    // Verify that the userid only contains letters, numbers, $ and underscore.
    if (!userid.matches("^[a-zA-Z0-9$_]+$")) {
        return false;
    }

    // Obtain the character portion of the userid.
    final String charPart = getCharacterPart(userid);

    // Verify that the userid does not exist in the bad prefixes table.
    String sqlQuery = "SELECT char_part FROM {h-schema}bad_prefixes WHERE char_part = :char_part_in";
    SQLQuery query = session.createSQLQuery(sqlQuery);
    query.setParameter("char_part_in", charPart);
    query.addScalar("char_part", StandardBasicTypes.STRING);
    if (query.list().size() > 0) {
        return false;
    }

    // Verify that the userid does not already exist.
    sqlQuery = "SELECT person_id FROM {h-schema}userid WHERE userid = :userid_in";
    query = session.createSQLQuery(sqlQuery);
    query.setParameter("userid_in", userid);
    query.addScalar("person_id", StandardBasicTypes.LONG);
    if (query.list().size() > 0) {
        return false;
    }

    return true;
}

From source file:edu.psu.iam.cpr.core.messaging.ServiceProvisionerQueue.java

License:Apache License

/**
 * This routine is used to obtain a list of service providers and their respective queues for a particular web service.
 * @param db contains a database connection.
 * @param webService contains the web server to do the query for.
 * @return will return an ArrayList of service provider information.
 *//*from   www .  j  a  v a2  s .  com*/
public static ArrayList<ServiceProvisionerQueue> getServiceProvisionerQueues(Database db, String webService) {

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

    final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
    sb.append("SELECT service_provisioner_key, service_provisioner, web_service_key, web_service, ");
    sb.append("service_provisioner_queue FROM v_sp_notification WHERE web_service=:web_service ");

    final SQLQuery query = session.createSQLQuery(sb.toString());
    query.setParameter("web_service", webService);
    query.addScalar("service_provisioner_key", StandardBasicTypes.LONG);
    query.addScalar("service_provisioner", StandardBasicTypes.STRING);
    query.addScalar("web_service_key", StandardBasicTypes.LONG);
    query.addScalar("web_service", StandardBasicTypes.STRING);
    query.addScalar("service_provisioner_queue", StandardBasicTypes.STRING);
    final Iterator<?> it = query.list().iterator();

    while (it.hasNext()) {
        Object res[] = (Object[]) it.next();
        results.add(new ServiceProvisionerQueue((Long) res[SP_KEY], (String) res[SP_NAME],
                (Long) res[WEB_SERVICE_KEY], (String) res[WEB_SERVICE], (String) res[SP_QUEUE]));
    }

    return results;
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.AbstractAreaDao.java

License:Open Source License

public List<BaseAreaEntity> closestArea(final List<AreaLocationTypesEntity> entities,
        final DatabaseDialect dialect, final Point point) {

    List resultList = new ArrayList();

    if (dialect != null && CollectionUtils.isNotEmpty(entities) && (point != null && !point.isEmpty())) {

        final StringBuilder sb = new StringBuilder();
        final Double longitude = point.getX();
        final Double latitude = point.getY();

        Iterator<AreaLocationTypesEntity> it = entities.iterator();
        sb.append(dialect.closestAreaToPointPrefix());
        int index = 0;
        while (it.hasNext()) {
            AreaLocationTypesEntity next = it.next();
            final String areaDbTable = next.getAreaDbTable();
            final String typeName = next.getTypeName();
            sb.append(dialect.closestAreaToPoint(index, typeName, areaDbTable, latitude, longitude, 10));
            index++;//  w w  w  .j  a v  a2 s  .  c o m
            it.remove(); // avoids a ConcurrentModificationException
            if (it.hasNext()) {
                sb.append(UNION_ALL);
            }
        }

        sb.append(dialect.closestAreaToPointSuffix());

        log.debug(QUERY, dialect.getClass().getSimpleName().toUpperCase(), sb.toString());

        javax.persistence.Query emNativeQuery = getEntityManager().createNativeQuery(sb.toString());

        emNativeQuery.unwrap(SQLQuery.class).addScalar(TYPE, StandardBasicTypes.STRING)
                .addScalar(GID, StandardBasicTypes.INTEGER).addScalar(CODE, StandardBasicTypes.STRING)
                .addScalar(NAME, StandardBasicTypes.STRING)
                .addScalar(CLOSEST, org.hibernate.spatial.GeometryType.INSTANCE);

        resultList = emNativeQuery.getResultList();
    }

    return resultList;

}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.AbstractAreaDao.java

License:Open Source License

public List<BaseAreaEntity> intersectingArea(final List<AreaLocationTypesEntity> entities,
        final DatabaseDialect dialect, final Point point) {

    List resultList = new ArrayList();
    int index = 1;

    if (dialect != null && CollectionUtils.isNotEmpty(entities) && (point != null && !point.isEmpty())) {

        final StringBuilder sb = new StringBuilder();
        final Double longitude = point.getX();
        final Double latitude = point.getY();

        Iterator<AreaLocationTypesEntity> it = entities.iterator();

        sb.append("select * from  (");

        while (it.hasNext()) {
            AreaLocationTypesEntity next = it.next();
            final String areaDbTable = next.getAreaDbTable();
            final String typeName = next.getTypeName();
            sb.append("(SELECT ").append(index).append(" as indexRS,").append("'").append(typeName)
                    .append("' as type, gid, code, name FROM spatial.").append(areaDbTable).append(" WHERE ")
                    .append(dialect.stIntersects(latitude, longitude)).append(" AND enabled = 'Y')");
            it.remove(); // avoids a ConcurrentModificationException
            index++;//from w w  w . j  a  v a2s  .c  o m
            if (it.hasNext()) {
                sb.append(UNION_ALL);
            }
        }

        sb.append(") a ORDER BY indexRS, gid ASC ");

        log.debug(QUERY, dialect.getClass().getSimpleName().toUpperCase(), sb.toString());

        javax.persistence.Query emNativeQuery = getEntityManager().createNativeQuery(sb.toString());

        emNativeQuery.unwrap(SQLQuery.class).addScalar(TYPE, StandardBasicTypes.STRING)
                .addScalar(GID, StandardBasicTypes.INTEGER).addScalar(CODE, StandardBasicTypes.STRING)
                .addScalar(NAME, StandardBasicTypes.STRING);

        resultList = emNativeQuery.getResultList();
    }

    return resultList;

}

From source file:fr.gael.dhus.olingo.v1.SQLVisitor.java

License:Open Source License

@Override
public Object visitMethod(MethodExpression method_expression, MethodOperator method, List<Object> parameters) {
    Criterion criterion;/*w w  w. j a  va2 s . co  m*/
    switch (method) {
    // String functions
    case CONCAT: {
        criterion = Restrictions.sqlRestriction("CONCAT(?,?)",
                new Object[] { parameters.get(0), parameters.get(1) },
                new Type[] { StandardBasicTypes.STRING, StandardBasicTypes.STRING });
        break;
    }
    case INDEXOF: {
        criterion = Restrictions.sqlRestriction("LOCATE(?,?)",
                new Object[] { parameters.get(0), parameters.get(1) },
                new Type[] { StandardBasicTypes.STRING, StandardBasicTypes.STRING });
        break;
    }
    case LENGTH: {
        criterion = Restrictions.sqlRestriction("LENGTH(?)", parameters.get(0), StandardBasicTypes.STRING);
        break;
    }
    case SUBSTRING: {
        criterion = Restrictions.sqlRestriction("SUBSTR(?,?)",
                new Object[] { parameters.get(0), parameters.get(1) },
                new Type[] { StandardBasicTypes.STRING, StandardBasicTypes.STRING });
        break;
    }
    case TOUPPER: {
        criterion = Restrictions.sqlRestriction("UPPER(?)", parameters.get(0), StandardBasicTypes.STRING);
        break;
    }
    case TOLOWER: {
        criterion = Restrictions.sqlRestriction("LOWER(?)", parameters.get(0), StandardBasicTypes.STRING);
        break;
    }
    case TRIM: {
        criterion = Restrictions.sqlRestriction("TRIM(?)", parameters.get(0), StandardBasicTypes.STRING);
        break;
    }
    case ENDSWITH:
    case STARTSWITH: {
        criterion = getCriterionFunction(method, parameters.get(0), parameters.get(1));
        break;
    }
    case SUBSTRINGOF: {
        criterion = getCriterionFunction(method, parameters.get(1), parameters.get(0));
        break;
    }

    // Date functions
    case DAY: {
        criterion = Restrictions.sqlRestriction("DAYOFMONTH(?)", parameters.get(0),
                StandardBasicTypes.TIMESTAMP);
        break;
    }
    case HOUR: {
        criterion = Restrictions.sqlRestriction("HOUR(?)", parameters.get(0), StandardBasicTypes.TIMESTAMP);
        break;
    }
    case MINUTE: {
        criterion = Restrictions.sqlRestriction("MINUTE(?)", parameters.get(0), StandardBasicTypes.TIMESTAMP);
        break;
    }
    case MONTH: {
        criterion = Restrictions.sqlRestriction("MONTH(?)", parameters.get(0), StandardBasicTypes.TIMESTAMP);
        break;
    }
    case SECOND: {
        criterion = Restrictions.sqlRestriction("SECOND(?)", parameters.get(0), StandardBasicTypes.TIMESTAMP);
        break;
    }
    case YEAR: {
        criterion = Restrictions.sqlRestriction("YEAR(?)", parameters.get(0), StandardBasicTypes.TIMESTAMP);
        break;
    }

    // Math functions
    case CEILING: {
        criterion = Restrictions.sqlRestriction("CEILING(?)", parameters.get(0), StandardBasicTypes.DOUBLE);
        break;
    }
    case FLOOR: {
        criterion = Restrictions.sqlRestriction("FLOOR (?)", parameters.get(0), StandardBasicTypes.DOUBLE);
        break;
    }
    case ROUND: {
        criterion = Restrictions.sqlRestriction("ROUND(?)", parameters.get(0), StandardBasicTypes.DOUBLE);
        break;
    }

    default:
        throw new UnsupportedOperationException("Unsupported method: " + method.toUriLiteral());
    }

    return criterion;
}

From source file:fr.gael.dhus.olingo.v1.SQLVisitor.java

License:Open Source License

private Criterion getCriterionFunction(MethodOperator method, Object... args) {
    Criterion criterion;//  w  ww .  ja  va  2 s .c o m
    if (args[0] instanceof Member) {
        String property = ((Member) args[0]).getName();
        switch (method) {
        case ENDSWITH: {
            String pattern = "%" + args[1];
            criterion = Restrictions.like(property, pattern);
            break;
        }
        case STARTSWITH: {
            String pattern = args[1] + "%";
            criterion = Restrictions.like(property, pattern);
            break;
        }
        case SUBSTRINGOF: {
            String pattern = "%" + args[1] + "%";
            criterion = Restrictions.like(property, pattern);
            break;
        }
        default: {
            throw new UnsupportedOperationException("Unsupported method: " + method.toUriLiteral());
        }
        }
    } else {
        Type[] types = { StandardBasicTypes.STRING, StandardBasicTypes.STRING };
        switch (method) {
        case ENDSWITH: {
            Object[] parameters = { args[0], ("%" + args[1]) };
            criterion = Restrictions.sqlRestriction("? LIKE ?", parameters, types);
            break;
        }
        case STARTSWITH: {
            Object[] parameters = { args[0], (args[1] + "%") };
            criterion = Restrictions.sqlRestriction("? LIKE ?", parameters, types);
            break;
        }
        case SUBSTRINGOF: {
            Object[] parameters = { args[0], ("%" + args[1] + "%") };
            criterion = Restrictions.sqlRestriction("? LIKE ?", parameters, types);
            break;
        }
        default: {
            throw new UnsupportedOperationException("Unsupported method: " + method.toUriLiteral());
        }
        }
    }
    return criterion;
}

From source file:gov.nih.nci.cabig.caaers.service.workflow.WorkflowServiceImpl.java

License:BSD License

/**
 * Find DCC reviewer from the workflow//  ww w  . j a v a 2s. co  m
 * @param wfId
 * @return User instance
 */
public User findCoordinatingCenterReviewer(Integer wfId) {
    String strQuery = "SELECT jbpm_pooledactor.actorid_ "
            + "FROM public.jbpm_pooledactor, public.jbpm_taskactorpool, public.jbpm_taskinstance "
            + "WHERE jbpm_pooledactor.id_ = jbpm_taskactorpool.pooledactor_ "
            + "AND jbpm_taskactorpool.taskinstance_= jbpm_taskinstance.id_ "
            + "AND jbpm_taskinstance.name_ IN ('Coordinating Center Review', 'Data Coordinator Review') "
            + "AND jbpm_taskinstance.procinst_= :wfId";
    final NativeSQLQuery query = new NativeSQLQuery(strQuery);
    query.setParameter("wfId", wfId.intValue());
    query.setScalar("actorid_", StandardBasicTypes.STRING);
    List userList = jbpmTemplate.getHibernateTemplate().executeFind(new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            org.hibernate.SQLQuery nativeQuery = session.createSQLQuery(query.getQueryString());
            Map<String, org.hibernate.type.Type> scalarMap = ((NativeSQLQuery) query).getScalarMap();
            for (String key : scalarMap.keySet()) {
                nativeQuery.addScalar(key, scalarMap.get(key));
            }
            Map<String, Object> queryParameterMap = query.getParameterMap();
            for (String key : queryParameterMap.keySet()) {
                Object value = queryParameterMap.get(key);
                nativeQuery.setParameter(key, value);
            }
            return nativeQuery.list();
        }
    });

    User reviewer = null;
    if (CollectionUtils.isNotEmpty(userList)) {
        reviewer = userRepository.getUserByLoginName((String) userList.get(0));
    }

    return reviewer;

}

From source file:gov.utah.dts.det.ccl.dao.impl.FacilityDaoImpl.java

License:Open Source License

@Override
public List<UserCaseloadCount> getUserCaseloadCounts() {
    Session session = (Session) em.getDelegate();
    SQLQuery query = session.createSQLQuery(CASELOAD_COUNT_QUERY);
    query.addScalar("id", StandardBasicTypes.LONG);
    query.addScalar("name", StandardBasicTypes.STRING);
    query.addScalar("roleType", StandardBasicTypes.STRING);
    query.addScalar("active", StandardBasicTypes.YES_NO);
    query.addScalar("count", StandardBasicTypes.LONG);
    query.setResultTransformer(Transformers.aliasToBean(UserCaseloadCount.class));
    return (List<UserCaseloadCount>) query.list();
}

From source file:jp.xet.baseunits.hibernate.AbstractStringBasedBaseunitsType.java

License:Apache License

/**
 * ??
 * 
 * @since 1.2
 */
public AbstractStringBasedBaseunitsType() {
    super(StandardBasicTypes.STRING);
}

From source file:ke.co.mspace.nonsmppmanager.service.SMSOutServiceImpl.java

@Override
public Map<String, Object> smsOutGroupBy(String user, String startDate, String endDate) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.getTransaction().begin();/*from  w ww. j  a v  a 2  s  . com*/
    Criteria criteria = session.createCriteria(SMSOut.class);

    /*
     * This is where the report is going to come from
     * projectionList.add(Projections.sqlGroupProjection("YEAR(time_submitted) as yearSubmitted, MONTHNAME(STR_TO_DATE(MONTH(time_submitted), '%m')) as monthSubmitted, time_submitted as timeSubmitted", "timeSubmitted", new String[] { "monthSubmitted", "timeSubmitted", "yearSubmitted" }, new Type[] { StandardBasicTypes.STRING }));
     */
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.sqlGroupProjection(
            "YEAR(time_submitted) as yearSubmitted, MONTHNAME(STR_TO_DATE(MONTH(time_submitted), '%m')) as timeSubmitted",
            "yearSubmitted, timeSubmitted", new String[] { "yearSubmitted", "timeSubmitted" },
            new Type[] { StandardBasicTypes.LONG, StandardBasicTypes.STRING }));

    projectionList.add(Projections.rowCount());

    criteria.setProjection(projectionList); //This is added
    criteria.add(Restrictions.eq("user", user));
    criteria.addOrder(Order.asc("timeSubmitted"));
    criteria.add(Restrictions.between("timeSubmitted", startDate, endDate));

    List<Object[]> results = criteria.list();

    for (Object[] aResult : results) {
        System.out.println("the Object: " + Arrays.deepToString(aResult));
        System.out.println("Year : " + aResult[0] + " Month : " + aResult[1] + " No. Sent : " + aResult[2]);
    }

    Map<String, Object> mapResult = new HashMap<>();
    mapResult.put("result", results);
    mapResult.put("noSMS", 20);

    session.getTransaction().commit();
    return mapResult;
}