use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class importxml method insertLine.
/**
* cette funtion permet de faire la inyection a la BDD line par line de la table "nomtable"
* et le données que ils sont dans une ArrayList
* @param ds
* @param table
* @param nomtable
*/
private void insertLine(Connection con, ArrayList<LineOfData> table, String nomtable) throws ClassNotFoundException, SQLException {
Statement stmt;
String nomcolun = "";
String values = "";
boolean first = true;
for (LineOfData lineOfData : table) {
if (!first) {
nomcolun += ",";
values += ",";
}
nomcolun += lineOfData.getColomne();
values += "'" + lineOfData.getValue() + "'";
first = false;
}
values += ");";
try {
// Connection conn = ds.getConnection();
stmt = con.createStatement();
try {
// récupération des noms des colonnes de la table
String query = "INSERT INTO " + nomtable + " ( " + nomcolun + ") VALUES (" + values;
stmt.executeUpdate(query);
} finally {
stmt.close();
}
} catch (SQLException ex) {
Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class importxml method ouvreFichier2.
/**
* cette funtion permet de ouvrir un fichier pour comencée a faire une
* injection de données.
* Cette funtion c'est la generique
* @param ds
* @param archive
* @throws ClassNotFoundException
* @throws SQLException
*/
public void ouvreFichier2(HikariDataSource ds, File archive) throws ClassNotFoundException, SQLException {
LanguageBean langueBean = new LanguageBean();
SAXBuilder builder = new SAXBuilder();
ArrayList<Table> toutTables = new ArrayList<>();
ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
try {
// on crée le document a partir du fichier que on a selectioné
Document document = (Document) builder.build(archive);
// Se obtiene la raiz 'tables'
Element rootNode = document.getRootElement();
// ici on a toutes les tables (les enfants de la racine)
List list = rootNode.getChildren("table");
// ici on fait le tour pour les enfants de 'tables'
for (int i = 0; i < list.size(); i++) {
// ici on a la première table
Element tabla = (Element) list.get(i);
// ici on a le nom de la table
String nombreTabla = tabla.getAttributeValue("nom");
// ici c'est la liste des lignes de la table
List lista_campos = tabla.getChildren();
// ici on découpe la liste des lignes
for (int j = 0; j < lista_campos.size(); j++) {
// ici on a une ligne de la table
Element campo = (Element) lista_campos.get(j);
for (Element colonne : campo.getChildren()) {
LineOfData lineOfData = new LineOfData();
lineOfData.setColomne(colonne.getName());
lineOfData.setValue(colonne.getText());
lineOfDatas.add(lineOfData);
}
insertLine2(ds, lineOfDatas, nombreTabla);
lineOfDatas.clear();
}
// / mettre à jour la table dans la BDD
}
} catch (IOException | JDOMException io) {
System.out.println(io.toString());
}
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("impBDD.info1")));
}
use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class ExportPrivatesDatas method showAllTables.
/**
* on recupere toutes le tables de la BDD
*
* @param ds
* @return
*/
public ArrayList<String> showAllTables(HikariDataSource ds) {
Connection conn;
Statement stmt;
ResultSet resultSet;
ArrayList<String> tables = new ArrayList<>();
try {
conn = ds.getConnection();
try {
stmt = conn.createStatement();
try {
String query = "SELECT * from Information_Schema.Tables where table_type= 'BASE TABLE' and table_schema ='public'";
resultSet = stmt.executeQuery(query);
while (resultSet.next()) {
tables.add(resultSet.getString("table_name"));
}
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException ex) {
Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
}
return tables;
}
use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class ExportPrivatesDatas method getRoles.
/**
* fonctions pour récupérer toutes données par table pour une utilisation
* future
*/
/**
* Cette fonction permet de récupérer toutes les données de la table R
*
* @param ds
* @return
*/
public ArrayList<Role> getRoles(HikariDataSource ds) {
ArrayList<Role> listRoles = new ArrayList<>();
Connection conn;
Statement stmt;
ResultSet resultSet;
try {
conn = ds.getConnection();
try {
stmt = conn.createStatement();
try {
String query = "SELECT * FROM roles ";
resultSet = stmt.executeQuery(query);
while (resultSet.next()) {
Role role1 = new Role();
/* role1.setId(resultSet.getInt("id"));
role1.setName(resultSet.getString("name"));
role1.setDescription(resultSet.getString("description"));
*/
listRoles.add(role1);
}
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException ex) {
Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
}
return listRoles;
}
use of mom.trd.opentheso.core.exports.privatesdatas.tables.Table in project opentheso by miledrousset.
the class ExportStatistiques method avoirnondescripteur.
/**
* on va a chercher le term que il ne sont pas descripteur
*
* @param ds
* @param document
* @param map
* @return
*/
private String avoirnondescripteur(HikariDataSource ds, String document, HashMap<String, String> map, ArrayList<String> listnonT, ArrayList<Integer> noTraduit, int domaines) {
// ArrayList pour savoir combien de term "nondescripteur" il y a dans chac domaine
ArrayList<Integer> ouviens = new ArrayList<>();
Connection conn = null;
Statement stmt = null;
ResultSet resultset;
// pour avancé dans ouviens et savoir le/les term "nondescripteur"
int ousont = 0;
// pour conté combien ils sont
int combien = 0;
try {
conn = ds.getConnection();
try {
stmt = conn.createStatement();
try {
for (Map.Entry e : map.entrySet()) {
// On cherche "nondescripteur" dans la table permuted avec le id_group, la lange, le theso et la option de ispreferredterm a false
String query = "Select id_concept from permuted where id_group = '" + e.getKey() + "' and id_lang = '" + lange + "' and ispreferredterm= 'false'" + " and id_thesaurus ='" + id_theso + "'";
resultset = stmt.executeQuery(query);
while (resultset.next()) {
combien++;
}
// introduisons combien dans l'ArrayList
ouviens.add(combien);
// reinicialisons le valeur pour le prochaine
combien = 0;
}
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException ex) {
Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
}
int conttateur = 0;
int cont;
changenames(ds, quisontorphan, lange, combien);
for (int h = 0; h < domaines; h++) {
this.document += "\r\n\r\n" + listnonT.get(h) + " " + nondescr + ouviens.get(ousont);
// manque faire le languageBean.getMsg
this.document += "\r\n\t " + termesNonTra + noTraduit.get(ousont);
// donne error le getMsg
this.document += "\r\n\t " + notes;
this.document += "\r\n\t " + ConceptOrphan;
for (cont = conttateur; cont < concept_orphan.get(ousont) + conttateur; cont++) {
this.document += quisontorphan.get(cont) + ", ";
}
conttateur += concept_orphan.get(ousont);
ousont++;
}
return this.document;
}
Aggregations