Search in sources :

Example 1 with DatabaseAccessException

use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.

the class RoleElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    int Role_id = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID);
    if (roles.contains(Role_id))
        return;
    roles.add(Role_id);
    X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null);
    AttributesImpl atts = new AttributesImpl();
    createRoleBinding(atts, m_Role);
    document.startElement("", "", "role", atts);
    // Process org access
    String sql = "SELECT * FROM AD_Role_OrgAccess WHERE AD_Role_ID= " + Role_id;
    PreparedStatement pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createOrgAccess(ctx, document, rs.getInt("AD_Org_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Role_OrgAccess", e);
        throw new DatabaseAccessException("Failed to export organization role access.");
    }
    // Process user assignment access
    sql = "SELECT * FROM AD_User_Roles WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createUserRole(ctx, document, rs.getInt("AD_User_ID"), rs.getInt("AD_Role_ID"), rs.getInt("AD_Org_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_User_Roles", e);
        throw new DatabaseAccessException("Failed to export user role assignment.");
    }
    // Process AD_Window_Access Values
    sql = "SELECT * FROM AD_Window_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createWindowAccess(ctx, document, rs.getInt("AD_Window_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Window_Access", e);
        throw new DatabaseAccessException("Failed to export window access.");
    }
    // Process AD_Process_Access Values
    sql = "SELECT * FROM AD_Process_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createProcessAccess(ctx, document, rs.getInt("AD_Process_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Process_Access", e);
        throw new DatabaseAccessException("Failed to export process access.");
    }
    // Process AD_Form_Access Values
    sql = "SELECT * FROM AD_Form_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createFormAccess(ctx, document, rs.getInt("AD_Form_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Form_Access", e);
        throw new DatabaseAccessException("Failed to export form access.");
    }
    // Process AD_Browse_Access
    String whereClause = I_AD_Browse_Access.COLUMNNAME_AD_Role_ID + "=?";
    List<X_AD_Browse_Access> browseaccess = new Query(ctx, I_AD_Browse_Access.Table_Name, whereClause, getTrxName(ctx)).setParameters(Role_id).list();
    for (X_AD_Browse_Access ba : browseaccess) {
        createBrowseAccess(ctx, document, ba.getAD_Browse_ID(), ba.getAD_Role_ID());
    }
    // Process AD_Workflow_Access Values
    sql = "SELECT * FROM AD_Workflow_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createWorkflowAccess(ctx, document, rs.getInt("AD_Workflow_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Workflow_Access", e);
        throw new DatabaseAccessException("Failed to export workflow access.");
    }
    // Process AD_Task_Access Values
    sql = "SELECT * FROM AD_Task_Access WHERE AD_Role_ID= " + Role_id;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createTaskAccess(ctx, document, rs.getInt("AD_Task_ID"), rs.getInt("AD_Role_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_Task_Access", e);
        throw new DatabaseAccessException("Failed to export task access.");
    } finally {
        try {
            if (pstmt != null)
                pstmt.close();
        } catch (Exception e) {
        }
        pstmt = null;
    }
    document.endElement("", "", "role");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Query(org.compiere.model.Query) X_AD_Browse_Access(org.adempiere.model.X_AD_Browse_Access) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) X_AD_Role(org.compiere.model.X_AD_Role) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) SAXException(org.xml.sax.SAXException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException)

Example 2 with DatabaseAccessException

use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.

the class WorkflowElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    int AD_Workflow_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID);
    if (workflows.contains(AD_Workflow_ID))
        return;
    workflows.add(AD_Workflow_ID);
    String sql = "SELECT Name FROM AD_Workflow WHERE  AD_Workflow_ID= " + AD_Workflow_ID;
    int ad_wf_nodenext_id = 0;
    int ad_wf_nodenextcondition_id = 0;
    AttributesImpl atts = new AttributesImpl();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        rs = pstmt.executeQuery();
        while (rs.next()) {
            X_AD_Workflow m_Workflow = new X_AD_Workflow(ctx, AD_Workflow_ID, null);
            createWorkflowBinding(atts, m_Workflow);
            document.startElement("", "", "workflow", atts);
            String sql1 = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID = " + AD_Workflow_ID + " ORDER BY " + X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID;
            PreparedStatement pstmt1 = null;
            ResultSet rs1 = null;
            try {
                pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
                // Generated workflowNodeNext(s) and
                // workflowNodeNextCondition(s)
                rs1 = pstmt1.executeQuery();
                while (rs1.next()) {
                    int nodeId = rs1.getInt("AD_WF_Node_ID");
                    createNode(ctx, document, nodeId);
                    ad_wf_nodenext_id = 0;
                    String sqlnn = "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID = ?" + " ORDER BY " + X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID;
                    PreparedStatement pstmtnn = null;
                    ResultSet rsnn = null;
                    try {
                        pstmtnn = DB.prepareStatement(sqlnn, getTrxName(ctx));
                        pstmtnn.setInt(1, nodeId);
                        rsnn = pstmtnn.executeQuery();
                        while (rsnn.next()) {
                            ad_wf_nodenext_id = rsnn.getInt("AD_WF_NodeNext_ID");
                            if (ad_wf_nodenext_id > 0) {
                                createNodeNext(ctx, document, ad_wf_nodenext_id);
                                ad_wf_nodenextcondition_id = 0;
                                String sqlnnc = "SELECT AD_WF_NextCondition_ID FROM AD_WF_NextCondition WHERE AD_WF_NodeNext_ID = ?" + " ORDER BY " + X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID;
                                PreparedStatement pstmtnnc = null;
                                ResultSet rsnnc = null;
                                try {
                                    pstmtnnc = DB.prepareStatement(sqlnnc, getTrxName(ctx));
                                    pstmtnnc.setInt(1, ad_wf_nodenext_id);
                                    rsnnc = pstmtnnc.executeQuery();
                                    while (rsnnc.next()) {
                                        ad_wf_nodenextcondition_id = rsnnc.getInt("AD_WF_NextCondition_ID");
                                        log.info("ad_wf_nodenextcondition_id: " + String.valueOf(ad_wf_nodenextcondition_id));
                                        if (ad_wf_nodenextcondition_id > 0) {
                                            createNodeNextCondition(ctx, document, ad_wf_nodenextcondition_id);
                                        }
                                    }
                                } finally {
                                    DB.close(rsnnc, pstmtnnc);
                                    rsnnc = null;
                                    pstmtnnc = null;
                                }
                            }
                        }
                    } finally {
                        DB.close(rsnn, pstmtnn);
                        rsnn = null;
                        pstmtnn = null;
                    }
                }
            } finally {
                DB.close(rs1, pstmt1);
                rs1 = null;
                pstmt1 = null;
                document.endElement("", "", "workflow");
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Workflow", e);
        if (e instanceof SAXException)
            throw (SAXException) e;
        else if (e instanceof SQLException)
            throw new DatabaseAccessException("Failed to export workflow.", e);
        else
            throw new RuntimeException("Failed to export workflow.", e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
}
Also used : X_AD_Workflow(org.compiere.model.X_AD_Workflow) AttributesImpl(org.xml.sax.helpers.AttributesImpl) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) SAXException(org.xml.sax.SAXException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) SAXException(org.xml.sax.SAXException)

Example 3 with DatabaseAccessException

use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.

the class WindowElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    int AD_Window_ID = Env.getContextAsInt(ctx, "AD_Window_ID");
    PackOut packOut = (PackOut) ctx.get("PackOutProcess");
    X_AD_Window m_Window = new X_AD_Window(ctx, AD_Window_ID, null);
    AttributesImpl atts = new AttributesImpl();
    createWindowBinding(atts, m_Window);
    document.startElement("", "", "window", atts);
    // Tab Tag
    String sql = "SELECT * FROM AD_TAB WHERE AD_WINDOW_ID = " + AD_Window_ID + " ORDER BY " + X_AD_Tab.COLUMNNAME_SeqNo + "," + X_AD_Tab.COLUMNNAME_AD_Tab_ID;
    PreparedStatement pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            packOut.createTable(rs.getInt("AD_Table_ID"), document);
            createTab(ctx, document, rs.getInt("AD_Tab_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        if (e instanceof SAXException)
            throw (SAXException) e;
        else if (e instanceof SQLException)
            throw new DatabaseAccessException("Failed to export window.", e);
        else if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException("Failed to export window.", e);
    } finally {
        try {
            if (pstmt != null)
                pstmt.close();
        } catch (Exception e) {
        }
        pstmt = null;
    }
    //TODO: export of ad_image and ad_color use
    // Loop tags.
    document.endElement("", "", "window");
    // Preference Tag
    sql = "SELECT * FROM AD_PREFERENCE WHERE AD_WINDOW_ID = " + AD_Window_ID + " ORDER BY " + X_AD_Preference.COLUMNNAME_AD_Preference_ID;
    pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            createPreference(ctx, document, rs.getInt("AD_Preference_ID"));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        if (e instanceof SAXException)
            throw (SAXException) e;
        else if (e instanceof SQLException)
            throw new DatabaseAccessException("Failed to export window preference.", e);
        else if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException("Failed to export window preference.", e);
    } finally {
        try {
            if (pstmt != null)
                pstmt.close();
        } catch (Exception e) {
        }
        pstmt = null;
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) SQLException(java.sql.SQLException) PackOut(org.adempiere.pipo.PackOut) ResultSet(java.sql.ResultSet) X_AD_Window(org.compiere.model.X_AD_Window) PreparedStatement(java.sql.PreparedStatement) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) SQLException(java.sql.SQLException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) SAXException(org.xml.sax.SAXException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) SAXException(org.xml.sax.SAXException)

Example 4 with DatabaseAccessException

use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.

the class ReportViewElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    PackOut packOut = (PackOut) ctx.get("PackOutProcess");
    int AD_ReportView_ID = Env.getContextAsInt(ctx, "AD_ReportView_ID");
    if (views.contains(AD_ReportView_ID))
        return;
    views.add(AD_ReportView_ID);
    String sql = "SELECT * FROM AD_ReportView WHERE AD_ReportView_ID= " + AD_ReportView_ID;
    PreparedStatement pstmt = null;
    pstmt = DB.prepareStatement(sql, getTrxName(ctx));
    AttributesImpl atts = new AttributesImpl();
    try {
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            X_AD_ReportView m_Reportview = new X_AD_ReportView(ctx, rs.getInt("AD_Reportview_ID"), null);
            atts = createReportViewBinding(atts, m_Reportview);
            document.startElement("", "", "reportview", atts);
            document.endElement("", "", "reportview");
            String sql1 = "SELECT * FROM AD_Printformat WHERE AD_Reportview_ID=" + AD_ReportView_ID + " AND AD_Client_ID=" + Env.getAD_Client_ID(ctx) + " ORDER BY " + X_AD_PrintFormat.COLUMNNAME_AD_PrintFormat_ID;
            PreparedStatement pstmt1 = null;
            pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
            try {
                ResultSet rs1 = pstmt1.executeQuery();
                while (rs1.next()) {
                    // Export Table if neccessary
                    packOut.createTable(rs1.getInt("AD_Table_ID"), document);
                    packOut.createPrintFormat(rs1.getInt("AD_Printformat_ID"), document);
                }
                rs1.close();
                pstmt1.close();
                pstmt1 = null;
            } finally {
                try {
                    if (pstmt1 != null)
                        pstmt1.close();
                } catch (Exception e) {
                }
                pstmt1 = null;
            }
            atts.clear();
            sql1 = "SELECT * FROM AD_ReportView_Col WHERE AD_Reportview_ID= " + AD_ReportView_ID;
            pstmt1 = null;
            pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
            try {
                ResultSet rs1 = pstmt1.executeQuery();
                while (rs1.next()) {
                    createReportViewCol(ctx, document, rs1.getInt("AD_ReportView_Col_ID"));
                }
                rs1.close();
                pstmt1.close();
                pstmt1 = null;
            } finally {
                try {
                    if (pstmt1 != null)
                        pstmt1.close();
                } catch (Exception e) {
                }
                pstmt1 = null;
            }
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, "reportview", e);
        if (e instanceof SAXException)
            throw (SAXException) e;
        else if (e instanceof SQLException)
            throw new DatabaseAccessException("Failed to export report view.", e);
        else if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException("Failed to export report view.", e);
    } finally {
        try {
            if (pstmt != null)
                pstmt.close();
        } catch (Exception e) {
        }
        pstmt = null;
    }
}
Also used : X_AD_ReportView(org.compiere.model.X_AD_ReportView) AttributesImpl(org.xml.sax.helpers.AttributesImpl) SQLException(java.sql.SQLException) PackOut(org.adempiere.pipo.PackOut) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) SQLException(java.sql.SQLException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) SAXException(org.xml.sax.SAXException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) SAXException(org.xml.sax.SAXException)

Example 5 with DatabaseAccessException

use of org.adempiere.pipo.exception.DatabaseAccessException in project adempiere by adempiere.

the class TabElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    PackOut packOut = (PackOut) ctx.get("PackOutProcess");
    int AD_Tab_ID = Env.getContextAsInt(ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID);
    X_AD_Tab m_Tab = new X_AD_Tab(ctx, AD_Tab_ID, getTrxName(ctx));
    AttributesImpl atts = new AttributesImpl();
    createTabBinding(atts, m_Tab);
    document.startElement("", "", "tab", atts);
    //Fields tags.
    String sql = "SELECT * FROM AD_FIELD WHERE AD_TAB_ID = " + AD_Tab_ID + "ORDER BY SEQNO asc, " + X_AD_Field.COLUMNNAME_AD_Field_ID;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, getTrxName(ctx));
        rs = pstmt.executeQuery();
        while (rs.next()) {
            createField(ctx, document, rs.getInt("AD_Field_ID"));
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        throw new DatabaseAccessException("Failed to export window tab", e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    document.endElement("", "", "tab");
    if (m_Tab.getAD_Process_ID() > 0) {
        packOut.createProcess(m_Tab.getAD_Process_ID(), document);
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) PackOut(org.adempiere.pipo.PackOut) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) X_AD_Tab(org.compiere.model.X_AD_Tab) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException) SAXException(org.xml.sax.SAXException) DatabaseAccessException(org.adempiere.pipo.exception.DatabaseAccessException)

Aggregations

DatabaseAccessException (org.adempiere.pipo.exception.DatabaseAccessException)14 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)10 PreparedStatement (java.sql.PreparedStatement)9 ResultSet (java.sql.ResultSet)9 SAXException (org.xml.sax.SAXException)9 AttributesImpl (org.xml.sax.helpers.AttributesImpl)9 SQLException (java.sql.SQLException)6 PackOut (org.adempiere.pipo.PackOut)5 Attributes (org.xml.sax.Attributes)5 BigDecimal (java.math.BigDecimal)1 X_AD_Browse_Access (org.adempiere.model.X_AD_Browse_Access)1 PackIn (org.adempiere.pipo.PackIn)1 MColumn (org.compiere.model.MColumn)1 MTable (org.compiere.model.MTable)1 Query (org.compiere.model.Query)1 X_AD_Element (org.compiere.model.X_AD_Element)1 X_AD_ImpFormat (org.compiere.model.X_AD_ImpFormat)1 X_AD_PrintFormat (org.compiere.model.X_AD_PrintFormat)1 X_AD_Process (org.compiere.model.X_AD_Process)1 X_AD_Reference (org.compiere.model.X_AD_Reference)1