Search in sources :

Example 1 with XMLSaver

use of com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.XMLSaver in project ACS by ACS-Community.

the class HibernateWDALImpl method set_DAO.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.WDALOperations#set_DAO(java.lang.String, java.lang.String)
	 */
public void set_DAO(String curl, String xml) throws CDBFieldDoesNotExistEx, CDBRecordIsReadOnlyEx, CDBExceptionEx, CDBXMLErrorEx, CDBRecordDoesNotExistEx {
    checkAccess();
    m_logger.log(AcsLogLevel.INFO, "set_DAO: " + curl);
    // read given xml and iterate through its content and check if something was changed
    DAOImpl daoImp = null;
    XMLHandler daoXMLSolver = null;
    // get content of the given xml string using parser without any shemas and validation
    // since given xml string come from a client that have no shemas and it is full expanded version
    // of existing xml or it is small composed xml of few properties
    XMLHandler xmlSolver = new XMLHandler(false, m_logger);
    // TODO markArrays == 2 impl. is a mess... I think lot of code could be removed!
    //xmlSolver.setMarkArrays(2);
    parseXML(xml, xmlSolver);
    Object node = DOMJavaClassIntrospector.getNode(curl, rootNode);
    if (node == null) {
        AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
        ex.setCurl(curl);
        throw ex.toCDBRecordDoesNotExistEx();
    }
    // node is saved as XML
    if (node instanceof XMLSaver) {
        XMLSaver saver = (XMLSaver) node;
        Transaction tr = null;
        try {
            tr = mainSession.beginTransaction();
            saver.save(xml);
            tr.commit();
        } catch (Throwable th) {
            if (tr != null)
                tr.rollback();
            m_logger.log(AcsLogLevel.NOTICE, "Failed to set DAO: " + curl, th);
            AcsJCDBExceptionEx cdbex = new AcsJCDBExceptionEx(th);
            throw cdbex.toCDBExceptionEx();
        }
        return;
    }
    // get original xml that we will use to compare
    xml = get_DAO(curl);
    daoXMLSolver = new XMLHandler(false, m_logger);
    parseXML(xml, daoXMLSolver);
    daoImp = new DAOImpl(curl, daoXMLSolver.m_rootNode, poa, m_logger);
    // iterater throuth given xml and put changed attributes in map
    LinkedHashMap map = new LinkedHashMap();
    try {
        checkforChanges("", xmlSolver.m_rootNode, map, daoImp);
        saveChanges(curl, map);
    } catch (AcsJCDBFieldDoesNotExistEx e) {
        throw e.toCDBFieldDoesNotExistEx();
    } catch (AcsJCDBXMLErrorEx e) {
        throw e.toCDBXMLErrorEx();
    }
}
Also used : AcsJCDBExceptionEx(alma.cdbErrType.wrappers.AcsJCDBExceptionEx) AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx) Transaction(org.hibernate.Transaction) XMLSaver(com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.XMLSaver) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

AcsJCDBExceptionEx (alma.cdbErrType.wrappers.AcsJCDBExceptionEx)1 AcsJCDBFieldDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx)1 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)1 AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)1 XMLSaver (com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.XMLSaver)1 LinkedHashMap (java.util.LinkedHashMap)1 Transaction (org.hibernate.Transaction)1