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:org.openwms.persistence.ext.hibernate.UnitUserType.java

License:Open Source License

/**
 * {@inheritDoc}/* w  ww. ja v a  2 s  .  c o m*/
 * 
 * We've to store the concrete classname as well.
 * 
 * @throws SQLException
 *             in case of database errors
 */
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws SQLException {
    if (value == null) {
        st.setNull(index, StandardBasicTypes.STRING.sqlType());
        st.setNull(index + 1, StandardBasicTypes.STRING.sqlType());
    } else {
        if (value instanceof Piece) {
            Piece piece = (Piece) value;
            st.setString(index, piece.getUnitType().toString() + "@" + Piece.class.getCanonicalName());
            st.setString(index + 1, piece.getMagnitude().toPlainString());
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Binding '" + piece.getUnitType().toString() + "@" + Piece.class.getCanonicalName()
                        + "' to parameter: " + index);
                LOGGER.trace(
                        "Binding '" + piece.getMagnitude().toPlainString() + "' to parameter: " + (index + 1));
            }
        } else if (value instanceof Weight) {
            Weight weight = (Weight) value;
            st.setString(index, weight.getUnitType().toString() + "@" + Weight.class.getCanonicalName());
            st.setString(index + 1, weight.getMagnitude().toPlainString());
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Binding '" + weight.getUnitType().toString() + "@"
                        + Weight.class.getCanonicalName() + "' to parameter: " + index);
                LOGGER.trace(
                        "Binding '" + weight.getMagnitude().toPlainString() + "' to parameter: " + index + 1);
            }
        } else {
            throw new TypeMismatchException("Incompatible type: " + value.getClass().getCanonicalName());
        }
    }
}

From source file:org.projectbuendia.openmrs.api.db.hibernate.HibernateProjectBuendiaDAO.java

License:Apache License

private <T extends SyncParameters> List<T> fetchResults(Class<T> clazz, @Nullable SyncToken syncToken,
        @Nullable Criterion restriction, boolean includeVoided, int maxResults) {
    Session session = sessionFactory.getCurrentSession();

    Criteria criteria = session.createCriteria(clazz);

    if (syncToken != null) {
        // (a, b) > (x, y) is equivalent to (a > x) OR ((a = x) AND (b > y)). See
        // http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_greater-than
        criteria.add(sqlRestriction(//from  www  .  j a  v  a  2 s  .  co m
                // {alias} is substituted for the table alias that hibernate uses for the type.
                "({alias}.date_updated, {alias}.uuid) > (?, ?)",
                new Object[] { syncToken.greaterThanOrEqualToTimestamp,
                        // If syncToken.greaterThanUuid is null, we use the empty string, which
                        // is 'smaller' than every other string in terms of sort order.
                        syncToken.greaterThanUuid == null ? "" : syncToken.greaterThanUuid },
                new Type[] { StandardBasicTypes.TIMESTAMP, StandardBasicTypes.STRING }));
    }

    Criteria subCriteria = criteria.createCriteria("item");

    if (restriction != null) {
        subCriteria.add(restriction);
    }

    if (!includeVoided) {
        subCriteria.add(eq("voided", false));
    }

    criteria.addOrder(asc("dateUpdated")).addOrder(asc("uuid"));

    if (maxResults > 0) {
        criteria.setMaxResults(maxResults);
    }

    //noinspection unchecked
    return criteria.list();
}

From source file:org.riotfamily.common.hibernate.AnyIdAnyType.java

License:Apache License

private String getString(ResultSet rs, String name, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {

    return (String) StandardBasicTypes.STRING.nullSafeGet(rs, name, session, owner);
}

From source file:org.riotfamily.common.hibernate.AnyIdAnyType.java

License:Apache License

public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable,
        SessionImplementor session) throws HibernateException, SQLException {

    Serializable id;/*from  w w  w .  j a  v a2 s  . c o  m*/
    String entityName;
    if (value == null) {
        id = null;
        entityName = null;
    } else {
        entityName = session.bestGuessEntityName(value);
        id = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, value, session);
    }

    if (settable == null || settable[0]) {
        StandardBasicTypes.STRING.nullSafeSet(st, entityName, index, session);
    }
    String s = idToString(entityName, id, session);
    if (settable == null) {
        StandardBasicTypes.STRING.nullSafeSet(st, s, index + 1, session);
    } else {
        boolean[] idsettable = new boolean[settable.length - 1];
        System.arraycopy(settable, 1, idsettable, 0, idsettable.length);
        StandardBasicTypes.STRING.nullSafeSet(st, s, index + 1, idsettable, session);
    }
}

From source file:org.riotfamily.common.hibernate.FailSafeAnyType.java

License:Apache License

public FailSafeAnyType() {
    super(StandardBasicTypes.STRING, StandardBasicTypes.LONG);
}

From source file:org.sakaiproject.messagebundle.impl.MessageBundleServiceImpl.java

License:Educational Community License

public int getSearchCount(String searchQuery, String module, String baseName, String locale) {
    List<String> values = new ArrayList<String>();
    List<BasicType> types = new ArrayList<BasicType>();
    StringBuffer queryString = new StringBuffer("");

    try {//from   w  w w.  ja v  a  2 s. c om
        if (StringUtils.isNotEmpty(searchQuery)) {
            queryString.append("(defaultValue like ? OR value like ? OR propertyName = ?)");
            values.add("%" + searchQuery + "%");
            values.add("%" + searchQuery + "%");
            values.add(searchQuery);
            types.add(StandardBasicTypes.STRING);
            types.add(StandardBasicTypes.STRING);
            types.add(StandardBasicTypes.STRING);
        }
        if (StringUtils.isNotEmpty(module)) {
            if (queryString.length() > 0) {
                queryString.append(" AND ");
            }
            queryString.append("moduleName = ? ");
            values.add(module);
            types.add(StandardBasicTypes.STRING);

        }
        if (StringUtils.isNotEmpty(baseName)) {
            if (queryString.length() > 0) {
                queryString.append(" AND ");
            }
            queryString.append("baseName = ?");
            values.add(baseName);
            types.add(StandardBasicTypes.STRING);

        }
        if (StringUtils.isNotEmpty(locale)) {
            if (queryString.length() > 0) {
                queryString.append(" AND ");
            }
            queryString.append("locale = ?");
            values.add(locale);
            types.add(StandardBasicTypes.STRING);

        }
        if (queryString.length() > 0) {
            queryString.insert(0, "select count(*) from MessageBundleProperty where ");
        } else {
            queryString.insert(0, "select count(*) from MessageBundleProperty");
        }
        Integer count = null;
        try {
            Query query = getSessionFactory().getCurrentSession().createQuery(queryString.toString());
            query.setParameters(values.toArray(), (Type[]) types.toArray(new Type[types.size()]));
            count = (Integer) query.uniqueResult();
        } catch (HibernateException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        return count.intValue();
    } catch (Exception e) {
        logger.error("problem searching the message bundle data", e);
    }
    return 0;
}

From source file:owldb.util.IRIStringType.java

License:Open Source License

/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override// w  w  w .  j  a  v a2s  .co m
public Object nullSafeGet(final java.sql.ResultSet rs, final String[] names, final Object owner)
        throws SQLException {
    final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[0]);
    return value == null ? null : IRI.create(value);
}

From source file:owldb.util.IRIStringType.java

License:Open Source License

/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override/* ww  w  .java2 s  .  c o m*/
public void nullSafeSet(final PreparedStatement pstmt, final Object value, final int index)
        throws SQLException {
    final String text = value == null ? "" : value.toString();
    StandardBasicTypes.STRING.nullSafeSet(pstmt, text, index);
}

From source file:owldb.util.NodeIDStringType.java

License:Open Source License

/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override//from  www .j a  v a2  s  .c o m
public Object nullSafeGet(final java.sql.ResultSet rs, final String[] names, final Object owner)
        throws SQLException {
    final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[0]);
    return value == null ? null : NodeID.getNodeID(value);
}

From source file:owldb.util.NodeIDStringType.java

License:Open Source License

/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override//  w  ww .j a v  a 2 s  .  co  m
public void nullSafeSet(final PreparedStatement pstmt, final Object value, final int index)
        throws SQLException {
    final String text = value == null ? ""
            : value instanceof NodeID ? ((NodeID) value).getID() : value.toString();
    StandardBasicTypes.STRING.nullSafeSet(pstmt, text, index);
}