Example usage for org.hibernate JDBCException getSQLException

List of usage examples for org.hibernate JDBCException getSQLException

Introduction

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

Prototype

public SQLException getSQLException() 

Source Link

Document

Get the underlying SQLException .

Usage

From source file:co.nubetech.crux.dao.ColumnAliasDAO.java

License:Apache License

public long save(ColumnAlias detail) throws CruxException {
    try {/* ww  w.java 2 s  .  com*/
        transaction.begin();
        session.saveOrUpdate(detail);
        transaction.commit();
    } catch (JDBCException e) {
        transaction.rollback();
        throw new CruxException(e.getSQLException().getMessage(), e);
    }
    return detail.getId();
}

From source file:co.nubetech.crux.dao.ColumnAliasDAO.java

License:Apache License

public long delete(ColumnAlias detail) throws CruxException {
    long id = detail.getId();
    try {/*  w w  w.j a v a  2s.c om*/
        // deleteAllChildrens(detail);
        transaction.begin();
        session.delete(detail);
        transaction.commit();
    } catch (JDBCException e) {
        transaction.rollback();
        throw new CruxException(e.getSQLException().getMessage(), e);
    }
    return id;
}

From source file:co.nubetech.crux.dao.ColumnFilterDAO.java

License:Apache License

public long save(ColumnFilter columnFilter) throws CruxException {
    try {//from  w w  w. j  a v a  2  s  .  c om
        transaction.begin();
        session.saveOrUpdate(columnFilter);
        transaction.commit();
    } catch (JDBCException e) {
        transaction.rollback();
        throw new CruxException(e.getSQLException().getMessage(), e);
    }
    return columnFilter.getId();
}

From source file:co.nubetech.crux.dao.ColumnFilterDAO.java

License:Apache License

public long delete(ColumnFilter columnFilter) throws CruxException {
    long id = columnFilter.getId();
    try {//from   w w w .j  a va2 s.  c o  m
        // deleteAllChildrens(detail);
        transaction.begin();
        session.delete(columnFilter);
        transaction.commit();
    } catch (JDBCException e) {
        transaction.rollback();
        throw new CruxException(e.getSQLException().getMessage(), e);
    }
    return id;
}

From source file:co.nubetech.crux.dao.ConnectionDAO.java

License:Apache License

public long save(Connection connection) throws CruxException {
    try {/*from w  ww .  java2s.c o m*/
        transaction.begin();
        session.saveOrUpdate(connection);
        transaction.commit();
    } catch (JDBCException e) {
        transaction.rollback();
        throw new CruxException(e.getSQLException().getMessage(), e);
    }

    return connection.getId();
}

From source file:co.nubetech.crux.dao.ConnectionPropertyDAO.java

License:Apache License

public long save(ConnectionProperty connectionProperty) throws CruxException {
    try {//  www  . ja  v a  2s  .c o m
        transaction.begin();
        session.saveOrUpdate(connectionProperty);
        transaction.commit();
    } catch (JDBCException e) {
        transaction.rollback();
        throw new CruxException(e.getSQLException().getMessage(), e);
    }
    return connectionProperty.getId();
}

From source file:co.nubetech.crux.dao.ConnectionPropertyDAO.java

License:Apache License

public long delete(ConnectionProperty connectionProperty) throws CruxException {
    long id = connectionProperty.getId();
    try {/*ww  w  . j  a v a 2  s  .c o  m*/
        transaction.begin();
        session.delete(connectionProperty);
        transaction.commit();
    } catch (JDBCException e) {
        transaction.rollback();
        throw new CruxException(e.getSQLException().getMessage(), e);
    }
    return id;
}

From source file:co.nubetech.crux.dao.MappingDAO.java

License:Apache License

private Mapping updateColumnAlias(Mapping mapping, Mapping foundMapping) throws CruxException {
    Map<String, ColumnAlias> oldColumnAliasMap = new HashMap<String, ColumnAlias>(
            foundMapping.getColumnAlias());
    Map<String, ColumnAlias> newColumnAliasMap = new HashMap<String, ColumnAlias>(mapping.getColumnAlias());

    Iterator<ColumnAlias> iteratorForOldColumnAlias = oldColumnAliasMap.values().iterator();
    Iterator<ColumnAlias> iteratorForNewColumnAlias = newColumnAliasMap.values().iterator();

    // Delete non-existing column alias.
    while (iteratorForOldColumnAlias.hasNext()) {
        ColumnAlias oldColumnAlias = iteratorForOldColumnAlias.next();
        Iterator<ColumnAlias> iteratorForNewColumnAlias1 = newColumnAliasMap.values().iterator();
        boolean columnAliasExists = false;
        while (iteratorForNewColumnAlias1.hasNext()) {
            ColumnAlias newColumnAlias = iteratorForNewColumnAlias1.next();
            if (newColumnAlias.getId() == oldColumnAlias.getId()) {
                columnAliasExists = true;
            }/* w ww.ja  v a  2s  . c o m*/
        }

        logger.debug("ColumnAliasExists: " + columnAliasExists);

        if (!columnAliasExists) {
            logger.debug("Removing ColumnAlias: " + oldColumnAlias);
            foundMapping.getColumnAlias().remove(oldColumnAlias.getAlias());
            try {
                transaction.begin();
                session.delete(oldColumnAlias);
                transaction.commit();
            } catch (JDBCException e) {
                transaction.rollback();
                throw new CruxException(e.getSQLException().getMessage(), e);
            }
        }

    }

    // Add new column alias and update old rowAlias.
    while (iteratorForNewColumnAlias.hasNext()) {
        ColumnAlias columnAlias = iteratorForNewColumnAlias.next();
        logger.debug("columnAlias: " + columnAlias);
        if (columnAlias.getId() == 0l) {
            foundMapping.addColumnAlias(columnAlias);
        } else {
            long columnAliasId = columnAlias.getId();
            String alias = columnAlias.getAlias();
            ValueType columnAliasColumnType = columnAlias.getValueType();
            String columnAliasCF = columnAlias.getColumnFamily();
            String columnAliasQualifier = columnAlias.getQualifier();

            Iterator<ColumnAlias> iteratorForOldColumnAlias1 = oldColumnAliasMap.values().iterator();

            while (iteratorForOldColumnAlias1.hasNext()) {
                ColumnAlias oldColumnAlias = iteratorForOldColumnAlias1.next();
                if (oldColumnAlias.getId() == columnAliasId) {
                    oldColumnAlias.setAlias(alias);
                    oldColumnAlias.setValueType(columnAliasColumnType);
                    oldColumnAlias.setColumnFamily(columnAliasCF);
                    oldColumnAlias.setQualifier(columnAliasQualifier);
                }
            }
        }
    }

    return foundMapping;

}

From source file:co.nubetech.crux.dao.MappingDAO.java

License:Apache License

private Mapping updateRowAlias(Mapping mapping, Mapping foundMapping) throws CruxException {
    Map<String, RowAlias> oldRowAliasMap = new HashMap<String, RowAlias>(foundMapping.getRowAlias());
    Map<String, RowAlias> newRowAliasMap = new HashMap<String, RowAlias>(mapping.getRowAlias());

    Iterator<RowAlias> iteratorForOldRowAlias = oldRowAliasMap.values().iterator();
    Iterator<RowAlias> iteratorForNewRowAlias = newRowAliasMap.values().iterator();

    // Delete non-existing row alias.
    while (iteratorForOldRowAlias.hasNext()) {
        RowAlias oldRowAlias = iteratorForOldRowAlias.next();
        Iterator<RowAlias> iteratorForNewRowAlias1 = newRowAliasMap.values().iterator();
        boolean rowAliasExists = false;
        while (iteratorForNewRowAlias1.hasNext()) {
            RowAlias newRowAlias = iteratorForNewRowAlias1.next();
            if (newRowAlias.getId() == oldRowAlias.getId()) {
                rowAliasExists = true;/*from w  w  w  .j a  v a 2  s.  c om*/
            }
        }

        logger.debug("rowAliasExists: " + rowAliasExists);

        if (!rowAliasExists) {
            logger.debug("Removing rowAlias: " + oldRowAlias);
            foundMapping.getRowAlias().remove(oldRowAlias.getAlias());
            try {
                transaction.begin();
                session.delete(oldRowAlias);
                transaction.commit();
            } catch (JDBCException e) {
                transaction.rollback();
                throw new CruxException(e.getSQLException().getMessage(), e);
            }
        }

    }

    // Add new row alias and update old rowAlias.
    while (iteratorForNewRowAlias.hasNext()) {
        RowAlias rowAlias = iteratorForNewRowAlias.next();
        logger.debug("rowAlias: " + rowAlias);
        if (rowAlias.getId() == 0l) {
            foundMapping.addRowAlias(rowAlias);
        } else {
            long rowAliasId = rowAlias.getId();
            String alias = rowAlias.getAlias();
            ValueType rowAliasColumnType = rowAlias.getValueType();
            Integer rowAliasLength = rowAlias.getLength();

            Iterator<RowAlias> iteratorForOldRowAlias1 = oldRowAliasMap.values().iterator();

            while (iteratorForOldRowAlias1.hasNext()) {
                RowAlias oldRowAlias = iteratorForOldRowAlias1.next();
                if (oldRowAlias.getId() == rowAliasId) {
                    oldRowAlias.setAlias(alias);
                    oldRowAlias.setValueType(rowAliasColumnType);
                    oldRowAlias.setLength(rowAliasLength);
                }
            }
        }
    }
    return foundMapping;
}

From source file:co.nubetech.crux.dao.MappingDAO.java

License:Apache License

public long saveMapping(Mapping mapping) throws CruxException {
    try {/*from   www  . j a  v a 2 s.  c  o  m*/
        logger.debug("Session is: " + session);
        transaction.begin();
        session.saveOrUpdate(mapping);
        transaction.commit();
    } catch (JDBCException e) {
        transaction.rollback();
        throw new CruxException(e.getSQLException().getMessage(), e);
    }
    return mapping.getId();
}