Exemplo n.º 1
0
bool Schema::setDimension(Dimension const& dim)
{
    schema::index_by_name& name_index = m_index.get<schema::name>();
    schema::index_by_name::iterator it = name_index.find(dim.getName());
    
    // FIXME: If there are two dimensions with the same name here, we're 
    // screwed if they both have the same namespace too
    if (it != name_index.end()) {
        while (it != name_index.end())
        {
            if (boost::equals(dim.getNamespace(), it->getNamespace()))
            {
                name_index.replace(it, dim);
                return true;
            }
            ++it;
        }
    } else {
        std::ostringstream oss;
        oss << "Dimension with name '" << dim.getName() << "' not found, unable to Schema::setDimension";
        throw dimension_not_found(oss.str());
    }

    return true;
}
Exemplo n.º 2
0
const Dimension& Schema::getDimension(std::size_t t) const
{
    schema::index_by_index const& idx = m_index.get<schema::index>();
    
    if (t >= idx.size())
        throw dimension_not_found("Index position is not valid");
    
    return idx.at(t);
}
Exemplo n.º 3
0
const Dimension& Schema::getDimension(dimension::id const& t) const
{
    schema::index_by_uid::const_iterator it = m_index.get<schema::uid>().find(t);

    if (it != m_index.get<schema::uid>().end())
    {
        return *it;
    }    
    
    std::ostringstream oss;
    oss << "getDimension: dimension not found with uuid '" << boost::lexical_cast<std::string>(t) << "'";
    throw dimension_not_found(oss.str());

}
Exemplo n.º 4
0
const Dimension& Schema::getDimension(dimension::id const& t) const
{
    /// getDimension for a dimension::id will not respect the isIgnored setting
    /// of the dimension.  Stages that wish to operate with dimensions with exacting
    /// specificity should take care to use uuids as their keys rather than
    /// names.
    schema::index_by_uid::const_iterator it = m_index.get<schema::uid>().find(t);

    if (it != m_index.get<schema::uid>().end())
    {
        return *it;
    }

    std::ostringstream oss;
    oss << "getDimension: dimension not found with uuid '" << boost::lexical_cast<std::string>(t) << "'";
    throw dimension_not_found(oss.str());
}
Exemplo n.º 5
0
bool Schema::setDimension(Dimension const& dim)
{
    // Try setting based on UUID first if it's there and not null.
    if (dim.getUUID() != boost::uuids::nil_uuid())
    {
        schema::index_by_uid& id_index = m_index.get<schema::uid>();
        schema::index_by_uid::const_iterator id = id_index.find(dim.getUUID());
        if (id != id_index.end())
        {
            id_index.replace(id, dim);
            return true;
        }
    }

    schema::index_by_name& name_index = m_index.get<schema::name>();
    schema::index_by_name::iterator it = name_index.find(dim.getName());
    // FIXME: If there are two dimensions with the same name here, we're
    // screwed if they both have the same namespace too
    if (it != name_index.end())
    {
        while (it != name_index.end())
        {
            if (boost::equals(dim.getNamespace(), it->getNamespace()))
            {
                name_index.replace(it, dim);
                return true;
            }
            ++it;
        }
    }
    else
    {
        std::ostringstream oss;
        oss << "Dimension with name '" << dim.getName() << "' not found, unable to Schema::setDimension";
        throw dimension_not_found(oss.str());
    }

    return true;
}
Exemplo n.º 6
0
const Dimension& Schema::getDimension(std::string const& t, std::string const& ns) const
{
    schema::index_by_name const& name_index = m_index.get<schema::name>();
    schema::index_by_name::const_iterator it = name_index.find(t);
    
    schema::index_by_name::size_type count = name_index.count(t);

    std::ostringstream oss;
    oss << "Dimension with name '" << t << "' not found, unable to Schema::getDimension";

    // FIXME: If there are two dimensions with the same name here, we're 
    // scrwed
    
    // std::cout << "finding dimension with name" << t << " and ns: " << ns << std::endl;
    if (it != name_index.end()) {
        
        if (ns.size())
        {
            while (it != name_index.end())
            {
                if (boost::equals(ns, it->getNamespace()))
                    return *it;
                ++it;
            }
            
        } 
        
        if (count > 1) {

            std::pair<schema::index_by_name::const_iterator, schema::index_by_name::const_iterator> ret = name_index.equal_range(t);
            boost::uint32_t num_parents(0);
            boost::uint32_t num_children(0);
            std::map<dimension::id, dimension::id> relationships;
            
            // Test to make sure that the number of parent dimensions all with 
            // the same name is equal to only 1. If there are multiple 
            // dimensions with the same name, but no relationships defined, 
            // we are in an error condition
            for (schema::index_by_name::const_iterator  o = ret.first; o != ret.second; ++o)
            {
                // Put a map together that maps parents to children that 
                // we are going to walk to find the very last child in the 
                // graph.
                std::pair<dimension::id, dimension::id> p( o->getParent(), o->getUUID());
                relationships.insert(p);
                
                // The parent dimension should have a nil parent of its own.
                // nil_uuid is the default parent of all dimensions as the y
                // are created
                if (o->getParent().is_nil()) 
                {
                    num_parents++;
                }
                else
                {
                    num_children++;
                }
                
            }
            
            if (num_parents != 1)
            {
                std::ostringstream oss;
                
                oss << "Schema has multiple dimensions with name '" << t << "', but "
                       "their parent/child relationships are not coherent. Multiple "
                       "parents are present.";
                
                throw multiple_parent_dimensions(oss.str());
            }
            
            dimension::id parent = boost::uuids::nil_uuid();
            
            // Starting at the parent (nil uuid), walk the child/parent graph down to the 
            // end.  When we're done finding dimensions, what's left is the child 
            // at the end of the graph.
            std::map<dimension::id, dimension::id>::const_iterator p = relationships.find(parent);
            dimension::id child;
            while (p != relationships.end())
            {
                child = p->second;
                p = relationships.find(p->second);
            }
            schema::index_by_uid::const_iterator pi = m_index.get<schema::uid>().find(child);
            if (pi != m_index.get<schema::uid>().end())
            {
                return *pi;
            } 
            else 
            {
                std::ostringstream errmsg;
                errmsg << "Unable to fetch subjugate dimension with id '" << child << "' in schema";
                throw dimension_not_found(errmsg.str());
            }
        }
        return *it;
    } else {
        boost::uuids::uuid ps1;
        try
        {
            boost::uuids::string_generator gen;
            ps1 = gen(t);
        } catch (std::runtime_error&)
        {
            // invalid string for uuid
            throw dimension_not_found(oss.str());
        }

        schema::index_by_uid::const_iterator i = m_index.get<schema::uid>().find(ps1);

        if (i != m_index.get<schema::uid>().end())
        {
            if (ns.size())
            {
                while (i != m_index.get<schema::uid>().end())
                {
                    if (boost::equals(ns, i->getNamespace()))
                        return *i;
                    ++i;
                }
            
            }
            
            return *i;
        } else 
        {
            oss.str("");
            oss << "Dimension with name '" << t << "' not found, unable to Schema::getDimension";
            throw dimension_not_found(oss.str());
        }

    }

}