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.goobi.production.flow.statistics.hibernate.StatQuestStorage.java

License:Open Source License

@Override
public List<DataTable> getDataTables(List<? extends BaseDTO> dataSource) {
    List<DataTable> allTables = new ArrayList<>();

    // gathering IDs from the filter passed by dataSource
    List<Integer> idList = getIds(dataSource);

    if (idList == null || idList.size() == 0) {
        return null;
    }/*w  w  w .  j  a  va 2  s . com*/

    // TODO: filter results according to date without sql query
    // adding time restrictions
    String natSQL = new SQLStorage(this.timeFilterFrom, this.timeFilterTo, this.timeGrouping, idList).getSQL();

    Session session = Helper.getHibernateSession();
    SQLQuery query = session.createSQLQuery(natSQL);

    // needs to be there otherwise an exception is thrown
    query.addScalar("storage", StandardBasicTypes.DOUBLE);
    query.addScalar("intervall", StandardBasicTypes.STRING);

    @SuppressWarnings("rawtypes")
    List list = query.list();

    DataTable dtbl = new DataTable(
            StatisticsMode.getByClassName(this.getClass()).getTitle() + " " + Helper.getTranslation("_inGB"));

    DataRow dataRow;

    // each data row comes out as an Array of Objects the only way to
    // extract the data is by knowing
    // in which order they come out
    for (Object obj : list) {
        dataRow = new DataRow(null);
        // TODO: Don't use arrays
        Object[] objArr = (Object[]) obj;
        try {
            // getting localized time group unit
            // setting row name with date/time extraction based on the group
            dataRow.setName(new Converter(objArr[1]).getString() + "");
            dataRow.addValue(Helper.getTranslation("storageDifference"), (new Converter(objArr[0]).getGB()));
        } catch (Exception e) {
            dataRow.addValue(e.getMessage(), 0.0);
        }

        // finally adding dataRow to DataTable and fetching next row
        dtbl.addDataRow(dataRow);
    }

    // a list of DataTables is expected as return Object, even if there is
    // only one Data Table as it is here in this implementation
    dtbl.setUnitLabel(Helper.getTranslation(this.timeGrouping.getSingularTitle()));
    allTables.add(dtbl);
    return allTables;
}

From source file:org.goobi.production.flow.statistics.hibernate.StatQuestThroughput.java

License:Open Source License

/**
 * Method generates a DataTable based on the input SQL. Methods success is
 * depending on a very specific data structure ... so don't use it if you don't
 * exactly understand it/* w  ww. ja v  a 2 s .  co m*/
 *
 * @param natSQL
 *            headerFromSQL -> to be used, if headers need to be read in first
 *            in order to get a certain sorting
 * @return DataTable
 */

// TODO Remove redundant code
private DataTable buildDataTableFromSQL(String natSQL, String headerFromSQL) {
    Session session = Helper.getHibernateSession();

    // creating header row from headerSQL (gets all columns in one row
    DataRow headerRow = null;
    if (headerFromSQL != null) {
        headerRow = new DataRow(null);
        SQLQuery headerQuery = session.createSQLQuery(headerFromSQL);

        // needs to be there otherwise an exception is thrown
        headerQuery.addScalar("stepCount", StandardBasicTypes.DOUBLE);
        headerQuery.addScalar("stepName", StandardBasicTypes.STRING);
        headerQuery.addScalar("stepOrder", StandardBasicTypes.DOUBLE);
        headerQuery.addScalar("intervall", StandardBasicTypes.STRING);

        @SuppressWarnings("rawtypes")
        List headerList = headerQuery.list();
        for (Object obj : headerList) {
            Object[] objArr = (Object[]) obj;
            try {
                headerRow.setName(new Converter(objArr[3]).getString() + "");
                headerRow.addValue(
                        new Converter(new Converter(objArr[2]).getInteger()).getString() + " ("
                                + new Converter(objArr[1]).getString() + ")",
                        (new Converter(objArr[0]).getDouble()));

            } catch (Exception e) {
                headerRow.addValue(e.getMessage(), 0.0);
            }
        }
    }

    SQLQuery query = session.createSQLQuery(natSQL);

    // needs to be there otherwise an exception is thrown
    query.addScalar("stepCount", StandardBasicTypes.DOUBLE);
    query.addScalar("stepName", StandardBasicTypes.STRING);
    query.addScalar("stepOrder", StandardBasicTypes.DOUBLE);
    query.addScalar("intervall", StandardBasicTypes.STRING);

    @SuppressWarnings("rawtypes")
    List list = query.list();

    DataTable dtbl = new DataTable("");

    // if headerRow is set then add it to the DataTable to set columns
    // needs to be removed later
    if (headerRow != null) {
        dtbl.addDataRow(headerRow);
    }

    DataRow dataRow = null;

    // each data row comes out as an Array of Objects
    // the only way to extract the data is by knowing
    // in which order they come out

    // checks if intervall has changed which then triggers the start for a
    // new row
    // intervall here is the timeGroup Expression (e.g. "2006/05" or
    // "2006-10-05")
    String observeIntervall = "";

    for (Object obj : list) {
        Object[] objArr = (Object[]) obj;
        try {
            // objArr[3]
            if (!observeIntervall.equals(new Converter(objArr[3]).getString())) {
                observeIntervall = new Converter(objArr[3]).getString();

                // row cannot be added before it is filled because the add
                // process triggers
                // a testing for header alignement -- this is where we add
                // it after iterating it first
                if (dataRow != null) {
                    dtbl.addDataRow(dataRow);
                }

                dataRow = new DataRow(null);
                // setting row name with localized time group and the
                // date/time extraction based on the group
                dataRow.setName(new Converter(objArr[3]).getString() + "");
            }
            dataRow.addValue(
                    new Converter(new Converter(objArr[2]).getInteger()).getString() + " ("
                            + new Converter(objArr[1]).getString() + ")",
                    (new Converter(objArr[0]).getDouble()));

        } catch (Exception e) {
            dataRow.addValue(e.getMessage(), 0.0);
        }
    }
    // to add the last row
    if (dataRow != null) {
        dtbl.addDataRow(dataRow);
    }

    // now removing headerRow
    if (headerRow != null) {
        dtbl.removeDataRow(headerRow);
    }

    return dtbl;
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

protected void bindMapSecondPass(ToMany 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(property, getColumnForSimpleValue(value),
                getSingleColumnConfig(pc.getIndexColumn()));
    }//from www.  j a va  2 s  . co m

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

    if (!(property instanceof org.grails.datastore.mapping.model.types.OneToMany)
            && !(property instanceof ManyToMany)) {

        SimpleValue elt = new SimpleValue(mappings, map.getCollectionTable());
        map.setElement(elt);

        String typeName = getTypeName(property, getPropertyConfig(property), getMapping(property.getOwner()));
        if (typeName == null) {

            if (property instanceof Basic) {
                Basic basic = (Basic) property;
                typeName = basic.getComponentType().getName();
            }
        }
        if (typeName == null || typeName.equals(Object.class.getName())) {
            typeName = StandardBasicTypes.STRING.getName();
        }
        bindSimpleValue(typeName, elt, false, getMapElementName(property, sessionFactoryBeanName), mappings);

        elt.setTypeName(typeName);
    }

    map.setInverse(false);
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

protected void bindMapSecondPass(ToMany property, InFlightMetadataCollector 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(property, getColumnForSimpleValue(value),
                getSingleColumnConfig(pc.getIndexColumn()));
    }//from   ww w  .jav a2 s. c o m

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

    if (!(property instanceof org.grails.datastore.mapping.model.types.OneToMany)
            && !(property instanceof ManyToMany)) {

        SimpleValue elt = new SimpleValue(mappings, map.getCollectionTable());
        map.setElement(elt);

        String typeName = getTypeName(property, getPropertyConfig(property), getMapping(property.getOwner()));
        if (typeName == null) {

            if (property instanceof Basic) {
                Basic basic = (Basic) property;
                typeName = basic.getComponentType().getName();
            }
        }
        if (typeName == null || typeName.equals(Object.class.getName())) {
            typeName = StandardBasicTypes.STRING.getName();
        }
        bindSimpleValue(typeName, elt, false, getMapElementName(property, sessionFactoryBeanName), mappings);

        elt.setTypeName(typeName);
    }

    map.setInverse(false);
}

From source file:org.inwiss.platform.persistence.hibernate.core.UserDAOHibernate.java

License:Apache License

/**
 * @see org.inwiss.platform.persistence.core.UserDAO#deleteUserCookies(java.lang.String)
 *//*from  w  w w.j  a va2s . com*/
public void deleteUserCookies(String userName) {
    String hql = "from UserCookie c where c.user.name = ?";
    List cookies = executeFind(hql, new Object[] { userName }, new Type[] { StandardBasicTypes.STRING });
    if (cookies != null && cookies.size() > 0) {
        for (int i = 0; i < cookies.size(); i++) {
            UserCookie userCookie = (UserCookie) cookies.get(i);
            getHibernateTemplate().delete(userCookie);
        }
    }
}

From source file:org.inwiss.platform.persistence.hibernate.core.UserDAOHibernate.java

License:Apache License

public List<Long> loadUserMenus(String userName) {
    String hql = " select distinct m.id from MenuItem m  " + " inner join m.roles as r "
            + " inner join r.users as u " + " where u.name = ?";
    List menuIds = executeFind(hql, new Object[] { userName }, new Type[] { StandardBasicTypes.STRING });
    return menuIds;
}

From source file:org.inwiss.platform.persistence.hibernate.core.UserDAOHibernate.java

License:Apache License

@Override
public PartialCollection loadUsersByOrgId(QueryInfo queryInfo) {
    List list = null;//w  w w  .  j  av a2s .  com
    Integer total = null;
    Map<String, String> queryParameters = queryInfo.getQueryParameters();
    String dept = queryParameters.get("dept");
    String hql = "from User u where u.dept = ?";
    list = executeFind(hql, new Object[] { dept }, new Type[] { StandardBasicTypes.STRING });
    if (list == null) {
        list = new ArrayList();
    }
    if (total == null) {
        total = new Integer(list.size());
    }

    return new PartialCollection(list, total);
}

From source file:org.jadira.usertype.spi.shared.AbstractStringColumnMapper.java

License:Apache License

public final StringType getHibernateType() {
    return StandardBasicTypes.STRING;
}

From source file:org.jboss.as.quickstart.hibernate4.util.vertica.VerticaDialect6.java

License:Open Source License

protected void registerFunctions() {
    registerFunction("abs", new StandardSQLFunction("abs"));
    registerFunction("sign", new StandardSQLFunction("sign", StandardBasicTypes.INTEGER));

    registerFunction("acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE));
    registerFunction("asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE));
    registerFunction("atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE));
    registerFunction("cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE));
    registerFunction("exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE));
    registerFunction("ln", new StandardSQLFunction("ln", StandardBasicTypes.DOUBLE));
    registerFunction("sin", new StandardSQLFunction("sin", StandardBasicTypes.DOUBLE));
    registerFunction("stddev", new StandardSQLFunction("stddev", StandardBasicTypes.DOUBLE));
    registerFunction("sqrt", new StandardSQLFunction("sqrt", StandardBasicTypes.DOUBLE));
    registerFunction("tan", new StandardSQLFunction("tan", StandardBasicTypes.DOUBLE));
    registerFunction("variance", new StandardSQLFunction("variance", StandardBasicTypes.DOUBLE));

    registerFunction("round", new StandardSQLFunction("round"));
    registerFunction("trunc", new StandardSQLFunction("trunc"));
    registerFunction("ceil", new StandardSQLFunction("ceil"));
    registerFunction("floor", new StandardSQLFunction("floor"));

    registerFunction("chr", new StandardSQLFunction("chr", StandardBasicTypes.CHARACTER));
    registerFunction("initcap", new StandardSQLFunction("initcap"));
    registerFunction("lower", new StandardSQLFunction("lower"));
    registerFunction("ltrim", new StandardSQLFunction("ltrim"));
    registerFunction("rtrim", new StandardSQLFunction("rtrim"));
    registerFunction("upper", new StandardSQLFunction("upper"));
    registerFunction("ascii", new StandardSQLFunction("ascii", StandardBasicTypes.INTEGER));

    registerFunction("to_char", new StandardSQLFunction("to_char", StandardBasicTypes.STRING));
    registerFunction("to_date", new StandardSQLFunction("to_date", StandardBasicTypes.TIMESTAMP));

    registerFunction("current_date", new NoArgSQLFunction("current_date", StandardBasicTypes.DATE, false));
    registerFunction("current_time", new NoArgSQLFunction("current_timestamp", StandardBasicTypes.TIME, false));
    registerFunction("current_timestamp",
            new NoArgSQLFunction("current_timestamp", StandardBasicTypes.TIMESTAMP, false));

    registerFunction("last_day", new StandardSQLFunction("last_day", StandardBasicTypes.DATE));
    registerFunction("sysdate", new NoArgSQLFunction("sysdate", StandardBasicTypes.DATE, false));
    registerFunction("user", new NoArgSQLFunction("user", StandardBasicTypes.STRING, false));

    // Multi-param string dialect functions...
    registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", ""));
    registerFunction("instr", new StandardSQLFunction("instr", StandardBasicTypes.INTEGER));
    registerFunction("instrb", new StandardSQLFunction("instrb", StandardBasicTypes.INTEGER));
    registerFunction("lpad", new StandardSQLFunction("lpad", StandardBasicTypes.STRING));
    registerFunction("replace", new StandardSQLFunction("replace", StandardBasicTypes.STRING));
    registerFunction("rpad", new StandardSQLFunction("rpad", StandardBasicTypes.STRING));
    registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
    registerFunction("substrb", new StandardSQLFunction("substrb", StandardBasicTypes.STRING));
    registerFunction("translate", new StandardSQLFunction("translate", StandardBasicTypes.STRING));

    registerFunction("substring", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
    registerFunction("bit_length", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "vsize(?1)*8"));
    registerFunction("coalesce", new NvlFunction());

    // Multi-param numeric dialect functions...
    registerFunction("atan2", new StandardSQLFunction("atan2", StandardBasicTypes.FLOAT));
    registerFunction("log", new StandardSQLFunction("log", StandardBasicTypes.INTEGER));
    registerFunction("mod", new StandardSQLFunction("mod", StandardBasicTypes.INTEGER));
    registerFunction("nvl", new StandardSQLFunction("nvl"));
    registerFunction("nvl2", new StandardSQLFunction("nvl2"));
    registerFunction("power", new StandardSQLFunction("power", StandardBasicTypes.FLOAT));

    // Multi-param date dialect functions...
    registerFunction("add_months", new StandardSQLFunction("add_months", StandardBasicTypes.DATE));
    registerFunction("months_between", new StandardSQLFunction("months_between", StandardBasicTypes.FLOAT));
    registerFunction("next_day", new StandardSQLFunction("next_day", StandardBasicTypes.DATE));

}

From source file:org.joda.time.contrib.hibernate.AbstractStringBasedJodaType.java

License:Apache License

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    String s = (String) StandardBasicTypes.STRING.nullSafeGet(rs, names[0], session, owner);
    if (s == null) {
        return null;
    }//  w w  w. jav a2s  . c om

    return fromNonNullString(s);
}