Project

Profile

Help

Refactor #78

closed

Convert pulp.server.db.connection to manage the database connection with an object

Added by Anonymous over 9 years ago. Updated almost 3 years ago.

Status:
CLOSED - WONTFIX
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Platform Release:
Groomed:
No
Sprint Candidate:
No
Tags:
Pulp 2
Sprint:
Quarter:

Description

This Task is designed to solve two problems. (1) To remove the use of globals and replace it with a class based design and (2) to consolidate the database getter methods onto the class managing the database singleton.

I generally avoid the use of globals because they casually share state and promote a non object oriented paradigm. Using a class to store any globals requires developers to be more explicit, and access functions can be getter methods instead of module level functions.

The specifics:
1) Introduce a new class in pulp.server.db.connection and move the initialize method into it as a @classmethod. Refactor all calls to the old pulp.server.db.connection.initialize method to use the new class method. The @classmethod initialize should store the _CONNECTION and _DATABASE objects as class attributes.

2) Move the get_collection(), get_database(), and get_connection() methods to be @classmethods on the new class introduced in (1). Refactor the usages of these 3 functions to use them as classmethods.

3) Ensure that get_collection(), get_database(), and get_connection() raise a consistent Exception if initialize() has not already been called.

4) Update the associated tests

Also available in: Atom PDF