Search in sources :

Example 6 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class DOMConfigurationAccessor method getConfiguration.

/* (non-Javadoc)
	 * @see com.cosylab.acs.laser.dao.ConfigurationAccessor#getConfiguration(java.lang.String)
	 */
@Override
public String getConfiguration(String curl) throws Exception {
    Object obj = objectMap.get(curl);
    if (obj == null) {
        AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
        ex.setCurl(curl);
        throw ex.toCDBRecordDoesNotExistEx();
    }
    if (obj instanceof String)
        return (String) obj;
    // get node name only
    String name;
    int pos = curl.lastIndexOf('/');
    if (pos == -1)
        name = curl;
    else
        name = curl.substring(pos + 1, curl.length());
    // root
    if (name.length() == 0)
        name = "root";
    return "<?xml version='1.0' encoding='ISO-8859-1'?>" + DOMJavaClassIntrospector.toXML(DOMJavaClassIntrospector.getNodeXMLName(name, obj), obj);
}
Also used : AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)

Example 7 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class DALRead method main.

public static void main(String[] args) {
    Logger m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("DALRead", false);
    try {
        String curl;
        String strIOR = null;
        boolean rawOutput = false;
        if (args.length < 1) {
            System.out.println("Usage: cmd curl [-d ior -raw -h]");
            return;
        }
        curl = args[0];
        // test for IOR in cmd line
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-d")) {
                if (i < args.length - 1) {
                    strIOR = args[++i];
                }
            }
            if (args[i].equals("-raw")) {
                rawOutput = true;
            }
            if (args[i].equals("-h")) {
                System.out.println("Usage: cmd curl [-d ior -raw -h]");
                return;
            }
        }
        if (strIOR == null) {
            // use default
            strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
        }
        // create and initialize the ORB
        ORB orb = ORB.init(args, null);
        DAL dal = DALHelper.narrow(orb.string_to_object(strIOR));
        String xml = dal.get_DAO(curl);
        if (rawOutput) {
            m_logger.log(AcsLogLevel.INFO, "Curl data:\n" + xml);
            return;
        }
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        XMLHandler xmlSolver = new XMLHandler(false, m_logger);
        saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx();
            System.err.println(info);
            throw xmlErr;
        }
        System.out.println("Env " + System.getProperty("HOMEPATH"));
        // dump contents
        System.out.println("________________________________________________________");
        walk(xmlSolver.m_rootNode);
        System.out.println("________________________________________________________");
    } catch (AcsJCDBXMLErrorEx e) {
        e.printStackTrace();
        e.log(m_logger);
    } catch (CDBXMLErrorEx e) {
        AcsJCDBXMLErrorEx je = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(e);
        String smsg = "XML Error \tCURL='" + je.getCurl() + "'\n\t\tFilename='" + je.getFilename() + "'\n\t\tNodename='" + je.getNodename() + "'\n\t\tMSG='" + je.getErrorString() + "'";
        je.log(m_logger);
        m_logger.log(AcsLogLevel.NOTICE, smsg, je);
    } catch (CDBRecordDoesNotExistEx e) {
        AcsJCDBRecordDoesNotExistEx je = AcsJCDBRecordDoesNotExistEx.fromCDBRecordDoesNotExistEx(e);
        String smsg = "Record does not exist \tCURL='" + je.getCurl() + "'";
        je.log(m_logger);
        m_logger.log(AcsLogLevel.NOTICE, smsg, je);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : XMLHandler(com.cosylab.cdb.jdal.XMLHandler) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) Logger(java.util.logging.Logger) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)

Example 8 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx 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)

Example 9 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class HibernateWDALImpl method get_DAO_Servant.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.DALOperations#get_DAO_Servant(java.lang.String)
	 */
public DAO get_DAO_Servant(String curl) throws CDBXMLErrorEx, CDBRecordDoesNotExistEx {
    checkAccess();
    // remove trailing slashes, to have unique curl (used for key)
    if (curl.length() > 0 && curl.charAt(0) == '/')
        curl = curl.substring(1);
    // make sure there are no identical DAOs created
    synchronized (daoMap) {
        // get cached
        if (daoMap.containsKey(curl))
            return daoMap.get(curl);
        Object node = curl.length() == 0 ? rootNode : DOMJavaClassIntrospector.getNode(curl, rootNode);
        if (node == null || DOMJavaClassIntrospector.isPrimitive(node.getClass())) {
            AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
            ex.setCurl(curl);
            m_logger.log(AcsLogLevel.NOTICE, "DAL::get_DAO_Servant " + ex.getShortDescription());
            throw ex.toCDBRecordDoesNotExistEx();
        }
        try {
            // create object id
            byte[] id = curl.getBytes();
            Object objImpl = null;
            DAOPOA daoImpl = null;
            if (node instanceof DAOPOA)
                objImpl = daoImpl = (DAOPOA) node;
            else if (node instanceof DAOImpl)
                objImpl = daoImpl = new DAOPOATie((DAOImpl) node);
            else if (node instanceof XMLTreeNode)
                //objImpl = daoImpl = new DAOImpl(curl, (XMLTreeNode)node, poa, m_logger);
                objImpl = daoImpl = new DAOPOATie(new NoDestroyDAOImpl(curl, (XMLTreeNode) node, poa, m_logger));
            else {
                //daoImpl = new HibernateDAOImpl(curl, node, poa, m_logger);
                HibernateWDAOImpl impl = new HibernateWDAOImpl(mainSession, curl, node, poa, m_logger);
                objImpl = impl;
                daoImpl = new DAOPOATie(impl);
                impl.setSetvant(daoImpl);
            }
            // activate object
            poa.activate_object_with_id(id, daoImpl);
            DAO href = DAOHelper.narrow(poa.servant_to_reference(daoImpl));
            // map DAO reference
            daoMap.put(curl, href);
            daoObjMap.put(curl, objImpl);
            m_logger.log(AcsLogLevel.INFO, "Returning DAO servant for: " + curl);
            return href;
        } catch (Throwable t) {
            // @todo not clean, just to be consistent v DAL impl
            t.printStackTrace();
            String info = "DAL::get_DAO_Servant " + t;
            AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
            xmlErr.setErrorString(info);
            m_logger.log(AcsLogLevel.NOTICE, info);
            throw xmlErr.toCDBXMLErrorEx();
        }
    }
}
Also used : WDAOPOATie(com.cosylab.CDB.WDAOPOATie) DAOPOATie(com.cosylab.CDB.DAOPOATie) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) DAOPOA(com.cosylab.CDB.DAOPOA) WDAOPOA(com.cosylab.CDB.WDAOPOA) DAO(com.cosylab.CDB.DAO) WDAO(com.cosylab.CDB.WDAO) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)

Example 10 with AcsJCDBRecordDoesNotExistEx

use of alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx in project ACS by ACS-Community.

the class HibernateWDALImpl method get_WDAO_Servant.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.WDALOperations#get_WDAO_Servant(java.lang.String)
	 */
public WDAO get_WDAO_Servant(String curl) throws CDBRecordIsReadOnlyEx, CDBXMLErrorEx, CDBRecordDoesNotExistEx {
    checkAccess();
    // remove trailing slashes, to have unique curl (used for key)
    if (curl.length() > 0 && curl.charAt(0) == '/')
        curl = curl.substring(1);
    // make sure there are no identical DAOs created
    synchronized (wdaoMap) {
        // get cached
        if (wdaoMap.containsKey(curl))
            return (WDAO) wdaoMap.get(curl);
        Object node = curl.length() == 0 ? rootNode : DOMJavaClassIntrospector.getNode(curl, rootNode);
        if (node == null || DOMJavaClassIntrospector.isPrimitive(node.getClass())) {
            AcsJCDBRecordDoesNotExistEx ex = new AcsJCDBRecordDoesNotExistEx();
            ex.setCurl(curl);
            m_logger.log(AcsLogLevel.NOTICE, "WDAL::get_WDAO_Servant " + ex.getShortDescription());
            throw ex.toCDBRecordDoesNotExistEx();
        }
        try {
            Object objImpl = null;
            WDAOPOA wdaoImpl = null;
            if (node instanceof WDAOPOA)
                objImpl = wdaoImpl = (WDAOPOA) node;
            else //else if (node instanceof XMLTreeNode)
            //{
            //	DAOImpl daoImpl = new DAOImpl(curl, (XMLTreeNode)node, poa, m_logger);
            //	objImpl = wdaoImpl = new WDAOImpl(this, curl, daoImpl, poa, m_logger);
            //}
            {
                HibernateWDAOImpl impl = new HibernateWDAOImpl(mainSession, curl, node, poa, m_logger);
                objImpl = impl;
                wdaoImpl = new WDAOPOATie(impl);
                impl.setSetvant(wdaoImpl);
            }
            // create object id
            byte[] id = ("WDAO" + curl).getBytes();
            // activate object
            poa.activate_object_with_id(id, wdaoImpl);
            WDAO href = WDAOHelper.narrow(poa.servant_to_reference(wdaoImpl));
            // map DAO reference
            wdaoMap.put(curl, href);
            wdaoObjMap.put(curl, objImpl);
            m_logger.log(AcsLogLevel.INFO, "Returning WDAO servant for: " + curl);
            return href;
        } catch (Throwable t) {
            // @todo not clean, just to be consistent v DAL impl
            String info = "WDAL::get_WDAO_Servant " + t;
            AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
            xmlErr.setErrorString(info);
            m_logger.log(AcsLogLevel.NOTICE, info);
            throw xmlErr.toCDBXMLErrorEx();
        }
    }
}
Also used : WDAO(com.cosylab.CDB.WDAO) WDAOPOA(com.cosylab.CDB.WDAOPOA) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) WDAOPOATie(com.cosylab.CDB.WDAOPOATie)

Aggregations

AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)11 AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)8 AcsJCDBExceptionEx (alma.cdbErrType.wrappers.AcsJCDBExceptionEx)2 DAO (com.cosylab.CDB.DAO)2 DAOPOATie (com.cosylab.CDB.DAOPOATie)2 WDAO (com.cosylab.CDB.WDAO)2 WDAOPOA (com.cosylab.CDB.WDAOPOA)2 WDAOPOATie (com.cosylab.CDB.WDAOPOATie)2 Transaction (org.hibernate.Transaction)2 StopWatch (alma.acs.util.StopWatch)1 CDBFieldIsReadOnlyEx (alma.cdbErrType.CDBFieldIsReadOnlyEx)1 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)1 CDBXMLErrorEx (alma.cdbErrType.CDBXMLErrorEx)1 WrongCDBDataTypeEx (alma.cdbErrType.WrongCDBDataTypeEx)1 AcsJCDBFieldDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx)1 AcsJWrongCDBDataTypeEx (alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx)1 DAOOperations (com.cosylab.CDB.DAOOperations)1 DAOPOA (com.cosylab.CDB.DAOPOA)1 XMLHandler (com.cosylab.cdb.jdal.XMLHandler)1 XMLSaver (com.cosylab.cdb.jdal.hibernate.DOMJavaClassIntrospector.XMLSaver)1