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.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

private static void bindMapSecondPass(GrailsDomainClassProperty property, Mappings mappings,
        Map<?, ?> persistentClasses, org.hibernate.mapping.Map map, String sessionFactoryBeanName) {
    bindCollectionSecondPass(property, mappings, persistentClasses, map, sessionFactoryBeanName);

    SimpleValue value = new SimpleValue(mappings, map.getCollectionTable());

    bindSimpleValue(getIndexColumnType(property, STRING_TYPE), value, true,
            getIndexColumnName(property, sessionFactoryBeanName), mappings);
    PropertyConfig pc = getPropertyConfig(property);
    if (pc != null && pc.getIndexColumn() != null) {
        bindColumnConfigToColumn(getColumnForSimpleValue(value), getSingleColumnConfig(pc.getIndexColumn()));
    }/*from w  ww .  jav  a  2 s .  com*/

    if (!value.isTypeSpecified()) {
        throw new MappingException("map index element must specify a type: " + map.getRole());
    }
    map.setIndex(value);

    if (!property.isOneToMany() && !property.isManyToMany()) {
        SimpleValue elt = new SimpleValue(mappings, map.getCollectionTable());
        map.setElement(elt);

        String typeName = getTypeName(property, getPropertyConfig(property),
                getMapping(property.getDomainClass()));
        if (typeName == null) {
            if (property.isBasicCollectionType()) {
                typeName = property.getReferencedPropertyType().getName();
            } else {
                typeName = StandardBasicTypes.STRING.getName();
            }
        }
        bindSimpleValue(typeName, elt, false, getMapElementName(property, sessionFactoryBeanName), mappings);

        elt.setTypeName(typeName);

        map.setInverse(false);
    } else {
        map.setInverse(false);
    }
}

From source file:org.csc.phynixx.sqlquery.config.h2.ExtendedH2Dialect.java

License:Apache License

public ExtendedH2Dialect() {
    super();/*from  w ww .j av  a2s .c o m*/
    this.registerFunction("person_name", new StandardSQLFunction("person_name", StandardBasicTypes.STRING));
    this.registerFunction("PERSON_NAME", new StandardSQLFunction("PERSON_NAME", StandardBasicTypes.STRING));
}

From source file:org.dspace.content.dao.impl.ItemDAOImpl.java

License:BSD License

@Override
public Iterator<Item> findByMetadataQuery(Context context, List<List<MetadataField>> listFieldList,
        List<String> query_op, List<String> query_val, List<UUID> collectionUuids, String regexClause,
        int offset, int limit) throws SQLException {
    Criteria criteria = createCriteria(context, Item.class, "item");
    criteria.setFirstResult(offset);/*w  w w.ja v a 2 s. co  m*/
    criteria.setMaxResults(limit);

    if (!collectionUuids.isEmpty()) {
        DetachedCriteria dcollCriteria = DetachedCriteria.forClass(Collection.class, "coll");
        dcollCriteria.setProjection(Projections.property("coll.id"));
        dcollCriteria.add(Restrictions.eqProperty("coll.id", "item.owningCollection"));
        dcollCriteria.add(Restrictions.in("coll.id", collectionUuids));
        criteria.add(Subqueries.exists(dcollCriteria));
    }

    int index = Math.min(listFieldList.size(), Math.min(query_op.size(), query_val.size()));
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < index; i++) {
        OP op = OP.valueOf(query_op.get(i));
        if (op == null) {
            log.warn("Skipping Invalid Operator: " + query_op.get(i));
            continue;
        }

        if (op == OP.matches || op == OP.doesnt_match) {
            if (regexClause.isEmpty()) {
                log.warn("Skipping Unsupported Regex Operator: " + query_op.get(i));
                continue;
            }
        }

        DetachedCriteria subcriteria = DetachedCriteria.forClass(MetadataValue.class, "mv");
        subcriteria.add(Property.forName("mv.dSpaceObject").eqProperty("item.id"));
        subcriteria.setProjection(Projections.property("mv.dSpaceObject"));

        if (!listFieldList.get(i).isEmpty()) {
            subcriteria.add(Restrictions.in("metadataField", listFieldList.get(i)));
        }

        sb.append(op.name() + " ");
        if (op == OP.equals || op == OP.not_equals) {
            subcriteria.add(Property.forName("mv.value").eq(query_val.get(i)));
            sb.append(query_val.get(i));
        } else if (op == OP.like || op == OP.not_like) {
            subcriteria.add(Property.forName("mv.value").like(query_val.get(i)));
            sb.append(query_val.get(i));
        } else if (op == OP.contains || op == OP.doesnt_contain) {
            subcriteria.add(Property.forName("mv.value").like("%" + query_val.get(i) + "%"));
            sb.append(query_val.get(i));
        } else if (op == OP.matches || op == OP.doesnt_match) {
            subcriteria
                    .add(Restrictions.sqlRestriction(regexClause, query_val.get(i), StandardBasicTypes.STRING));
            sb.append(query_val.get(i));
        }

        if (op == OP.exists || op == OP.equals || op == OP.like || op == OP.contains || op == OP.matches) {
            criteria.add(Subqueries.exists(subcriteria));
        } else {
            criteria.add(Subqueries.notExists(subcriteria));
        }
    }
    log.debug(String.format("Running custom query with %d filters", index));

    return list(criteria).iterator();
}

From source file:org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore.java

License:Open Source License

public CDOID createObjectID(String val) {
    final int index = val.lastIndexOf(CDOClassifierRef.URI_SEPARATOR);
    if (index == -1) {
        throw new IllegalArgumentException("Id string " + val + " is not a valid id");
    }//ww w .  j  a v  a  2  s . c om

    final String uriPart = val.substring(0, index);
    final String idPart = val.substring(index + 1);
    final CDOClassifierRef classifierRef = new CDOClassifierRef(uriPart);
    final String entityName = getEntityName(classifierRef);
    final EClass eClass = getEClass(entityName);
    final EAnnotation typeEAnnotation = eClass.getEAnnotation(ID_TYPE_EANNOTATION_SOURCE);
    if (typeEAnnotation == null) {
        throw new IllegalStateException("EClass " + eClass + " does not have a type annotation");
    }

    final String idTypeStr = typeEAnnotation.getDetails().get(ID_TYPE_EANNOTATION_KEY);
    if (StandardBasicTypes.STRING.getName().equals(idTypeStr)) {
        return HibernateUtil.getInstance().createCDOID(classifierRef, idPart);
    } else if (StandardBasicTypes.LONG.getName().equals(idTypeStr)) {
        return HibernateUtil.getInstance().createCDOID(classifierRef, new Long(idPart));
    } else {
        throw new IllegalArgumentException("ID type " + idTypeStr + " not supported ");
    }
}

From source file:org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOCustomTypeUserType.java

License:Open Source License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sessionImplementor, Object owner)
        throws SQLException {
    try {//  ww w .  java2  s.c o m
        final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[0], sessionImplementor);
        if (rs.wasNull()) {
            return null;
        }

        return value;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDAnyUserType.java

License:Open Source License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sessionImplementor, Object owner)
        throws SQLException {
    final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[1], sessionImplementor);
    if (rs.wasNull()) {
        return null;
    }//from  ww  w.  j  ava 2 s  . c  o m
    final String entityName = StandardBasicTypes.STRING.nullSafeGet(rs, names[0], sessionImplementor);
    return deserializeId(entityName, value);
}

From source file:org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType.java

License:Open Source License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sessionImplementor, Object owner)
        throws SQLException {
    final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[0], sessionImplementor);
    if (rs.wasNull()) {
        return null;
    }/*from w  ww .ja  v a2s.  c  o m*/

    return HibernateUtil.getInstance().convertStringToCDOID(value);
}

From source file:org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOLobUserType.java

License:Open Source License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sessionImplementor, Object owner)
        throws SQLException {
    try {//from ww w.java  2s  .c om
        final String value = StandardBasicTypes.STRING.nullSafeGet(rs, names[0], sessionImplementor);
        if (rs.wasNull()) {
            return null;
        }

        return convertStringToLob(value);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.AnyEObjectType.java

License:Open Source License

public Type[] getSubtypes() {
    return new Type[] { StandardBasicTypes.STRING, StandardBasicTypes.STRING, StandardBasicTypes.STRING };
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.eav.EAVGenericIDUserType.java

License:Open Source License

public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException {
    final String value = (String) StandardBasicTypes.STRING.nullSafeGet(rs, names[0]);
    if (rs.wasNull()) {
        return null;
    }/* w w  w  .  j  a v a  2 s  .com*/

    final int end1 = value.indexOf(SEPARATOR);
    final int start2 = end1 + SEPARATOR.length();

    final String idStr = value.substring(0, end1);
    final String idClassName = value.substring(start2);
    final Serializable id = getId(idStr, idClassName);
    return id;
}