# Path: monasca_api/common/repositories/model/sub_alarm_definition.py
# class SubAlarmDefinition(object):
#     def __init__(self, row=None, sub_expr=None):
#     def _init_dimensions(self, dimensions_str):
#     def expression(self):
#     def __hash__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def same_key_fields(self, other):
# 
# Path: monasca_api/common/repositories/sqla/models.py
# def get_all_metadata():
# def create_a_model(metadata=None):
# def create_sadd_model(metadata=None):
# def create_aa_model(metadata=None):
# def create_md_model(metadata=None):
# def create_mde_model(metadata=None):
# def create_nm_model(metadata=None):
# def create_nmt_model(metadata=None):
# def create_mdd_model(metadata=None):
# def create_am_model(metadata=None):
# def create_ad_model(metadata=None):
# def create_sa_model(metadata=None):
# def create_sad_model(metadata=None):
#     def __init__(self, columns, separator=',', order_by=None):
# def _group_concat_oracle(element, compiler_, **kw):
# def _group_concat_postgresql(element, compiler_, **kw):
# def _group_concat_sybase(element, compiler_, **kw):
# def _group_concat_mysql(element, compiler_, **kw):
# def _group_concat_default(element, compiler_, **kw):
#     def __init__(self, column, fields):
# def _field_sort_mysql(element, compiler_, **kw):
# def _field_sort_general(element, compiler_, **kw):
# class group_concat(expression.ColumnElement):
# class field_sort(expression.ColumnElement):


import datetime
import six
from oslo_utils import encodeutils
from oslo_utils import uuidutils
from sqlalchemy import MetaData, update, delete, insert
from sqlalchemy import select, text, bindparam, null, literal_column
from sqlalchemy import or_
from monasca_api.common.repositories import alarm_definitions_repository as adr
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories.model import sub_alarm_definition
from monasca_api.common.repositories.sqla import models
from monasca_api.common.repositories.sqla import sql_repository
                    mdd_s,
                    mdd_s.c.id == am_s.c.metric_definition_dimensions_id) .join(
                    mde_s,
                    mde_s.c.id == mdd_s.c.metric_definition_id) .outerjoin(
                    mdg,
                    mdg.c.dimension_set_id == mdd_s.c.metric_dimension_set_id)) .where(
                ad_s.c.tenant_id == bindparam('b_tenant_id')) .where(
                ad_s.c.id == bindparam('b_id')) .order_by(
                a_s.c.id) .distinct())

        self.soft_delete_ad_query = (update(ad)
                                     .where(ad.c.tenant_id == bindparam('b_tenant_id'))
                                     .where(ad.c.id == bindparam('b_id'))
                                     .where(ad.c.deleted_at == null())
                                     .values(deleted_at=datetime.datetime.utcnow()))

        self.delete_a_query = (delete(a)
                               .where(a.c.alarm_definition_id == bindparam('b_id')))

        columns_gc = [sadd_s.c.dimension_name + text("'='") + sadd_s.c.value]
        saddg = (select([sadd_s.c.sub_alarm_definition_id,
                         models.group_concat(columns_gc).label('dimensions')])
                 .select_from(sadd_s)
                 .group_by(sadd_s.c.sub_alarm_definition_id)
                 .alias('saddg'))

        self.get_sub_alarm_definitions_query = (
            select(
                [
                    sad_s,

# Path: monasca_api/common/repositories/model/sub_alarm_definition.py
# class SubAlarmDefinition(object):
#     def __init__(self, row=None, sub_expr=None):
#     def _init_dimensions(self, dimensions_str):
#     def expression(self):
#     def __hash__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def same_key_fields(self, other):
# 
# Path: monasca_api/common/repositories/sqla/models.py
# def get_all_metadata():
# def create_a_model(metadata=None):
# def create_sadd_model(metadata=None):
# def create_aa_model(metadata=None):
# def create_md_model(metadata=None):
# def create_mde_model(metadata=None):
# def create_nm_model(metadata=None):
# def create_nmt_model(metadata=None):
# def create_mdd_model(metadata=None):
# def create_am_model(metadata=None):
# def create_ad_model(metadata=None):
# def create_sa_model(metadata=None):
# def create_sad_model(metadata=None):
#     def __init__(self, columns, separator=',', order_by=None):
# def _group_concat_oracle(element, compiler_, **kw):
# def _group_concat_postgresql(element, compiler_, **kw):
# def _group_concat_sybase(element, compiler_, **kw):
# def _group_concat_mysql(element, compiler_, **kw):
# def _group_concat_default(element, compiler_, **kw):
#     def __init__(self, column, fields):
# def _field_sort_mysql(element, compiler_, **kw):
# def _field_sort_general(element, compiler_, **kw):
# class group_concat(expression.ColumnElement):
# class field_sort(expression.ColumnElement):


# Path: monasca_api/common/repositories/sqla/alarm_definitions_repository.py
import datetime
import six
from oslo_utils import encodeutils
from oslo_utils import uuidutils
from sqlalchemy import MetaData, update, delete, insert
from sqlalchemy import select, text, bindparam, null, literal_column
from sqlalchemy import or_
from monasca_api.common.repositories import alarm_definitions_repository as adr
from monasca_api.common.repositories import exceptions
from monasca_api.common.repositories.model import sub_alarm_definition
from monasca_api.common.repositories.sqla import models
from monasca_api.common.repositories.sqla import sql_repository

                    mdd_s,
                    mdd_s.c.id == am_s.c.metric_definition_dimensions_id) .join(
                    mde_s,
                    mde_s.c.id == mdd_s.c.metric_definition_id) .outerjoin(
                    mdg,
                    mdg.c.dimension_set_id == mdd_s.c.metric_dimension_set_id)) .where(
                ad_s.c.tenant_id == bindparam('b_tenant_id')) .where(
                ad_s.c.id == bindparam('b_id')) .order_by(
                a_s.c.id) .distinct())

        self.soft_delete_ad_query = (update(ad)
                                     .where(ad.c.tenant_id == bindparam('b_tenant_id'))
                                     .where(ad.c.id == bindparam('b_id'))
                                     .where(ad.c.deleted_at == null())
                                     .values(deleted_at=datetime.datetime.utcnow()))

        self.delete_a_query = (delete(a)
                               .where(a.c.alarm_definition_id == bindparam('b_id')))

        columns_gc = [sadd_s.c.dimension_name + text("'='") + sadd_s.c.value]
        saddg = (select([sadd_s.c.sub_alarm_definition_id,
                         models.group_concat(columns_gc).label('dimensions')])
                 .select_from(sadd_s)
                 .group_by(sadd_s.c.sub_alarm_definition_id)
                 .alias('saddg'))

        self.get_sub_alarm_definitions_query = (
            select(
                [
                    sad_s,

                    saddg.c.dimensions]) .select_from(