Search in sources :

Example 1 with DAOOperations

use of com.cosylab.CDB.DAOOperations in project ACS by ACS-Community.

the class CDBAccess method internalConnect.

/**
	 * Performs the connect of the specified DAO.
	 * 
	 * @param	proxy	the proxy to connect, non-<code>null</code>
	 */
private void internalConnect(DAOProxy proxy) {
    String curl = null;
    try {
        checkDALConnection();
    } catch (Throwable th) {
        // TODO @todo replace
        RuntimeException re = new RuntimeException("Failed to obtain DAO for proxy '" + proxy + "'.", th);
        throw re;
    }
    DAOOperations dao = null;
    try {
        curl = proxy.getCURL();
        if (remoteDAO) {
            dao = dalReference.get_DAO_Servant(curl);
        } else {
            String xml = dalReference.get_DAO(curl);
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser saxParser = factory.newSAXParser();
            // use CDB XML handler which does not creates strings...
            XMLHandler xmlSolver = new XMLHandler(false, logger);
            saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
            if (xmlSolver.m_errorString != null) {
                AcsJCDBXMLErrorEx e = new AcsJCDBXMLErrorEx();
                e.setErrorString("XML parser error: " + xmlSolver.m_errorString);
                throw e;
            //throw new XMLerror("XML parser error: " + xmlSolver.m_errorString);
            }
            // create non-CORBA related, silent DAO
            dao = new DAOImpl(curl, xmlSolver.m_rootNode, null, logger, true);
            proxy.setElementName(xmlSolver.m_rootNode.getName());
        }
        // register listener, if not already registered
        if (changeListener != null) {
            if (!changeListener.isRegistered(curl))
                changeListener.handle(dalReference, curl, proxy);
        }
    } catch (Throwable th) {
        // TODO @todo replace
        RuntimeException re = new RuntimeException("Failed to obtain DAO object for proxy '" + proxy + "'.", th);
        throw re;
    }
    try {
        proxy.initialize(dao);
    } catch (Throwable th) {
        // TODO @todo replace
        RuntimeException re = new RuntimeException("The proxy '" + proxy + "' rejects the DAO.", th);
        throw re;
    }
    logger.config("Connected to DAO '" + proxy.getCURL() + "'.");
}
Also used : XMLHandler(com.cosylab.cdb.jdal.XMLHandler) InputSource(org.xml.sax.InputSource) DAOOperations(com.cosylab.CDB.DAOOperations) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) DAOImpl(com.cosylab.cdb.jdal.DAOImpl) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 2 with DAOOperations

use of com.cosylab.CDB.DAOOperations 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)2 DAOOperations (com.cosylab.CDB.DAOOperations)2 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)1 DAO (com.cosylab.CDB.DAO)1 DAOPOATie (com.cosylab.CDB.DAOPOATie)1 DAOImpl (com.cosylab.cdb.jdal.DAOImpl)1 XMLHandler (com.cosylab.cdb.jdal.XMLHandler)1 StringReader (java.io.StringReader)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 Servant (org.omg.PortableServer.Servant)1 InputSource (org.xml.sax.InputSource)1