# Path: blazar/db/exceptions.py
# LOG = logging.getLogger(__name__)
# class BlazarDBException(exceptions.BlazarException):
# class BlazarDBDuplicateEntry(BlazarDBException):
# class BlazarDBNotFound(BlazarDBException):
# class BlazarDBInvalidFilter(BlazarDBException):
# class BlazarDBInvalidFilterOperator(BlazarDBException):
# class BlazarDBResourcePropertiesNotEnabled(BlazarDBException):
# class BlazarDBInvalidResourceProperty(BlazarDBException):
# 
# Path: blazar/db/sqlalchemy/models.py
# def _generate_unicode_uuid():
# def MediumText():
# def _id_column():
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self, include=None):
# class Lease(mb.BlazarBase):
# class Reservation(mb.BlazarBase):
# class Event(mb.BlazarBase):
# class ResourceProperty(mb.BlazarBase):
# class ComputeHostReservation(mb.BlazarBase):
# class InstanceReservations(mb.BlazarBase):
# class ComputeHostAllocation(mb.BlazarBase):
# class ComputeHost(mb.BlazarBase):
# class ComputeHostExtraCapability(mb.BlazarBase):
# class FloatingIPReservation(mb.BlazarBase):
# class RequiredFloatingIP(mb.BlazarBase):
# class FloatingIPAllocation(mb.BlazarBase):
# class FloatingIP(mb.BlazarBase):


import sys
import sqlalchemy as sa
from oslo_config import cfg
from oslo_db import exception as common_db_exc
from oslo_db.sqlalchemy import session as db_session
from oslo_log import log as logging
from sqlalchemy.sql.expression import asc
from sqlalchemy.sql.expression import desc
from blazar.db import exceptions as db_exc
from blazar.db.sqlalchemy import facade_wrapper
from blazar.db.sqlalchemy import models
    session = get_session()
    with session.begin():
        try:
            event.save(session=session)
        except common_db_exc.DBDuplicateEntry as e:
            # raise exception about duplicated columns (e.columns)
            raise db_exc.BlazarDBDuplicateEntry(
                model=event.__class__.__name__, columns=e.columns)

    return event_get(event.id)


def event_update(event_id, values):
    session = get_session()

    with session.begin():
        event = _event_get(session, event_id)
        event.update(values)
        event.save(session=session)

    return event_get(event_id)


def event_destroy(event_id):
    session = get_session()
    with session.begin():
        event = _event_get(session, event_id)

        if not event:
            # raise not found error

# Path: blazar/db/exceptions.py
# LOG = logging.getLogger(__name__)
# class BlazarDBException(exceptions.BlazarException):
# class BlazarDBDuplicateEntry(BlazarDBException):
# class BlazarDBNotFound(BlazarDBException):
# class BlazarDBInvalidFilter(BlazarDBException):
# class BlazarDBInvalidFilterOperator(BlazarDBException):
# class BlazarDBResourcePropertiesNotEnabled(BlazarDBException):
# class BlazarDBInvalidResourceProperty(BlazarDBException):
# 
# Path: blazar/db/sqlalchemy/models.py
# def _generate_unicode_uuid():
# def MediumText():
# def _id_column():
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self):
#     def to_dict(self, include=None):
# class Lease(mb.BlazarBase):
# class Reservation(mb.BlazarBase):
# class Event(mb.BlazarBase):
# class ResourceProperty(mb.BlazarBase):
# class ComputeHostReservation(mb.BlazarBase):
# class InstanceReservations(mb.BlazarBase):
# class ComputeHostAllocation(mb.BlazarBase):
# class ComputeHost(mb.BlazarBase):
# class ComputeHostExtraCapability(mb.BlazarBase):
# class FloatingIPReservation(mb.BlazarBase):
# class RequiredFloatingIP(mb.BlazarBase):
# class FloatingIPAllocation(mb.BlazarBase):
# class FloatingIP(mb.BlazarBase):


# Path: blazar/db/sqlalchemy/api.py
import sys
import sqlalchemy as sa
from oslo_config import cfg
from oslo_db import exception as common_db_exc
from oslo_db.sqlalchemy import session as db_session
from oslo_log import log as logging
from sqlalchemy.sql.expression import asc
from sqlalchemy.sql.expression import desc
from blazar.db import exceptions as db_exc
from blazar.db.sqlalchemy import facade_wrapper
from blazar.db.sqlalchemy import models

    session = get_session()
    with session.begin():
        try:
            event.save(session=session)
        except common_db_exc.DBDuplicateEntry as e:
            # raise exception about duplicated columns (e.columns)
            raise db_exc.BlazarDBDuplicateEntry(
                model=event.__class__.__name__, columns=e.columns)

    return event_get(event.id)


def event_update(event_id, values):
    session = get_session()

    with session.begin():
        event = _event_get(session, event_id)
        event.update(values)
        event.save(session=session)

    return event_get(event_id)


def event_destroy(event_id):
    session = get_session()
    with session.begin():
        event = _event_get(session, event_id)

        if not event:
            # raise not found error

            raise db_exc.BlazarDBNotFound(id=event_id, model='Event')