Example usage for org.apache.commons.dbutils.handlers ArrayListHandler ArrayListHandler

List of usage examples for org.apache.commons.dbutils.handlers ArrayListHandler ArrayListHandler

Introduction

In this page you can find the example usage for org.apache.commons.dbutils.handlers ArrayListHandler ArrayListHandler.

Prototype

public ArrayListHandler() 

Source Link

Document

Creates a new instance of ArrayListHandler using a BasicRowProcessor for conversions.

Usage

From source file:org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement.java

public SQLComponent createComponent() {
    return new BaseSQLComponent(this) {
        public void addViews() {
            this.setLayout(new GridBagLayout());
            final GridBagConstraints c = new DefaultGridBagConstraints();
            c.anchor = GridBagConstraints.NORTHWEST;
            c.gridwidth = 4;//from   ww  w  .j a  v  a  2 s.  co  m
            c.gridheight = 8;

            vecteurTabAxe = new Vector();

            repartitionsAxe = new Vector();
            repartitionElemsAxe = new Vector();
            postesAxe = new Vector();

            tabAxes = new JTabbedPane();

            /***********************************************************************************
             * * CREATION DES ONGLETS
             **********************************************************************************/

            // on recupere les axes existant
            // SELECT ID, NOM FROM AXE
            SQLBase base = getTable().getBase();
            SQLSelect sel = new SQLSelect(base);
            sel.addSelect(getTable().getKey());
            sel.addSelect(getTable().getField("NOM"));
            sel.addRawOrder("AXE_ANALYTIQUE.NOM");
            String req = sel.asString();

            Object ob = getTable().getBase().getDataSource().execute(req, new ArrayListHandler());

            List myList = (List) ob;
            if (myList.size() != 0) {

                // on cre les onglets et on stocke les axes
                for (int i = 0; i < myList.size(); i++) {

                    // ID, nom
                    Object[] objTmp = (Object[]) myList.get(i);

                    axes.add(new Axe(Integer.parseInt(objTmp[0].toString()), objTmp[1].toString()));

                    // on recupere les repartitions et les lements associs  l'axe
                    RepartitionAxeAnalytiquePanel repAxeComp = new RepartitionAxeAnalytiquePanel(
                            ((Axe) axes.get(i)).getId());

                    repartitionsAxe.add(repAxeComp.getRepartitions());
                    repartitionElemsAxe.add(repAxeComp.getRepartitionElems());
                    postesAxe.add(repAxeComp.getPostes());
                    tabAxes.addTab(((Axe) axes.get(i)).getNom(), repAxeComp);

                    vecteurTabAxe.add(i, new String(String.valueOf(i)));
                }

                System.out.println("Size ----> " + axes.size());
            } else {
                ajouterAxe("Nouvel Axe");
            }

            c.fill = GridBagConstraints.BOTH;
            c.weightx = 1;
            c.weighty = 1;
            this.add(tabAxes, c);

            tabAxes.addMouseListener(new MouseAdapter() {

                public void mousePressed(final MouseEvent e) {

                    final int index = tabAxes.indexAtLocation(e.getX(), e.getY());

                    validAxeText();

                    if (e.getClickCount() == 2) {

                        actionModifierAxe(e, index);
                    }

                    if (e.getButton() == MouseEvent.BUTTON3) {
                        actionDroitOnglet(index, e);
                    }
                }
            });

            tabAxes.addAncestorListener(new AncestorListener() {

                public void ancestorAdded(AncestorEvent event) {

                    validAxeText();

                }

                public void ancestorRemoved(AncestorEvent event) {

                    validAxeText();

                }

                public void ancestorMoved(AncestorEvent event) {

                    validAxeText();

                }
            });

            /***********************************************************************************
             * * AJOUT D'UN AXE
             **********************************************************************************/
            JButton boutonAddAxe = new JButton("Ajouter un axe");
            boutonAddAxe.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {

                    if (ajoutAxeFrame == null) {
                        ajoutAxeFrame = new AjouterAxeAnalytiqueFrame(a);
                    }
                    ajoutAxeFrame.pack();
                    ajoutAxeFrame.setVisible(true);
                }
            });

            c.gridx += 4;
            c.gridwidth = 1;
            c.gridheight = 1;
            c.weightx = 0;
            c.weighty = 0;
            c.fill = GridBagConstraints.HORIZONTAL;
            this.add(boutonAddAxe, c);

            /***********************************************************************************
             * * SUPPRESSION D'UN AXE
             **********************************************************************************/
            JButton boutonDelAxe = new JButton("Supprimer un axe");
            boutonDelAxe.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {

                    supprimerAxe(Integer.parseInt(vecteurTabAxe.get(tabAxes.getSelectedIndex()).toString()));

                }
            });

            c.gridy++;
            this.add(boutonDelAxe, c);

            JButton boutonSet = new JButton("SetVal");
            boutonSet.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {
                    setVal();
                }
            });

            c.gridy++;
            this.add(boutonSet, c);

            JButton boutonCheck = new JButton("Check");
            boutonCheck.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {
                    checkID();
                }
            });

            c.gridy++;
            this.add(boutonCheck, c);
        }
    };
}

From source file:org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement.java

/**
 * Supprimer un onglet/*from  w w  w. j a v  a 2 s. c om*/
 * 
 * @param axeSelect : numero de l'axe
 */
private void supprimerAxe(int axeSelect) {

    // int axeSelect =
    // Integer.parseInt(this.vecteurTabAxe.get(this.tabAxes.getSelectedIndex()).toString());

    // Test si l'axe contient une repartition deja associe  un compte
    // SELECT ID, ID_COMPTE FROM ASSOCIATION WHERE ID.AXE = id
    SQLTable assocTable = getTable().getBase().getTable("ASSOCIATION_COMPTE_ANALYTIQUE");

    SQLBase base = getTable().getBase();
    SQLSelect selAssoc = new SQLSelect(base);
    selAssoc.addSelect(assocTable.getField("ID"));
    selAssoc.addSelect(assocTable.getField("ID_COMPTE_PCE"));
    selAssoc.setWhere(assocTable.getField("ID_AXE_ANALYTIQUE"), "=", ((Axe) this.axes.get(axeSelect)).getId());

    String reqAssoc = selAssoc.asString();
    Object obAssoc = getTable().getBase().getDataSource().execute(reqAssoc, new ArrayListHandler());

    List myListAssoc = (List) obAssoc;

    if (myListAssoc.size() != 0) {
        System.out.println("La rpartition est affecte  un compte.");
        ValiderSuppressionAxeFrame validFrame = new ValiderSuppressionAxeFrame(this.a, axeSelect);

        validFrame.pack();
        validFrame.setVisible(true);

    } else {
        deleteAxe(axeSelect);
    }
}

From source file:org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement.java

private void supprimerRepartitionTable(Repartition rep) {

    SQLRowValues vals = new SQLRowValues(getTable().getBase().getTable("REPARTITION_ANALYTIQUE"));
    vals.put(getTable().getBase().getTable("REPARTITION_ANALYTIQUE").getArchiveField().getName(),
            new Integer(1));

    // Test si la repartition n'est pas deja associe  un compte
    // SELECT ID, ID_COMPTE FROM ASSOCIATION WHERE ID.REP = id
    SQLTable assocTable = getTable().getBase().getTable("ASSOCIATION_COMPTE_ANALYTIQUE");
    SQLBase base = assocTable.getBase();
    SQLSelect selAssoc = new SQLSelect(base);
    selAssoc.addSelect(assocTable.getField("ID"));
    selAssoc.addSelect(assocTable.getField("ID_COMPTE_PCE"));
    selAssoc.setWhere(assocTable.getField("ID_REPARTITION_ANALYTIQUE"), "=", rep.getId());

    String reqAssoc = selAssoc.asString();
    Object obAssoc = getTable().getBase().getDataSource().execute(reqAssoc, new ArrayListHandler());

    List myListAssoc = (List) obAssoc;

    if (myListAssoc.size() != 0) {
        SQLRowValues valsAssoc = new SQLRowValues(
                getTable().getBase().getTable("ASSOCIATION_COMPTE_ANALYTIQUE"));
        valsAssoc.put("ARCHIVE", 1);
        try {/*from  w w  w  . ja  v  a2  s. c o  m*/

            for (int i = 0; i < myListAssoc.size(); i++) {
                Object[] objTmp = (Object[]) myListAssoc.get(i);
                valsAssoc.update(Integer.parseInt(objTmp[0].toString()));
            }

        } catch (SQLException e) {
            System.err.println("Erreur suppression association ");
            e.printStackTrace();
        }
    }

    try {
        vals.update(rep.getId());
    } catch (SQLException e) {
        System.err.println("Erreur suppression Repartition " + rep.getId());
        e.printStackTrace();
    }

    System.out.println("Rep Supprime  -->" + rep.toString());
}

From source file:org.openconcerto.erp.core.finance.accounting.element.AssociationCompteAnalytiqueSQLElement.java

public SQLComponent createComponent() {
    return new BaseSQLComponent(this) {
        public void addViews() {
            this.setLayout(new GridBagLayout());

            final GridBagConstraints c = new DefaultGridBagConstraints();
            c.weightx = 1;//from   w  w  w .  j av  a  2  s  . c  o m
            c.weighty = 1;
            c.fill = GridBagConstraints.BOTH;

            final List<ClasseCompte> classeComptes = new ArrayList<ClasseCompte>();
            tabbedClasse = new JTabbedPane();

            final SQLTable classeCompteTable = getTable().getBase().getTable("CLASSE_COMPTE");
            final SQLSelect selClasse = new SQLSelect();
            selClasse.addSelect(classeCompteTable.getField("ID"));
            selClasse.addSelect(classeCompteTable.getField("NOM"));
            selClasse.addSelect(classeCompteTable.getField("TYPE_NUMERO_COMPTE"));
            selClasse.addRawOrder("TYPE_NUMERO_COMPTE");

            String reqClasse = selClasse.asString();
            Object obClasse = getTable().getBase().getDataSource().execute(reqClasse, new ArrayListHandler());

            List<Object[]> myListClasse = (List<Object[]>) obClasse;
            for (Object[] objTmp : myListClasse) {
                ClasseCompte ccTmp = new ClasseCompte(Integer.parseInt(objTmp[0].toString()),
                        objTmp[1].toString(), objTmp[2].toString());
                classeComptes.add(ccTmp);
                tabbedClasse.add(ccTmp.getNom(), new JScrollPane(creerJTable(ccTmp)));
            }

            this.add(tabbedClasse, c);

            final SQLTableModifiedListener tListener = new SQLTableModifiedListener() {

                @Override
                public void tableModified(SQLTableEvent evt) {
                    final int tabCount = tabbedClasse.getTabCount();
                    for (int i = 0; i < tabCount; i++) {
                        tabbedClasse.setComponentAt(i, new JScrollPane(creerJTable(classeComptes.get(i))));
                    }

                }
            };

            final SQLTable tAxeAnalytique = getElement().getDirectory()
                    .getElement(AxeAnalytiqueSQLElement.class).getTable();
            tAxeAnalytique.addTableModifiedListener(tListener);

            final SQLTable tRepartitionAnalytique = getElement().getDirectory()
                    .getElement(RepartitionAnalytiqueSQLElement.class).getTable();
            tRepartitionAnalytique.addTableModifiedListener(tListener);

            final SQLTable tRepartitionAnalytiqueElement = getElement().getDirectory()
                    .getElement(RepartitionAnalytiqueElementSQLElement.class).getTable();
            tRepartitionAnalytiqueElement.addTableModifiedListener(tListener);

            final SQLTable tComptePCE = getElement().getDirectory().getElement(ComptePCESQLElement.class)
                    .getTable();
            tComptePCE.addTableModifiedListener(tListener);

        }
    };

}

From source file:org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement.java

@Override
protected void archive(SQLRow row, boolean cutLinks) throws SQLException {
    // on verifie qu'aucune ecriture n'est asssocie  ce compte
    SQLBase base = getTable().getBase();
    SQLTable ecritureTable = base.getTable("ECRITURE");
    SQLSelect selEcr = new SQLSelect(base);
    selEcr.addSelect(ecritureTable.getField("ID_COMPTE_PCE"));
    selEcr.setWhere(new Where(ecritureTable.getField("ID_COMPTE_PCE"), "=", row.getID()));

    String reqEcriture = selEcr.asString();

    Object obEcriture = base.getDataSource().execute(reqEcriture, new ArrayListHandler());

    List myListEcriture = (List) obEcriture;

    if (myListEcriture.size() != 0) {

        System.err.println("Impossible de supprimer un compte mouvement!");
        ExceptionHandler.handle("", new Exception("Impossible de supprimer un compte mouvement!"));
    } else {/*from w w w.  java 2 s . com*/
        super.archive(row, cutLinks);
    }
}

From source file:org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement.java

/**
 * Valider l'ensemble des mouvements forms par le sous arbre de du mouvement d'id idMvtPere
 * /*from  w w  w. j av  a  2  s .  c o  m*/
 * @param idMvtPere
 */
private static void validerMouvementProfondeur(int idMvtPere) {
    SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
    SQLTable tableMvt = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete()
            .getTable("MOUVEMENT");

    SQLSelect selectFils = new SQLSelect();
    selectFils.addSelect(tableMvt.getField("ID"));
    selectFils.setWhere(tableMvt.getField("ID_MOUVEMENT_PERE"), "=", idMvtPere);

    List l = (List) base.getDataSource().execute(selectFils.asString(), new ArrayListHandler());

    // valide mouvements fils
    for (int i = 0; i < l.size(); i++) {
        Object[] tmp = (Object[]) l.get(i);
        validerMouvementProfondeur(Integer.parseInt(tmp[0].toString()));
    }

    // valide mouvement
    validationEcritures(idMvtPere);
}

From source file:org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement.java

/**
 * Valide l'ensemble des ecritures du mouvement
 * /*from  www . j a  va 2 s  .c o  m*/
 * @param idMvt Id du mouvement  valider
 */
public static final void validationEcritures(int idMvt) {
    SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
    SQLTable tableEcriture = base.getTable("ECRITURE");

    SQLSelect selEcriture = new SQLSelect(base);
    selEcriture.addSelect(tableEcriture.getField("ID"));

    Where w = new Where(tableEcriture.getField("ID_MOUVEMENT"), "=", idMvt);

    selEcriture.setWhere(w);

    String reqEcriture = selEcriture.asString();

    Object obEcriture = base.getDataSource().execute(reqEcriture, new ArrayListHandler());

    List myListEcriture = (List) obEcriture;

    if (myListEcriture.size() != 0) {

        for (int i = 0; i < myListEcriture.size(); i++) {
            Object[] objTmp = (Object[]) myListEcriture.get(i);
            valideEcriture(Integer.parseInt(objTmp[0].toString()));
        }
    }
}

From source file:org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement.java

/**
 * Validation des ecritures avant la date d
 * // w  w  w  .  j  a va 2 s .  c o m
 * @param d date
 * @param cloture
 */
public static final void validationEcrituresBefore(Date d, boolean cloture) {

    SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
    SQLTable tableEcriture = base.getTable("ECRITURE");

    // on recupere l'ensemble des mouvements  valider
    SQLSelect selEcriture = new SQLSelect(base);
    selEcriture.addSelect(tableEcriture.getField("ID_MOUVEMENT"));
    selEcriture.setDistinct(true);
    Where w1 = new Where(tableEcriture.getField("DATE"), "<=", d);
    Where w2 = new Where(tableEcriture.getField("VALIDE"), "=", Boolean.FALSE);
    selEcriture.setWhere(w1.and(w2));
    List l = (List) base.getDataSource().execute(selEcriture.asString(), new ArrayListHandler());

    // validation de tous les mouvements
    for (int i = 0; i < l.size(); i++) {
        Object[] tmp = (Object[]) l.get(i);
        System.err.println("Validation du mouvement " + tmp[0]);
        validationEcritures(Integer.parseInt(tmp[0].toString()));
    }

    if (cloture) {

        SQLTable tableExercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON");

        SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
        SQLRow rowExercice = tableExercice.getRow(rowSociete.getInt("ID_EXERCICE_COMMON"));
        Date dateCloture = (Date) rowExercice.getObject("DATE_CLOTURE");

        if (dateCloture == null || dateCloture.before(d)) {

            SQLRowValues rowVals = new SQLRowValues(tableExercice);
            rowVals.put("DATE_CLOTURE", new java.sql.Date(d.getTime()));
            try {
                rowVals.update(rowExercice.getID());
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement.java

/**
 * Archivage de l'ensemble des oprations lis au mouvement pass en parametre
 * //from   w w w. ja va  2 s.c  o m
 * @param idMvtPere mouvement racine
 * @param dropPere suppression du mouvement pere
 */
public void archiveMouvementProfondeur(int idMvtPere, boolean dropPere) {
    if (idMvtPere > 1) {
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
        SQLTable tableMvt = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete()
                .getTable("MOUVEMENT");

        SQLSelect selectFils = new SQLSelect();
        selectFils.addSelect(tableMvt.getField("ID"));
        selectFils.setWhere(tableMvt.getField("ID_MOUVEMENT_PERE"), "=", idMvtPere);

        List l = (List) base.getDataSource().execute(selectFils.asString(), new ArrayListHandler());

        // archive mouvements fils
        for (int i = 0; i < l.size(); i++) {
            Object[] tmp = (Object[]) l.get(i);
            archiveMouvementProfondeur(Integer.parseInt(tmp[0].toString()), true);
        }

        // archive mouvement
        archiveEcritures(idMvtPere, dropPere);

    } else {

        System.err.println("Suppression du mouvement d'id 1 impossible.");
        JOptionPane.showMessageDialog(null, "Impossible d'archiver, le mouvement est indfini.");
    }
}

From source file:org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement.java

private synchronized void archiveEcritures(final int idMvt, final boolean dropMvt) {
    final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
    final SQLTable tableMvt = base.getTable("MOUVEMENT");
    final SQLTable tableEcriture = base.getTable("ECRITURE");
    final SQLRow rowMvt = tableMvt.getRow(idMvt);

    // on verifie que le mouvement n'est pas valid
    if (MouvementSQLElement.isEditable(idMvt)) {

        // on archive le mouvement
        if (dropMvt) {
            SQLElement elt = Configuration.getInstance().getDirectory().getElement(tableMvt);
            try {
                elt.archive(idMvt);//from www.  j a  v  a2  s . co  m
            } catch (SQLException e) {
                ExceptionHandler.handle("Erreur lors de la suppression du mouvement d'id [" + idMvt + "]", e);
                e.printStackTrace();
            }
        } else {

            SQLFactory<Object> sqlFactory = new SQLFactory<Object>() {
                @Override
                public Object create() throws SQLException {
                    // on recupere l'ensemble des ecritures associes au mouvement
                    SQLSelect selEcritures = new SQLSelect();
                    selEcritures.addSelect(tableEcriture.getField("ID"));
                    selEcritures.setWhere(tableEcriture.getField("ID_MOUVEMENT"), "=", idMvt);

                    List l = (List) base.getDataSource().execute(selEcritures.asString(),
                            new ArrayListHandler());
                    for (int i = 0; i < l.size(); i++) {
                        Object[] tmp = (Object[]) l.get(i);
                        archiveEcriture(tableEcriture.getRow(Integer.parseInt(tmp[0].toString())));
                    }

                    return null;
                }
            };

            try {
                SQLUtils.executeAtomic(base.getDataSource(), sqlFactory);
            } catch (SQLException e) {

                ExceptionHandler.handle("Une erreur est survenue lors de la suppression des critures.", e);
            }
        }

    } else {
        ExceptionHandler.handle(
                "Impossible de supprimer le mouvement n" + rowMvt.getInt("NUMERO") + " car il est valid.");
    }
}