Example usage for java.sql ResultSet getBoolean

List of usage examples for java.sql ResultSet getBoolean

Introduction

In this page you can find the example usage for java.sql ResultSet getBoolean.

Prototype

boolean getBoolean(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a boolean in the Java programming language.

Usage

From source file:esg.node.security.UserInfoDAO.java

public void init() {

    this.idResultSetHandler = new ResultSetHandler<Integer>() {
        public Integer handle(ResultSet rs) throws SQLException {
            if (!rs.next()) {
                return -1;
            }/*  w  ww. j  a v a2s .  c om*/
            return rs.getInt(1);
        }
    };

    this.booleanResultSetHandler = new ResultSetHandler<Boolean>() {
        public Boolean handle(ResultSet rs) throws SQLException {
            if (!rs.next()) {
                return false;
            }
            return rs.getBoolean(1);
        }
    };

    this.existsResultSetHandler = new ResultSetHandler<Boolean>() {
        public Boolean handle(ResultSet rs) throws SQLException {
            if (!rs.next()) {
                return false;
            }
            return (rs.getInt(1) > 0);
        }
    };

    this.singleStringResultSetHandler = new ResultSetHandler<String>() {
        public String handle(ResultSet rs) throws SQLException {
            if (!rs.next()) {
                return null;
            }
            return rs.getString(1);
        }
    };

    passwordQueryHandler = new ResultSetHandler<String>() {
        public String handle(ResultSet rs) throws SQLException {
            String password = null;
            while (rs.next()) {
                password = rs.getString(1);
            }
            return password;
        }
    };

    //To handle the single record result
    userInfoResultSetHandler = new ResultSetHandler<UserInfo>() {
        public UserInfo handle(ResultSet rs) throws SQLException {
            UserInfo userInfo = null;
            while (rs.next()) {
                userInfo = new UserInfo();
                userInfo.setid(rs.getInt(1)).setOpenid(rs.getString(2)).setFirstName(rs.getString(3))
                        .setMiddleName(rs.getString(4)).setLastName(rs.getString(5))
                        .setUserName(rs.getString(6)).setEmail(rs.getString(7)).setDn(rs.getString(8))
                        .setOrganization(rs.getString(9)).setOrgType(rs.getString(10)).setCity(rs.getString(11))
                        .setState(rs.getString(12)).setCountry(rs.getString(13)).setStatusCode(rs.getInt(14));
            }
            return userInfo;
        }
    };

    userPermissionsResultSetHandler = new ResultSetHandler<Map<String, Set<String>>>() {
        Map<String, Set<String>> permissions = new HashMap<String, Set<String>>();
        Set<String> roleSet = null;

        public Map<String, Set<String>> handle(ResultSet rs) throws SQLException {
            permissions.clear();
            if (!rs.next()) {
                return permissions;
            }
            do {
                addPermission(rs.getString(1), rs.getString(2));
            } while (rs.next());
            return permissions;
        }

        public void addPermission(String groupName, String roleName) {
            //lazily instantiate the set of values for group if not
            //there
            if ((roleSet = permissions.get(groupName)) == null) {
                roleSet = new HashSet<String>();
            }

            //enter group associated with group value set
            roleSet.add(roleName);
            permissions.put(groupName, roleSet);
        }
    };

    basicResultSetHandler = new ResultSetHandler<List<String[]>>() {
        public List<String[]> handle(ResultSet rs) throws SQLException {
            ArrayList<String[]> results = new ArrayList<String[]>();
            String[] record = null;
            assert (null != results);

            ResultSetMetaData meta = rs.getMetaData();
            int cols = meta.getColumnCount();
            log.trace("Number of fields: " + cols);

            log.trace("adding column data...");
            record = new String[cols];
            for (int i = 0; i < cols; i++) {
                try {
                    record[i] = meta.getColumnLabel(i + 1);
                } catch (SQLException e) {
                    log.error(e);
                }
            }
            results.add(record);

            for (int i = 0; rs.next(); i++) {
                log.trace("Looking at record " + (i + 1));
                record = new String[cols];
                for (int j = 0; j < cols; j++) {
                    record[j] = rs.getString(j + 1);
                    log.trace("gathering result record column " + (j + 1) + " -> " + record[j]);
                }
                log.trace("adding record ");
                results.add(record);
                record = null; //gc courtesy
            }
            return results;
        }
    };

    new InitAdmin();
}

From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#retrieveMessage(String)
 *///from  w  ww  .j av  a 2  s  .c o  m
public synchronized List<Object> retrieveMessage(final String messageId) throws SQLException {
    final String methodName = IWebMessagingDAO.CNAME
            + "#retrieveMessage(final String messageId) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug(messageId);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    List<Object> svcMessage = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL retrServiceMessage(?)}");
        stmt.setString(1, messageId);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.execute()) {
            resultSet = stmt.getResultSet();

            if (resultSet.next()) {
                resultSet.first();
                svcMessage = new ArrayList<Object>();
                svcMessage.add(resultSet.getString(1)); // svc_message_id
                svcMessage.add(resultSet.getString(2)); // svc_message_title
                svcMessage.add(resultSet.getString(3)); // svc_message_txt
                svcMessage.add(resultSet.getString(4)); // svc_message_author
                svcMessage.add(resultSet.getTimestamp(5)); // svc_message_submitdate
                svcMessage.add(resultSet.getBoolean(6)); // svc_message_active
                svcMessage.add(resultSet.getBoolean(7)); // svc_message_alert
                svcMessage.add(resultSet.getBoolean(8)); // svc_message_expires
                svcMessage.add(resultSet.getTimestamp(9)); // svc_message_expirydate
                svcMessage.add(resultSet.getTimestamp(10)); // svc_message_modifiedon
                svcMessage.add(resultSet.getString(11)); // svc_message_modifiedby

                if (DEBUG) {
                    DEBUGGER.debug("svcMessage: {}", svcMessage);
                }
            }
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return svcMessage;
}

From source file:edu.jhu.pha.vosync.rest.DropboxService.java

@GET
@Path("shares")
@RolesAllowed({ "user" })
public byte[] getShares() {
    final SciDriveUser user = ((SciDriveUser) security.getUserPrincipal());

    ByteArrayOutputStream byteOut = null;
    try {/*from   ww  w.  j  av a  2 s  . com*/
        JsonFactory f = new JsonFactory();
        byteOut = new ByteArrayOutputStream();
        final JsonGenerator g2 = f.createJsonGenerator(byteOut);

        g2.writeStartArray();

        DbPoolServlet.goSql("Get shares",
                "select share_id, container_name, group_name, share_write_permission FROM container_shares "
                        + "LEFT JOIN groups ON container_shares.group_id = groups.group_id "
                        + "JOIN containers ON container_shares.container_id = containers.container_id "
                        + "JOIN user_identities ON containers.user_id = user_identities.user_id WHERE identity = ?",
                new SqlWorker<Boolean>() {
                    @Override
                    public Boolean go(Connection conn, PreparedStatement stmt) throws SQLException {
                        stmt.setString(1, user.getName());
                        ResultSet rs = stmt.executeQuery();
                        while (rs.next()) {
                            try {
                                g2.writeStartObject();
                                g2.writeStringField("share_id", rs.getString("share_id"));
                                g2.writeStringField("container", rs.getString("container_name"));
                                g2.writeStringField("group", rs.getString("group_name"));
                                g2.writeBooleanField("write_permission",
                                        rs.getBoolean("share_write_permission"));
                                g2.writeEndObject();
                            } catch (IOException ex) {
                                logger.error(ex.getMessage());
                            }
                        }
                        return true;
                    }
                });
        g2.writeEndArray();

        g2.close();
        byteOut.close();
        return byteOut.toByteArray();
    } catch (IOException ex) {
        throw new InternalServerErrorException(ex);
    }
}

From source file:com.cws.us.pws.dao.impl.ProductReferenceDAOImpl.java

/**
 * @see com.cws.us.pws.dao.interfaces.IProductReferenceDAO#getProductList(String) throws SQLException
 *///from w ww .j a  v  a2s.  co m
@Override
public List<Object[]> getProductList(final String lang) throws SQLException {
    final String methodName = IProductReferenceDAO.CNAME
            + "#getProductList(final String lang) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", lang);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    List<Object[]> results = null;

    try {
        sqlConn = this.dataSource.getConnection();

        if (DEBUG) {
            DEBUGGER.debug("Connection: {}", sqlConn);
        }

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain connection to application datasource");
        }

        stmt = sqlConn.prepareCall("{ CALL getProductList(?) }");
        stmt.setString(1, lang);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (!(stmt.execute())) {
            throw new SQLException("PreparedStatement is null. Cannot execute.");
        }

        resultSet = stmt.getResultSet();

        if (DEBUG) {
            DEBUGGER.debug("ResultSet: {}", resultSet);
        }

        if (resultSet.next()) {
            resultSet.beforeFirst();
            results = new ArrayList<Object[]>();

            while (resultSet.next()) {
                Object[] data = new Object[] { resultSet.getString(1), // PRODUCT_ID
                        resultSet.getString(2), // PRODUCT_NAME
                        resultSet.getString(3), // PRODUCT_SHORT_DESC
                        resultSet.getString(4), // PRODUCT_DESC
                        resultSet.getBigDecimal(5), // PRODUCT_PRICE
                        resultSet.getBoolean(6) // IS_FEATURED
                };

                results.add(data);
            }

            if (DEBUG) {
                DEBUGGER.debug("results: {}", results);
            }
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    if (DEBUG) {
        DEBUGGER.debug("results: {}", results);
    }

    return results;
}

From source file:dk.netarkivet.harvester.datamodel.HarvestDefinitionDBDAO.java

/**
 * Get all sparse versions of partial harvests for GUI purposes ordered by
 * name.//  www. j a  va 2  s.  com
 *
 * @return An iterable (possibly empty) of SparsePartialHarvests
 */
public Iterable<SparsePartialHarvest> getSparsePartialHarvestDefinitions(boolean excludeInactive) {
    Connection c = HarvestDBConnection.get();
    PreparedStatement s = null;
    String query = "SELECT harvestdefinitions.harvest_id," + "       harvestdefinitions.name,"
            + "       harvestdefinitions.comments," + "       harvestdefinitions.numevents,"
            + "       harvestdefinitions.submitted," + "       harvestdefinitions.isactive,"
            + "       harvestdefinitions.edition," + "       schedules.name,"
            + "       partialharvests.nextdate, " + "       harvestdefinitions.audience, "
            + "       harvestdefinitions.channel_id " + "FROM harvestdefinitions, partialharvests, schedules"
            + " WHERE harvestdefinitions.harvest_id " + "       = partialharvests.harvest_id"
            + " AND (harvestdefinitions.isactive " + " = ?"
            // This linie is duplicated to allow to select both active
            // and inactive HD's.
            + " OR harvestdefinitions" + ".isactive " + " = ?)" + "   AND schedules.schedule_id "
            + "       = partialharvests.schedule_id " + "ORDER BY harvestdefinitions.name";
    try {
        s = DBUtils.prepareStatement(c, query, true, excludeInactive);
        ResultSet res = s.executeQuery();
        List<SparsePartialHarvest> harvests = new ArrayList<SparsePartialHarvest>();
        while (res.next()) {
            SparsePartialHarvest sph = new SparsePartialHarvest(res.getLong(1), res.getString(2),
                    res.getString(3), res.getInt(4), new Date(res.getTimestamp(5).getTime()), res.getBoolean(6),
                    res.getLong(7), res.getString(8), DBUtils.getDateMaybeNull(res, 9), res.getString(10),
                    DBUtils.getLongMaybeNull(res, 11));
            harvests.add(sph);
        }
        return harvests;
    } catch (SQLException e) {
        throw new IOFailure("SQL error getting sparse harvests" + "\n" + ExceptionUtils.getSQLExceptionCause(e),
                e);
    } finally {
        DBUtils.closeStatementIfOpen(s);
        HarvestDBConnection.release(c);
    }
}

From source file:com.cws.us.pws.dao.impl.ProductReferenceDAOImpl.java

/**
 * @see com.cws.us.pws.dao.interfaces.IProductReferenceDAO#getFeaturedProducts(String) throws SQLException
 *//*from   w w  w  . j  a  va 2  s .c  o m*/
@Override
public List<Object[]> getFeaturedProducts(final String lang) throws SQLException {
    final String methodName = IProductReferenceDAO.CNAME
            + "#getFeaturedProducts(final String lang) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", lang);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    List<Object[]> results = null;

    try {
        sqlConn = this.dataSource.getConnection();

        if (DEBUG) {
            DEBUGGER.debug("Connection: {}", sqlConn);
        }

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain connection to application datasource");
        }

        stmt = sqlConn.prepareCall("{ CALL getFeaturedProducts(?) }");
        stmt.setString(1, lang);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (!(stmt.execute())) {
            throw new SQLException("PreparedStatement is null. Cannot execute.");
        }

        resultSet = stmt.getResultSet();

        if (DEBUG) {
            DEBUGGER.debug("ResultSet: {}", resultSet);
        }

        if (resultSet.next()) {
            resultSet.beforeFirst();
            results = new ArrayList<Object[]>();

            while (resultSet.next()) {
                Object[] data = new Object[] { resultSet.getString(1), // PRODUCT_ID
                        resultSet.getString(2), // PRODUCT_NAME
                        resultSet.getString(3), // PRODUCT_SHORT_DESC
                        resultSet.getString(4), // PRODUCT_DESC
                        resultSet.getBigDecimal(5), // PRODUCT_PRICE
                        resultSet.getBoolean(6) // IS_FEATURED
                };

                results.add(data);
            }

            if (DEBUG) {
                DEBUGGER.debug("results: {}", results);
            }
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    if (DEBUG) {
        DEBUGGER.debug("results: {}", results);
    }

    return results;
}

From source file:com.sfs.whichdoctor.dao.ReportDAOImpl.java

/**
 * Load the report bean from the result set.
 *
 * @param rs the rs/*from  w ww . j  a  va  2 s .c o m*/
 * @return the report bean
 * @throws SQLException the sQL exception
 */
private ReportBean loadReport(final ResultSet rs) throws SQLException {

    ReportBean report = new ReportBean();

    report.setId(rs.getInt("ReportId"));
    report.setGUID(rs.getInt("GUID"));
    report.setReferenceGUID(rs.getInt("ReferenceGUID"));
    report.setReportType(rs.getString("ReportType"));
    report.setReportStatus(rs.getString("ReportStatus"));
    report.setReportGrouping(rs.getString("ReportGrouping"));
    report.setReportOrder(rs.getInt("ReportOrder"));
    report.setYear(rs.getInt("ReportYear"));
    report.setMemo(rs.getString("Memo"));

    if (StringUtils.equalsIgnoreCase(rs.getString("ReportPublish"), "yes")) {
        report.setReportPublish(true);
    }

    String authors = rs.getString("Authors");

    if (StringUtils.isNotBlank(authors)) {
        StringTokenizer st = new StringTokenizer(authors, ",");
        while (st.hasMoreTokens()) {
            String strGUID = st.nextToken();
            try {
                int guid = Integer.parseInt(strGUID);
                PersonBean person = personDAO.loadGUID(guid);

                if (person != null) {
                    report.addAuthor(person);
                }
            } catch (Exception e) {
                dataLogger.error("Could not load PersonBean for report");
            }
        }
    }

    report.setActive(rs.getBoolean("Active"));
    try {
        report.setCreatedDate(rs.getTimestamp("CreatedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage());
    }
    report.setCreatedBy(rs.getString("CreatedBy"));
    try {
        report.setModifiedDate(rs.getTimestamp("ModifiedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage());
    }
    report.setModifiedBy(rs.getString("ModifiedBy"));
    try {
        report.setExportedDate(rs.getTimestamp("ExportedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage());
    }
    report.setExportedBy(rs.getString("ExportedBy"));

    // Load user details from DB
    UserBean user = new UserBean();
    user.setDN(rs.getString("CreatedBy"));
    user.setPreferredName(rs.getString("CreatedFirstName"));
    user.setLastName(rs.getString("CreatedLastName"));
    report.setCreatedUser(user);

    UserBean modified = new UserBean();
    modified.setDN(rs.getString("ModifiedBy"));
    modified.setPreferredName(rs.getString("ModifiedFirstName"));
    modified.setLastName(rs.getString("ModifiedLastName"));
    report.setModifiedUser(modified);

    UserBean export = new UserBean();
    export.setDN(rs.getString("ExportedBy"));
    export.setPreferredName(rs.getString("ExportedFirstName"));
    export.setLastName(rs.getString("ExportedLastName"));
    report.setExportedUser(export);

    return report;
}

From source file:com.flexive.ejb.beans.ScriptingEngineBean.java

/**
 * {@inheritDoc}//from www  . j  ava2s  .  c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxScriptInfo> getScriptInfos() throws FxApplicationException {
    Connection con = null;
    PreparedStatement ps = null;
    String sql;
    ArrayList<FxScriptInfo> slist = new ArrayList<FxScriptInfo>();
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        //            1     2     3     4    5         6
        sql = "SELECT ID, SNAME,SDESC,STYPE,ACTIVE, IS_CACHED FROM " + TBL_SCRIPTS + " ORDER BY ID";
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();

        while (rs != null && rs.next()) {
            slist.add(new FxScriptInfo(rs.getInt(1), FxScriptEvent.getById(rs.getLong(4)), rs.getString(2),
                    rs.getString(3), rs.getBoolean(5), rs.getBoolean(6)));
        }

    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxLoadException(LOG, exc, "ex.scripts.load.failed", exc.getMessage());
    } finally {
        Database.closeObjects(ScriptingEngineBean.class, con, ps);
    }
    return slist;
}

From source file:chh.utils.db.source.common.JdbcClient.java

public List<List<Column>> select(String sqlQuery, List<Column> queryParams) {
    Connection connection = null;
    try {/*from   w  w w. j  a  v  a2 s .  c o m*/
        connection = connectionProvider.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery);
        if (queryTimeoutSecs > 0) {
            preparedStatement.setQueryTimeout(queryTimeoutSecs);
        }
        setPreparedStatementParams(preparedStatement, queryParams);
        ResultSet resultSet = preparedStatement.executeQuery();
        List<List<Column>> rows = Lists.newArrayList();
        while (resultSet.next()) {
            ResultSetMetaData metaData = resultSet.getMetaData();
            int columnCount = metaData.getColumnCount();
            List<Column> row = Lists.newArrayList();
            for (int i = 1; i <= columnCount; i++) {
                String columnLabel = metaData.getColumnLabel(i);
                int columnType = metaData.getColumnType(i);
                Class columnJavaType = Util.getJavaType(columnType);
                if (columnJavaType.equals(String.class)) {
                    row.add(new Column<String>(columnLabel, resultSet.getString(columnLabel), columnType));
                } else if (columnJavaType.equals(Integer.class)) {
                    row.add(new Column<Integer>(columnLabel, resultSet.getInt(columnLabel), columnType));
                } else if (columnJavaType.equals(Double.class)) {
                    row.add(new Column<Double>(columnLabel, resultSet.getDouble(columnLabel), columnType));
                } else if (columnJavaType.equals(Float.class)) {
                    row.add(new Column<Float>(columnLabel, resultSet.getFloat(columnLabel), columnType));
                } else if (columnJavaType.equals(Short.class)) {
                    row.add(new Column<Short>(columnLabel, resultSet.getShort(columnLabel), columnType));
                } else if (columnJavaType.equals(Boolean.class)) {
                    row.add(new Column<Boolean>(columnLabel, resultSet.getBoolean(columnLabel), columnType));
                } else if (columnJavaType.equals(byte[].class)) {
                    row.add(new Column<byte[]>(columnLabel, resultSet.getBytes(columnLabel), columnType));
                } else if (columnJavaType.equals(Long.class)) {
                    row.add(new Column<Long>(columnLabel, resultSet.getLong(columnLabel), columnType));
                } else if (columnJavaType.equals(Date.class)) {
                    row.add(new Column<Date>(columnLabel, resultSet.getDate(columnLabel), columnType));
                } else if (columnJavaType.equals(Time.class)) {
                    row.add(new Column<Time>(columnLabel, resultSet.getTime(columnLabel), columnType));
                } else if (columnJavaType.equals(Timestamp.class)) {
                    row.add(new Column<Timestamp>(columnLabel, resultSet.getTimestamp(columnLabel),
                            columnType));
                } else {
                    throw new RuntimeException(
                            "type =  " + columnType + " for column " + columnLabel + " not supported.");
                }
            }
            rows.add(row);
        }
        return rows;
    } catch (SQLException e) {
        throw new RuntimeException("Failed to execute select query " + sqlQuery, e);
    } finally {
        closeConnection(connection);
    }
}

From source file:de.erdesignerng.dialect.JDBCReverseEngineeringStrategy.java

protected void reverseEngineerIndexes(Model aModel, TableEntry aTableEntry, DatabaseMetaData aMetaData,
        Table aTable, ReverseEngineeringNotifier aNotifier) throws SQLException, ReverseEngineeringException {

    ResultSet theIndexResults = aMetaData.getIndexInfo(aTableEntry.getCatalogName(),
            aTableEntry.getSchemaName(), aTableEntry.getTableName(), false, true);
    Index theIndex = null;//from w ww .  j a v  a2s.com

    while (theIndexResults.next()) {

        String theIndexName = convertIndexNameFor(aTable, theIndexResults.getString("INDEX_NAME"));

        if ((theIndexName != null)
                && ((theIndex == null) || (!theIndex.getOriginalName().equals(theIndexName)))) {

            String theNewIndexName = dialect.getCastType().cast(theIndexName);

            if (aTable.getIndexes().findByName(theNewIndexName) == null) {
                theIndex = new Index();
                theIndex.setName(theNewIndexName);
                theIndex.setOriginalName(theIndexName);

                boolean isNonUnique = theIndexResults.getBoolean("NON_UNIQUE");
                if (isNonUnique) {
                    theIndex.setIndexType(IndexType.NONUNIQUE);
                } else {
                    theIndex.setIndexType(IndexType.UNIQUE);
                }

                aNotifier.notifyMessage(ERDesignerBundle.ENGINEERINGINDEX, theIndex.getName());

                try {
                    aTable.addIndex(aModel, theIndex);
                } catch (ElementAlreadyExistsException | ElementInvalidNameException e) {
                    throw new ReverseEngineeringException("Cannot add index " + theIndexName + " in table "
                            + aTable.getName() + " : " + e.getMessage(), e);
                }
            } else {
                theIndex = null;
            }
        }

        if (theIndex != null) {
            short aPosition = theIndexResults.getShort("ORDINAL_POSITION");

            String theColumnName = theIndexResults.getString("COLUMN_NAME");
            String theASCorDESC = theIndexResults.getString("ASC_OR_DESC");

            reverseEngineerIndexAttribute(aMetaData, aTableEntry, aTable, aNotifier, theIndex, theColumnName,
                    aPosition, theASCorDESC);
        }
    }

    theIndexResults.close();

    // Remove duplicate unique indexes
    Index thePrimaryKey = aTable.getPrimarykey();
    if (thePrimaryKey != null) {
        Set<Index> theDuplicateIndexes = new HashSet<>();
        for (Index theInd : aTable.getIndexes()) {
            if ((theInd.getIndexType() == IndexType.UNIQUE)
                    && (thePrimaryKey.getExpressions().containsAllExpressions(theInd.getExpressions()))) {
                theDuplicateIndexes.add(theInd);
            }
        }

        aTable.getIndexes().removeAll(theDuplicateIndexes);
    }
}