Search in sources :

Example 11 with DAO

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

the class ChannelProperties method getCDBAdminProps.

// //////////////////////////////////////////////////////////////////////////
/**
	 * Given a channel name that exists in the ACS CDB
	 * ($ACS_CDB/CDB/MACI/Channels/channelName/channelName.xml), this function
	 * returns the channels administrative properties in their CORBA format.
	 * 
	 * @param channelName
	 *           name of the channel found in $ACS_CDB/CDB/MACI/Channels
	 * @return channel's admin properties
	 * @throws AcsJException
	 *            if the channel's CDB entry is corrupted in any way
	 */
public Property[] getCDBAdminProps(String channelName) throws AcsJException {
    // use this object to get at channel information from the CDB
    DAO tempDAO = null;
    try {
        tempDAO = m_services.getCDB().get_DAO_Servant("MACI/Channels/" + channelName);
    } catch (alma.cdbErrType.CDBXMLErrorEx e) {
        m_logger.log(Level.WARNING, "Bad CDB entry found for '" + channelName + "' channel");
        throw new alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx(e);
    } catch (alma.cdbErrType.CDBRecordDoesNotExistEx e) {
        m_logger.log(Level.WARNING, "No CDB entry found for '" + channelName + "' channel");
        throw new alma.ACSErrTypeCommon.wrappers.AcsJFileNotFoundEx(e);
    } catch (AcsJContainerServicesEx e) {
        m_logger.log(Level.WARNING, "CDB unavailable");
        throw new alma.ACSErrTypeCommon.wrappers.AcsJNoResourcesEx(e);
    }
    // MaxQueueLength - TAO 1.1 had a queque of ~5 events. TAO 1.3 allows an
    // infinite amount of events to be stored. 20 seems like
    // a reasonable default.
    Any maxQLAny = m_services.getAdvancedContainerServices().getAny();
    try {
        maxQLAny.insert_long(tempDAO.get_long("MaxQueueLength"));
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    Property maxQL = new Property(MaxQueueLength.value, maxQLAny);
    // MaxConsumers - ///////////////////////////////////////////////////////
    Any maxConsumersAny = m_services.getAdvancedContainerServices().getAny();
    try {
        maxConsumersAny.insert_long(tempDAO.get_long("MaxConsumers"));
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    Property maxConsumers = new Property(MaxConsumers.value, maxConsumersAny);
    // MaxSuppliers - ///////////////////////////////////////////////////////
    Any maxSuppliersAny = m_services.getAdvancedContainerServices().getAny();
    try {
        maxSuppliersAny.insert_long(tempDAO.get_long("MaxSuppliers"));
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    Property maxSuppliers = new Property(MaxSuppliers.value, maxSuppliersAny);
    // RejectNewEvents - if the queque is full, suppliers get exceptions when
    // trying to push events onto the channel.
    Any rejectNEAny = m_services.getAdvancedContainerServices().getAny();
    boolean tBool = true;
    try {
        if (tempDAO.get_string("RejectNewEvents").equals("false")) {
            tBool = false;
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    rejectNEAny.insert_boolean(tBool);
    Property rejectNE = new Property(RejectNewEvents.value, rejectNEAny);
    Property[] adminProps = { maxQL, maxConsumers, maxSuppliers, rejectNE };
    return adminProps;
}
Also used : AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Any(org.omg.CORBA.Any) AcsJException(alma.acs.exceptions.AcsJException) DAO(com.cosylab.CDB.DAO) Property(org.omg.CosNotification.Property)

Example 12 with DAO

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

Aggregations

DAO (com.cosylab.CDB.DAO)12 AcsJException (alma.acs.exceptions.AcsJException)3 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)2 CDBFieldDoesNotExistEx (alma.cdbErrType.CDBFieldDoesNotExistEx)2 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)2 AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)2 DAOPOATie (com.cosylab.CDB.DAOPOATie)2 WDAO (com.cosylab.CDB.WDAO)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Any (org.omg.CORBA.Any)2 Property (org.omg.CosNotification.Property)2 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)1 DAOOperations (com.cosylab.CDB.DAOOperations)1 DAOPOA (com.cosylab.CDB.DAOPOA)1 WDAOPOA (com.cosylab.CDB.WDAOPOA)1 WDAOPOATie (com.cosylab.CDB.WDAOPOATie)1 ParseException (java.text.ParseException)1 Servant (org.omg.PortableServer.Servant)1