class SessionManager: def __init__(self, entity): self.entity = entity self.session = Session() if not self.session.object_session(self.entity): self.session.add(self.entity) def __enter__(self): return self.session def __exit__(self, exc_type, exc_value, exc_traceback): if exc_value: self.session.expunge(self.entity) return False self.session.commit() return True
def save(streamsets: StreamSets): if not Session.object_session(streamsets): Session.add(streamsets) Session.commit()
def save(source_: Source): if not Session.object_session(source_): Session.add(source_) Session.commit()
def save_auth_token(token: AuthenticationToken): if not Session.object_session(token): Session.add(token) Session.commit()
def save(destination_: HttpDestination): if not Session.object_session(destination_): Session.add(destination_) Session.commit()
def save(entity: Entity): if not Session.object_session(entity): Session.add(entity) Session.commit()