Search in sources :

Example 21 with AcsJCDBXMLErrorEx

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

the class DALImpl method get_DAO_Servant.

/**
	 * create DAO servant with requested XML
	 */
public synchronized DAO get_DAO_Servant(String curl) throws CDBRecordDoesNotExistEx, CDBXMLErrorEx {
    totalDALInvocationCounter.incrementAndGet();
    // make sure CURL->DAO mapping is surjective function, remove leading slash
    if (curl.length() > 1 && curl.charAt(0) == '/')
        curl = curl.substring(1);
    // make sure there are no identical DAOs created
    synchronized (daoMap) {
        if (daoMap.containsKey(curl))
            return daoMap.get(curl);
    }
    // do the hardwork here
    XMLHandler xmlSolver;
    try {
        xmlSolver = loadRecords(curl, false);
    } catch (AcsJCDBXMLErrorEx e) {
        // @todo watch if this log also needs a repeat guard, similar to logRecordNotExistWithRepeatGuard
        m_logger.log(AcsLogLevel.NOTICE, "Failed to read curl '" + curl + "'.", e);
        throw e.toCDBXMLErrorEx();
    } catch (AcsJCDBRecordDoesNotExistEx e) {
        logRecordNotExistWithRepeatGuard(curl);
        throw e.toCDBRecordDoesNotExistEx();
    }
    if (xmlSolver == null) {
        // @TODO can this happen? Should we not throw an exception then?
        return null;
    }
    try {
        DAO href = null;
        // bind to map
        synchronized (daoMap) {
            // execution when different DAO are created
            if (daoMap.containsKey(curl))
                return daoMap.get(curl);
            final DAOImpl servantDelegate = new DAOImpl(curl, xmlSolver.m_rootNode, poa, m_logger);
            DAOOperations topLevelServantDelegate = servantDelegate;
            if (Boolean.getBoolean(Server.LOG_CDB_CALLS_PROPERTYNAME)) {
                // Currently we only intercept the functional IDL-defined methods, by wrapping servantDelegate.
                // If we want to also intercept the CORBA admin methods, then *servant* below should be wrapped with a dynamic proxy instead.
                DAOOperations interceptingServantDelegate = SimpleCallInterceptor.createSimpleInterceptor(DAOOperations.class, servantDelegate, m_logger);
                topLevelServantDelegate = interceptingServantDelegate;
            }
            final Servant servant = new DAOPOATie(topLevelServantDelegate);
            // create object id. 
            // Note that the ID *must* be derived from the curl, because DAOImpl#destroy will do the same in POA#deactivate_object.
            byte[] id = curl.getBytes();
            // activate object
            poa.activate_object_with_id(id, servant);
            href = DAOHelper.narrow(poa.servant_to_reference(servant));
            // map DAO reference
            daoMap.put(curl, href);
        }
        m_logger.log(AcsLogLevel.DEBUG, "Returning DAO servant for: " + curl);
        return href;
    } catch (Throwable t) {
        String info = "DAO::get_DAO_Servant " + t;
        AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
        xmlErr.setErrorString(info);
        m_logger.log(AcsLogLevel.NOTICE, info);
        throw xmlErr.toCDBXMLErrorEx();
    }
}
Also used : DAOPOATie(com.cosylab.CDB.DAOPOATie) DAO(com.cosylab.CDB.DAO) DAOOperations(com.cosylab.CDB.DAOOperations) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) Servant(org.omg.PortableServer.Servant)

Aggregations

AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)21 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)8 CDBXMLErrorEx (alma.cdbErrType.CDBXMLErrorEx)5 StringReader (java.io.StringReader)5 SAXParser (javax.xml.parsers.SAXParser)5 InputSource (org.xml.sax.InputSource)5 SAXParserFactory (javax.xml.parsers.SAXParserFactory)4 AcsJCDBExceptionEx (alma.cdbErrType.wrappers.AcsJCDBExceptionEx)3 XMLHandler (com.cosylab.cdb.jdal.XMLHandler)3 File (java.io.File)3 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)2 AcsJCDBFieldDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx)2 DAO (com.cosylab.CDB.DAO)2 DAOOperations (com.cosylab.CDB.DAOOperations)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 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2