# Path: sqlalchemy_continuum/factory.py
# class ModelFactory(object):
#     model_name = None
# 
#     def __call__(self, manager):
#         """
#         Create model class but only if it doesn't already exist
#         in declarative model registry.
#         """
#         Base = manager.declarative_base
#         try:
#             registry = Base.registry._class_registry
#         except AttributeError:  # SQLAlchemy < 1.4
#             registry = Base._decl_class_registry
#         if self.model_name not in registry:
#             return self.create_class(manager)
#         return registry[self.model_name]
# 
# Path: sqlalchemy_continuum/utils.py
# def version_class(model):
#     """
#     Return the version class for given SQLAlchemy declarative model class.
# 
#     ::
# 
#         version_class(Article)  # ArticleVersion class
# 
# 
#     :param model: SQLAlchemy declarative model class
# 
#     .. seealso:: :func:`parent_class`
#     """
#     manager = get_versioning_manager(model)
#     try:
#         return manager.version_class_map[model]
#     except KeyError:
#         return model
# 
# def version_obj(session, parent_obj):
#     manager = get_versioning_manager(parent_obj)
#     uow = manager.unit_of_work(session)
#     for version_obj in uow.version_session:
#         if (
#             parent_class(version_obj.__class__) == parent_obj.__class__ and
#             identity(version_obj)[:-1] == identity(parent_obj)
#         ):
#             return version_obj


import sqlalchemy as sa
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.inspection import inspect
from sqlalchemy_utils import JSONType, generic_relationship
from .base import Plugin
from ..factory import ModelFactory
from ..utils import version_class, version_obj
            manager = self

            transaction_id = sa.Column(
                sa.BigInteger,
                index=True,
                nullable=False
            )

            data = sa.Column(JSONType)

            object_type = sa.Column(sa.String(255))

            object_id = sa.Column(sa.BigInteger)

            object_tx_id = sa.Column(sa.BigInteger)

            target_type = sa.Column(sa.String(255))

            target_id = sa.Column(sa.BigInteger)

            target_tx_id = sa.Column(sa.BigInteger)

            def _calculate_tx_id(self, obj):
                session = sa.orm.object_session(self)
                if obj:
                    object_version = version_obj(session, obj)
                    if object_version:
                        return object_version.transaction_id

                    model = obj.__class__

# Path: sqlalchemy_continuum/factory.py
# class ModelFactory(object):
#     model_name = None
# 
#     def __call__(self, manager):
#         """
#         Create model class but only if it doesn't already exist
#         in declarative model registry.
#         """
#         Base = manager.declarative_base
#         try:
#             registry = Base.registry._class_registry
#         except AttributeError:  # SQLAlchemy < 1.4
#             registry = Base._decl_class_registry
#         if self.model_name not in registry:
#             return self.create_class(manager)
#         return registry[self.model_name]
# 
# Path: sqlalchemy_continuum/utils.py
# def version_class(model):
#     """
#     Return the version class for given SQLAlchemy declarative model class.
# 
#     ::
# 
#         version_class(Article)  # ArticleVersion class
# 
# 
#     :param model: SQLAlchemy declarative model class
# 
#     .. seealso:: :func:`parent_class`
#     """
#     manager = get_versioning_manager(model)
#     try:
#         return manager.version_class_map[model]
#     except KeyError:
#         return model
# 
# def version_obj(session, parent_obj):
#     manager = get_versioning_manager(parent_obj)
#     uow = manager.unit_of_work(session)
#     for version_obj in uow.version_session:
#         if (
#             parent_class(version_obj.__class__) == parent_obj.__class__ and
#             identity(version_obj)[:-1] == identity(parent_obj)
#         ):
#             return version_obj


# Path: sqlalchemy_continuum/plugins/activity.py
import sqlalchemy as sa
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.inspection import inspect
from sqlalchemy_utils import JSONType, generic_relationship
from .base import Plugin
from ..factory import ModelFactory
from ..utils import version_class, version_obj

            manager = self

            transaction_id = sa.Column(
                sa.BigInteger,
                index=True,
                nullable=False
            )

            data = sa.Column(JSONType)

            object_type = sa.Column(sa.String(255))

            object_id = sa.Column(sa.BigInteger)

            object_tx_id = sa.Column(sa.BigInteger)

            target_type = sa.Column(sa.String(255))

            target_id = sa.Column(sa.BigInteger)

            target_tx_id = sa.Column(sa.BigInteger)

            def _calculate_tx_id(self, obj):
                session = sa.orm.object_session(self)
                if obj:
                    object_version = version_obj(session, obj)
                    if object_version:
                        return object_version.transaction_id

                    model = obj.__class__

                    version_cls = version_class(model)