Search in sources :

Example 1 with DAOPOATie

use of com.cosylab.CDB.DAOPOATie 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 2 with DAOPOATie

use of com.cosylab.CDB.DAOPOATie 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

AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)2 AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)2 DAO (com.cosylab.CDB.DAO)2 DAOPOATie (com.cosylab.CDB.DAOPOATie)2 DAOOperations (com.cosylab.CDB.DAOOperations)1 DAOPOA (com.cosylab.CDB.DAOPOA)1 WDAO (com.cosylab.CDB.WDAO)1 WDAOPOA (com.cosylab.CDB.WDAOPOA)1 WDAOPOATie (com.cosylab.CDB.WDAOPOATie)1 Servant (org.omg.PortableServer.Servant)1