'If database has been cleaned, this method
will update it.
:return:'

@with_session
def synchronize_database(self, session=None):

    log.debug(u'T411Proxy    start    database    synchronization    with    T411')
    category_tree = self.rest_client.retrieve_category_tree()
    term_tree = self.rest_client.retrieve_terms_tree()
    (main_categories, indexed_categories) = self.mapper.map_category_tree(category_tree)
    (category_to_term_type, term_types) = self.mapper.map_term_type_tree(term_tree)
    log.debug(u'%d    categories    (%d    are    main    categories)    and    %d    term    types    retrieved', len(indexed_categories), len(main_categories), len(term_types))
    for (category_id, term_type_id) in category_to_term_type:
        category = indexed_categories.get(category_id)
        term_type = term_types.get(term_type_id)
        category.term_types.append(term_type)
    session.add_all(main_categories)
    session.commit()
    self.__has_cached_criterias = None
