Example usage for org.hibernate HibernateException HibernateException

List of usage examples for org.hibernate HibernateException HibernateException

Introduction

In this page you can find the example usage for org.hibernate HibernateException HibernateException.

Prototype

public HibernateException(Throwable cause) 

Source Link

Document

Constructs a HibernateException using the given message and underlying cause.

Usage

From source file:com.tida_okinawa.corona.io.dam.hibernate.IoService.java

License:Open Source License

@Override
protected int addCategoryDam(String category) {
    try {//from www  .  jav a2 s  .co m
        int id = 0;
        CategoryBean result = (CategoryBean) CommonCreateQuery.getCategoryQuery(category).uniqueResult();
        if (result != null) {
            id = result.getId();
            if (id != 0) {
                return 0;
            }
        }
        CategoryBean addCategory = new CategoryBean();
        addCategory.setName(category);
        /*  */
        this.session.beginTransaction();
        this.session.save(addCategory);
        this.session.flush();
        /*  */
        this.session.getTransaction().commit();
        result = (CategoryBean) CommonCreateQuery.getCategoryQuery(category).uniqueResult();
        if (result.getId() <= 0) {
            throw new HibernateException(Messages.IoService_systemErrorGetCategoryInfo);
        }
        return result.getId();
    } catch (HibernateException e) {
        e.printStackTrace();
        return -1;
    } finally {
        if (this.session.getTransaction().isActive()) {
            this.session.getTransaction().rollback();
        }
    }
}

From source file:com.tida_okinawa.corona.io.dam.hibernate.IoService.java

License:Open Source License

@Override
public void removeCategory(String categoryName) {
    CategoryBean category = (CategoryBean) CommonCreateQuery.getCategoryQuery(categoryName).uniqueResult();
    if (category != null) {
        try {//w  w  w  .  j av  a 2 s  .com
            /*  */
            this.session.beginTransaction();
            this.session.delete(category);
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
        category = (CategoryBean) CommonCreateQuery.getCategoryQuery(categoryName).uniqueResult();
        if (category != null) {
            throw new HibernateException(
                    "?????()"); //$NON-NLS-1$
        }
    }
    for (Iterator<TextItem> itr = _categoryList.iterator(); itr.hasNext();) {
        TextItem item = itr.next();
        if (item.getText().equals(categoryName)) {
            itr.remove();
            break;
        }
    }
}

From source file:com.tida_okinawa.corona.io.dam.hibernate.IoService.java

License:Open Source License

/**
 * ??????// ww w .jav  a2s.c o  m
 * TODO:???????finally????
 * 
 * @param name
 *            ???????
 * @param dbName
 *            ???????????
 * @param type
 *            
 * @param projectId
 *            ID
 * @param productId
 *            ID
 * @param claimId
 *            ?????ID
 * @param tgts
 *            ID
 * @return ?ID
 * @throws SQLException
 *             , HibernateException
 */
private int createClaimWorkDataTable(String name, String dbName, TableType type, int projectId, int productId,
        int claimId, Set<Integer> tgts) throws SQLException, HibernateException {

    // ClaimWorkDataDao

    StringBuilder strSQL = new StringBuilder(192).append("CREATE TABLE "); //$NON-NLS-1$
    if (dbName == null) {
        throw new HibernateException("Not find dbname"); //$NON-NLS-1$
    }
    /* ? */
    String strExeSql = ""; //$NON-NLS-1$
    String strWork = CoronaIoUtils.createWorkTableName(dbName, type, projectId);
    int workId = 0;

    /* TablesDao.getTableId(strWork);?? */
    try {
        strExeSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='").append(strWork) //$NON-NLS-1$
                .append("'").toString(); //$NON-NLS-1$
        @SuppressWarnings("unchecked")
        List<Object> list = this.session.createSQLQuery(strExeSql).list();
        if (list != null && list.size() > 0) {
            Object rs = list.get(0);
            workId = Integer.parseInt(rs.toString());
        }
    } catch (HibernateException e) {
        CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
        throw e;
    }
    if (workId == 0) {
        // ???USR_WORK_????USR_CM_??USR_CM_()????????
        strSQL.append(strWork).append(" (").append("WORK_ID INT NOT NULL, ").append("FLD_ID INT NOT NULL, ") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                .append("REC_ID INT NOT NULL, "); //$NON-NLS-1$

        if (TableType.CORRECTION_MISTAKES_DATA.equals(type)) {
            // USR_CM_??
            strSQL.append("DATA MEDIUMTEXT, ").append("PRIMARY KEY (WORK_ID, FLD_ID, REC_ID));"); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            // USR_WORK_????ID???
            strSQL.append("HISTORY_ID INT, "); //$NON-NLS-1$
            strSQL.append("DATA MEDIUMTEXT, ").append("PRIMARY KEY (WORK_ID, FLD_ID, REC_ID, HISTORY_ID));"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        try {
            /*  */
            this.session.beginTransaction();
            this.session.createSQLQuery(strSQL.toString()).executeUpdate();
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strSQL.toString()); //$NON-NLS-1$
            throw e;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        /* ? */
        /* TablesDao.insertTable(name, strWork, type);?? */
        try {
            // INSERT IGNORE INTO TABLES....???
            StringBuilder strCheckHQL = new StringBuilder(150)
                    .append("from TablesBean where name = :NAME and dbname = :DBNAME and type = :TYPE"); //$NON-NLS-1$
            @SuppressWarnings("unchecked")
            List<TablesBean> list = this.session.createQuery(strCheckHQL.toString()).setString("NAME", name) //$NON-NLS-1$
                    .setString("DBNAME", strWork) //$NON-NLS-1$
                    .setInteger("TYPE", type.getIntValue()) //$NON-NLS-1$
                    .list();
            if (list != null && list.size() == 0) {
                StringBuilder strSql = new StringBuilder(128)
                        .append("INSERT INTO TABLES (NAME, DBNAME, TYPE, LASTED) VALUES('"); //$NON-NLS-1$
                strSql.append(name).append("','").append(strWork).append("',").append(type.getIntValue()) //$NON-NLS-1$//$NON-NLS-2$
                        .append(",now())"); //$NON-NLS-1$
                strExeSql = strSql.toString();
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(strExeSql).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            }

        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            throw e;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
        /* workId = TablesDao.getTableId(strWork); ?? */
        try {
            String strSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='").append(dbName) //$NON-NLS-1$
                    .append("'").toString(); //$NON-NLS-1$
            strExeSql = strSql;
            @SuppressWarnings("unchecked")
            List<Object> list = this.session.createSQLQuery(strExeSql).list();
            if (list != null && list.size() > 0) {
                Object rs = list.get(0);
                workId = Integer.parseInt(rs.toString());
            }
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            throw e;
        }
        if (workId == 0) {
            throw new HibernateException("not find workId"); //$NON-NLS-1$
        }

        // ??USR_CLAIMxxx?Index
        if (!TableType.CORRECTION_MISTAKES_DATA.equals(type)) {
            StringBuilder strCreateIndex = new StringBuilder("CREATE INDEX "); //$NON-NLS-1$
            strCreateIndex.append(strWork).append("_INDEX ON ").append(strWork) //$NON-NLS-1$
                    .append("(WORK_ID, HISTORY_ID, REC_ID ASC);"); //$NON-NLS-1$
            // CommonDao.executeSQL4Throws(strCreateIndex.toString());
            // ??
            try {
                strExeSql = strCreateIndex.toString();
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(strExeSql).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                throw e;
            } finally {
                if (this.session.getTransaction().isActive()) {
                    this.session.getTransaction().rollback();
                }
            }
        }
    }

    if (type == TableType.WORK_DATA) {
        /* TODO:? */
        String strRelPtn = CoronaIoUtils.createWorkTableName(dbName, TableType.RESULT_DATA, projectId);
        int relId = 0;
        /* TablesDao.getTableId(strRelPtn); ?? */
        try {
            String strSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='") //$NON-NLS-1$
                    .append(strRelPtn).append("'").toString(); //$NON-NLS-1$
            strExeSql = strSql;
            @SuppressWarnings("unchecked")
            List<Object> list = this.session.createSQLQuery(strExeSql).list();
            if (list != null && list.size() > 0) {
                Object rs = list.get(0);
                relId = Integer.parseInt(rs.toString());
            }
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            throw e;
        }

        if (relId == 0) {
            StringBuilder createSql = new StringBuilder(128);
            createSql.append("Create Table ").append(strRelPtn); //$NON-NLS-1$
            createSql.append("(work_id Int Not NULL,").append("fld_id Int Not NULL,"); //$NON-NLS-1$ //$NON-NLS-2$
            createSql.append("history Int Not NULL,").append("rec_id Int Not NULL,"); //$NON-NLS-1$ //$NON-NLS-2$
            createSql.append("pattern_id Int Not NULL,").append("hit_info MediumText Not NULL)"); //$NON-NLS-1$ //$NON-NLS-2$
            // CommonDao.executeSQL4Throws(createSql.toString());
            try {
                strExeSql = createSql.toString();
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(strExeSql).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                throw e;
            } finally {
                if (this.session.getTransaction().isActive()) {
                    this.session.getTransaction().rollback();
                }
            }
            // ?
            /*
             * TablesDao.insertTable(TableType.RESULT_DATA.toString(),
             * strRelPtn, TableType.RESULT_DATA); ??
             */
            try {
                String paraName = TableType.RESULT_DATA.toString();
                String paraDbName = strRelPtn;
                int paraType = TableType.RESULT_DATA.getIntValue();

                // INSERT IGNORE INTO WORKDATAS....???
                StringBuilder strCheckHQL = new StringBuilder(150)
                        .append("from TablesBean where name = :NAME and dbname = :DBNAME and type = :TYPE"); //$NON-NLS-1$
                @SuppressWarnings("unchecked")
                List<TablesBean> list = this.session.createQuery(strCheckHQL.toString())
                        .setString("NAME", paraName) //$NON-NLS-1$
                        .setString("DBNAME", paraDbName) //$NON-NLS-1$
                        .setInteger("TYPE", paraType) //$NON-NLS-1$
                        .list();
                if (list != null && list.size() == 0) {
                    StringBuilder strSql = new StringBuilder(128)
                            .append("INSERT INTO TABLES (NAME, DBNAME, TYPE, LASTED) VALUES('"); //$NON-NLS-1$
                    strSql.append(paraName).append("','").append(paraDbName).append("',").append(paraType) //$NON-NLS-1$//$NON-NLS-2$
                            .append(",now())"); //$NON-NLS-1$
                    strExeSql = strSql.toString();
                    /*  */
                    this.session.beginTransaction();
                    this.session.createSQLQuery(strExeSql).executeUpdate();
                    this.session.flush();
                    /*  */
                    this.session.getTransaction().commit();
                }
            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                throw e;
            } finally {
                if (this.session.getTransaction().isActive()) {
                    this.session.getTransaction().rollback();
                }
            }
            /* relId = TablesDao.getTableId(strRelPtn); ? */
            relId = 0;
            try {
                String strSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='") //$NON-NLS-1$
                        .append(strRelPtn).append("'").toString(); //$NON-NLS-1$
                strExeSql = strSql;
                @SuppressWarnings("unchecked")
                List<Object> list = this.session.createSQLQuery(strExeSql).list();
                if (list != null && list.size() > 0) {
                    Object rs = list.get(0);
                    relId = Integer.parseInt(rs.toString());
                }
            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                throw e;
            }
            if (relId == 0) {
                throw new HibernateException("not find workId"); //$NON-NLS-1$
            }

            StringBuffer strCreateIndex = new StringBuffer().append("CREATE INDEX "); //$NON-NLS-1$
            strCreateIndex.append(strRelPtn).append("_INDEX ON ").append(strRelPtn) //$NON-NLS-1$
                    .append("(WORK_ID, HISTORY, REC_ID ASC);"); //$NON-NLS-1$
            /*
             * CommonDao.executeSQL4Throws(strCreateIndex.toString());
             * ??
             */
            try {
                strExeSql = strCreateIndex.toString();
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(strExeSql).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                throw e;
            } finally {
                if (this.session.getTransaction().isActive()) {
                    this.session.getTransaction().rollback();
                }
            }

        }

        /* - */
        insertRelationClaimData(projectId, productId, claimId, workId, relId, tgts);

    }

    /* ID? */
    /* return TablesDao.getTableId(strWork); ?? */
    try {
        strExeSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='").append(strWork) //$NON-NLS-1$
                .append("'").toString(); //$NON-NLS-1$
        workId = 0;
        @SuppressWarnings("unchecked")
        List<Object> list = this.session.createSQLQuery(strExeSql).list();
        if (list != null && list.size() > 0) {
            Object rs = list.get(0);
            workId = Integer.parseInt(rs.toString());
        }
    } catch (HibernateException e) {
        CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
        throw e;
    }
    return workId;
}

From source file:com.yahoo.elide.datastores.hibernate3.usertypes.JsonType.java

License:Apache License

/**
 * {@inheritDoc}/*from  ww  w  . jav a  2  s . c  om*/
 */
@Override
public Object nullSafeGet(ResultSet resultSet, String[] names, Object object)
        throws HibernateException, SQLException {

    if (resultSet.getString(names[0]) != null) {

        // Get the rawJson
        String rawJson = resultSet.getString(names[0]);

        try {
            ObjectMapper mapper = new ObjectMapper();
            return mapper.readValue(rawJson, this.objectClass);
        } catch (IOException e) {
            throw new HibernateException(
                    "Could not retrieve an instance of the mapped class from a JDBC resultset.");
        }
    }
    return null;
}

From source file:com.yahoo.elide.datastores.hibernate3.usertypes.JsonType.java

License:Apache License

/**
 * {@inheritDoc}/*from   ww  w.  j a  v  a2 s  . c  o  m*/
 */
@Override
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index)
        throws HibernateException, SQLException {

    if (value == null) {
        preparedStatement.setNull(index, Types.NULL);
    } else {
        ObjectMapper mapper = new ObjectMapper();
        try {
            String json = mapper.writeValueAsString(value);
            preparedStatement.setString(index, json);
        } catch (JsonProcessingException e) {
            throw new HibernateException(
                    "Could not write an instance of the mapped class to a prepared statement.");
        }
    }
}

From source file:com.yahoo.elide.datastores.hibernate5.usertypes.JsonType.java

License:Apache License

/**
 * {@inheritDoc}/*from  ww  w .j  ava2 s  . com*/
 */
@Override
public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object ownerSession)
        throws HibernateException, SQLException {

    if (resultSet.getString(names[0]) != null) {

        // Get the rawJson
        String rawJson = resultSet.getString(names[0]);

        try {
            ObjectMapper mapper = new ObjectMapper();
            return mapper.readValue(rawJson, this.objectClass);
        } catch (IOException e) {
            throw new HibernateException(
                    "Could not retrieve an instance of the mapped class from a JDBC resultset.");
        }
    }
    return null;
}

From source file:com.yahoo.elide.datastores.hibernate5.usertypes.JsonType.java

License:Apache License

/**
 * {@inheritDoc}/*w  ww. ja  v a2  s.  c o m*/
 */
@Override
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index,
        SessionImplementor session) throws HibernateException, SQLException {

    if (value == null) {
        preparedStatement.setNull(index, Types.NULL);
    } else {
        ObjectMapper mapper = new ObjectMapper();
        try {
            String json = mapper.writeValueAsString(value);
            preparedStatement.setString(index, json);
        } catch (JsonProcessingException e) {
            throw new HibernateException(
                    "Could not write an instance of the mapped class to a prepared statement.");
        }
    }
}

From source file:com.zaxxer.hikari.hibernate.HikariConnectionProvider.java

License:Apache License

@SuppressWarnings("rawtypes")
@Override/*from  w w w  .j av  a  2s .  c  o  m*/
public void configure(Map props) throws HibernateException {
    try {
        LOGGER.debug("Configuring HikariCP");

        this.hcfg = HikariConfigurationUtil.loadConfiguration(props);
        this.hds = new HikariDataSource(this.hcfg);

    } catch (Exception e) {
        throw new HibernateException(e);
    }

    LOGGER.debug("HikariCP Configured");
}

From source file:com.zutubi.pulse.master.hibernate.HackyConnectionProvider.java

License:Apache License

public void configure(Properties props) throws HibernateException {
    if (dataSource == null) {
        throw new HibernateException("DataSource must be set statically.");
    }/*from   w w  w  . ja v a 2s. c  om*/
}

From source file:common.util.db.MonthEqExpression.java

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    String[] columns = criteriaQuery.getColumns(propertyName, criteria);
    if (columns.length != 1) {
        throw new HibernateException("monthEq may only be used with single-column properties");
    }/*from w w  w. j a v  a  2s . co  m*/
    return "extract(month from " + columns[0] + ") = ?";
}