Example usage for java.sql Statement getResultSet

List of usage examples for java.sql Statement getResultSet

Introduction

In this page you can find the example usage for java.sql Statement getResultSet.

Prototype

ResultSet getResultSet() throws SQLException;

Source Link

Document

Retrieves the current result as a ResultSet object.

Usage

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer la liste des Ids of Topconcepts pour
 * un thsaurus/*w  w w  .ja  va2s  .  c  om*/
 *
 * @param ds
 * @param idThesaurus
 * @return Objet class NodeTT
 */
public ArrayList<NodeTT> getAllListIdsOfTopConcepts(HikariDataSource ds, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeTT> listIdOfTopConcept = new ArrayList<>();

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept," + "id_ark, id_group from concept where id_thesaurus = '"
                        + idThesaurus + "'" + " and top_concept = true";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeTT nodeTT = new NodeTT();
                    nodeTT.setIdConcept(resultSet.getString("id_concept"));
                    nodeTT.setIdArk(resultSet.getString("id_ark"));
                    nodeTT.setIdGroup(resultSet.getString("id_group"));
                    listIdOfTopConcept.add(nodeTT);
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting Ids of TopConcept of thsaurus : " + idThesaurus, sqle);
        listIdOfTopConcept = null;
    }
    return listIdOfTopConcept;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer les identifiants des Group d'un
 * Concept dont il est le fils direct/*from www . j  a v a2s.c  om*/
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @return String idGroup
 */
public ArrayList<String> getListGroupParentIdOfConcept(HikariDataSource ds, String idConcept,
        String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<String> idGroup = new ArrayList<>();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_group from concept where id_thesaurus = '" + idThesaurus + "'"
                        + " and id_concept = '" + idConcept + "'" + " and top_concept=true";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    while (resultSet.next()) {
                        idGroup.add(resultSet.getString("id_group"));
                    }
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting Id of group of Concept : " + idConcept, sqle);
    }
    return idGroup;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de savoir si un concept a des fils ou non suivant
 * l'id du Concept et l'id du thsaurus sous forme de classe Concept (sans
 * les relations)/*  w w  w. jav a 2s . com*/
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @return Objet class NodeConceptTree
 */
public boolean haveChildren(HikariDataSource ds, String idThesaurus, String idConcept) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    boolean children = false;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select count(*)  from hierarchical_relationship" + " where id_thesaurus='"
                        + idThesaurus + "'" + " and id_concept1='" + idConcept + "'" + " and role='NT'";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    resultSet.next();
                    if (resultSet.getInt(1) != 0) {
                        children = true;
                    } else {
                        children = false;
                    }
                    resultSet.close();
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while testing if haveChildren of Concept : " + idConcept, sqle);
    }
    return children;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer la liste des Ids of Topconcepts
 * suivant l'id du groupe et le thsaurus
 *
 * @param ds/* ww w  . jav  a  2  s.c  o  m*/
 * @param idGroup
 * @param idThesaurus
 * @return Objet class NodeConceptTree
 */
public ArrayList<String> getListIdsOfTopConcepts(HikariDataSource ds, String idGroup, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<String> listIdOfTopConcept = new ArrayList<>();

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept from concept where id_thesaurus = '" + idThesaurus + "'"
                        + " and id_group = '" + idGroup + "'" + " and top_concept = true";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    listIdOfTopConcept.add(resultSet.getString("id_concept"));
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting Ids of TopConcept of Group : " + idGroup, sqle);
    }
    return listIdOfTopConcept;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer la liste des Topconcepts suivant l'id
 * du groupe et le thsaurus sous forme de classe NodeConceptTree (sans les
 * relations)//from w ww.  j  a v a2 s  . c o  m
 *
 * @param ds
 * @param idGroup
 * @param idThesaurus
 * @param idLang
 * @return Objet class NodeConceptTree
 */
public ArrayList<NodeConceptTree> getListTopConcepts(HikariDataSource ds, String idGroup, String idThesaurus,
        String idLang) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeConceptTree> nodeConceptTree = null;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept, status from concept where id_thesaurus = '" + idThesaurus
                        + "'" + " and id_group = '" + idGroup + "'" + " and top_concept = true";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    nodeConceptTree = new ArrayList<>();
                    while (resultSet.next()) {
                        NodeConceptTree nodeConceptTree1 = new NodeConceptTree();
                        nodeConceptTree1.setIdConcept(resultSet.getString("id_concept"));
                        nodeConceptTree1.setStatusConcept(resultSet.getString("status"));
                        nodeConceptTree1.setIdThesaurus(idThesaurus);
                        nodeConceptTree1.setIdLang(idLang);
                        nodeConceptTree.add(nodeConceptTree1);
                    }
                }
                for (NodeConceptTree nodeConceptTree1 : nodeConceptTree) {
                    query = "SELECT term.lexical_value FROM term, preferred_term"
                            + " WHERE preferred_term.id_term = term.id_term"
                            + " and preferred_term.id_concept ='" + nodeConceptTree1.getIdConcept() + "'"
                            + " and term.lang = '" + idLang + "'" + " and term.id_thesaurus = '" + idThesaurus
                            + "'";

                    stmt.executeQuery(query);
                    resultSet = stmt.getResultSet();
                    if (resultSet != null) {
                        resultSet.next();
                        if (resultSet.getRow() == 0) {
                            nodeConceptTree1.setTitle("");

                        } else {

                            nodeConceptTree1.setTitle(resultSet.getString("lexical_value"));

                        }
                        nodeConceptTree1.setHaveChildren(
                                haveChildren(ds, idThesaurus, nodeConceptTree1.getIdConcept()));
                    }
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting TopConcept of Group : " + idGroup, sqle);
    }
    Collections.sort(nodeConceptTree);
    return nodeConceptTree;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer les Ids des concepts suivant l'id du
 * Concept-Pre et le thsaurus sous forme de classe tableau
 *
 * @param ds/*from   w  w  w  .j ava2 s.  c o m*/
 * @param idConcept
 * @param idThesaurus
 * @return Objet Array String
 */
public ArrayList<String> getListChildrenOfConcept(HikariDataSource ds, String idConcept, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<String> listIdsOfConcept = new ArrayList<>();

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept2 from hierarchical_relationship" + " where id_thesaurus = '"
                        + idThesaurus + "'" + " and id_concept1 = '" + idConcept + "'" + " and role = '" + "NT"
                        + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    listIdsOfConcept.add(resultSet.getString("id_concept2"));
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List of Id of Concept : " + idConcept, sqle);
    }
    return listIdsOfConcept;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer l'historique d'un concept
 *
 * @param ds/*from  ww w  . ja  va2 s  .  c om*/
 * @param idConcept
 * @param idThesaurus
 * @return String idGroup
 */
public ArrayList<Concept> getConceptHisoriqueAll(HikariDataSource ds, String idConcept, String idThesaurus) {
    ArrayList<Concept> listeConcept = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT modified, status, notation, top_concept, id_group, username from concept_historique, users where id_thesaurus = '"
                        + idThesaurus + "'" + " and id_concept = '" + idConcept + "'"
                        + " and concept_historique.id_user=users.id_user" + " order by modified DESC";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    while (resultSet.next()) {
                        Concept c = new Concept();
                        c.setIdConcept(idConcept);
                        c.setIdThesaurus(idThesaurus);
                        c.setModified(resultSet.getDate("modified"));
                        c.setStatus(resultSet.getString("status"));
                        c.setNotation(resultSet.getString("notation"));
                        c.setTopConcept(resultSet.getBoolean("top_concept"));
                        c.setIdGroup(resultSet.getString("id_group"));
                        c.setUserName(resultSet.getString("username"));
                        listeConcept.add(c);
                    }
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting historique of Concept : " + idConcept, sqle);
    }
    return listeConcept;
}

From source file:com.evolveum.midpoint.testing.sanity.TestSanity.java

License:asdf

/**
 * Delete the shadow which will cause deletion of associated account.
 * The account was unlinked in the previous test, therefore no operation with user is needed.
 *///from  w w w.  j  a v a2  s .c  o  m
@Test
public void test041DeleteDerbyAccount() throws FileNotFoundException, JAXBException, FaultMessage,
        ObjectNotFoundException, SchemaException, DirectoryException, SQLException {
    TestUtil.displayTestTile("test041DeleteDerbyAccount");

    // GIVEN

    assertNoRepoCache();

    // WHEN
    OperationResultType result = deleteObjectViaModelWS(ObjectTypes.SHADOW.getTypeQName(),
            accountShadowOidDerby);

    // THEN
    assertNoRepoCache();
    displayJaxb("deleteObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("deleteObject has failed", result);

    // Check if shadow was deleted
    OperationResult repoResult = new OperationResult("getObject");

    try {
        repositoryService.getObject(ShadowType.class, accountShadowOidDerby, null, repoResult);
        AssertJUnit.fail("Shadow was not deleted");
    } catch (ObjectNotFoundException ex) {
        display("Caught expected exception from getObject(shadow): " + ex);
    }

    // check if account was deleted in DB Table

    Statement stmt = derbyController.getExecutedStatementWhereLoginName(USER_JACK_DERBY_LOGIN);
    ResultSet rs = stmt.getResultSet();

    System.out.println("RS: " + rs);

    assertFalse("Account was not deleted in database", rs.next());

}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

public ArrayList<NodeFusion> getConceptFusion(HikariDataSource ds, String idConcept, String idLang,
        String idThesaurus) {/*from   w  w  w .  j  av a2s .c o m*/
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeFusion> nf = new ArrayList<>();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept1, id_concept2 from concept_fusion where"
                        + " concept_fusion.id_thesaurus = '" + idThesaurus + "'"
                        + " AND (concept_fusion.id_concept1 = '" + idConcept + "'"
                        + " OR concept_fusion.id_concept2 = '" + idConcept + "')";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();

                while (resultSet.next()) {
                    NodeFusion n = new NodeFusion();
                    n.setIdConcept1(resultSet.getString("id_concept1"));
                    n.setIdConcept2(resultSet.getString("id_concept2"));
                    n.setLexicalValue1(getLexicalValueOfConcept(ds, resultSet.getString("id_concept1"),
                            idThesaurus, idLang));
                    n.setLexicalValue2(getLexicalValueOfConcept(ds, resultSet.getString("id_concept2"),
                            idThesaurus, idLang));
                    nf.add(n);
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting fusion of Concept : " + idConcept, sqle);
    }
    return nf;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer l'historique d'un concept  une date
 * prcise//from   w  w w.  j  a va 2 s. c  o m
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @param date
 * @return String idGroup
 */
public ArrayList<Concept> getConceptHisoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus,
        java.util.Date date) {
    ArrayList<Concept> listeConcept = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT modified, status, notation, top_concept, id_group, username from concept_historique, users where id_thesaurus = '"
                        + idThesaurus + "'" + " and id_concept = '" + idConcept + "'"
                        + " and concept_historique.id_user=users.id_user" + " and modified <= '" + date
                        + "' order by modified DESC";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    while (resultSet.next()) {
                        Concept c = new Concept();
                        c.setIdConcept(idConcept);
                        c.setIdThesaurus(idThesaurus);
                        c.setModified(resultSet.getDate("modified"));
                        c.setStatus(resultSet.getString("status"));
                        c.setNotation(resultSet.getString("notation"));
                        c.setTopConcept(resultSet.getBoolean("top_concept"));
                        c.setIdGroup(resultSet.getString("id_group"));
                        c.setUserName(resultSet.getString("username"));
                        listeConcept.add(c);
                    }
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting date historique of Concept : " + idConcept, sqle);
    }
    return listeConcept;
}