summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4>2011-06-06 17:40:56 +0000
committerlmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4>2011-06-06 17:40:56 +0000
commit06c16da75060e0e48a6d1bf5eaaeeb804620aa12 (patch)
tree9d03af069d9f163ac477e6de49fbd9d78af88ce2
parent69fe1942edd09f377b930f9f44e1413e9f75cbab (diff)
frontend.db: Adding afe custom database engine
Turns out that we rely on custom code to generate joins that does some trickery with Django ORM system, and was using a method calling get_from_clause, that was present on the Query class on Django 1.1. Now, the method was moved to a class upper in the hierarchy, called SQLCompiler, and SQLCompiler is tied to the db backend being used. After some research, seems like there's no solution cleaner than implementing one db backend special for autotest, just to accomodate this function. So created one db engine that inherits pretty much everything from the mysql one, except for the compiler classes. Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> git-svn-id: svn://test.kernel.org/autotest/trunk@5408 592f7852-d20e-0410-864c-8624ca9c26a4
-rw-r--r--frontend/db/__init__.py0
-rw-r--r--frontend/db/backends/__init__.py0
-rw-r--r--frontend/db/backends/afe/__init__.py0
-rw-r--r--frontend/db/backends/afe/base.py22
-rw-r--r--frontend/db/backends/afe/compiler.py32
-rw-r--r--frontend/db/backends/afe/creation.py1
-rw-r--r--frontend/db/backends/afe/introspection.py1
-rw-r--r--frontend/db/backends/afe/validation.py1
8 files changed, 57 insertions, 0 deletions
diff --git a/frontend/db/__init__.py b/frontend/db/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/frontend/db/__init__.py
diff --git a/frontend/db/backends/__init__.py b/frontend/db/backends/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/frontend/db/backends/__init__.py
diff --git a/frontend/db/backends/afe/__init__.py b/frontend/db/backends/afe/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/frontend/db/backends/afe/__init__.py
diff --git a/frontend/db/backends/afe/base.py b/frontend/db/backends/afe/base.py
new file mode 100644
index 00000000..6d617d20
--- /dev/null
+++ b/frontend/db/backends/afe/base.py
@@ -0,0 +1,22 @@
+from django.db.backends.mysql.base import DatabaseCreation as MySQLCreation
+from django.db.backends.mysql.base import DatabaseOperations as MySQLOperations
+from django.db.backends.mysql.base import DatabaseWrapper as MySQLDatabaseWrapper
+from django.db.backends.mysql.base import DatabaseIntrospection as MySQLIntrospection
+
+try:
+ import MySQLdb as Database
+except ImportError, e:
+ from django.core.exceptions import ImproperlyConfigured
+ raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
+
+
+class DatabaseOperations(MySQLOperations):
+ compiler_module = "autotest_lib.frontend.db.backends.afe.compiler"
+
+
+class DatabaseWrapper(MySQLDatabaseWrapper):
+ def __init__(self, *args, **kwargs):
+ super(DatabaseWrapper, self).__init__(*args, **kwargs)
+ self.creation = MySQLCreation(self)
+ self.ops = DatabaseOperations()
+ self.introspection = MySQLIntrospection(self)
diff --git a/frontend/db/backends/afe/compiler.py b/frontend/db/backends/afe/compiler.py
new file mode 100644
index 00000000..99714155
--- /dev/null
+++ b/frontend/db/backends/afe/compiler.py
@@ -0,0 +1,32 @@
+from django.db.backends.mysql import compiler as mysql_compiler
+from autotest_lib.frontend.afe.model_logic import _quote_name
+
+class SQLCompiler(mysql_compiler.SQLCompiler):
+ def get_from_clause(self):
+ from_, params = super(SQLCompiler, self).get_from_clause()
+
+ if hasattr(self.query, "_custom_joins"):
+ for join_dict in self.query._custom_joins:
+ from_.append('%s %s AS %s ON (%s)'
+ % (join_dict['join_type'],
+ _quote_name(join_dict['table']),
+ _quote_name(join_dict['alias']),
+ join_dict['condition']))
+ params.extend(join_dict['condition_values'])
+
+ return from_, params
+
+class SQLInsertCompiler(mysql_compiler.SQLInsertCompiler, SQLCompiler):
+ pass
+
+class SQLDeleteCompiler(mysql_compiler.SQLDeleteCompiler, SQLCompiler):
+ pass
+
+class SQLUpdateCompiler(mysql_compiler.SQLUpdateCompiler, SQLCompiler):
+ pass
+
+class SQLAggregateCompiler(mysql_compiler.SQLAggregateCompiler, SQLCompiler):
+ pass
+
+class SQLDateCompiler(mysql_compiler.SQLDateCompiler, SQLCompiler):
+ pass
diff --git a/frontend/db/backends/afe/creation.py b/frontend/db/backends/afe/creation.py
new file mode 100644
index 00000000..955a11ed
--- /dev/null
+++ b/frontend/db/backends/afe/creation.py
@@ -0,0 +1 @@
+from django.db.backends.mysql.creation import *
diff --git a/frontend/db/backends/afe/introspection.py b/frontend/db/backends/afe/introspection.py
new file mode 100644
index 00000000..222bc9b8
--- /dev/null
+++ b/frontend/db/backends/afe/introspection.py
@@ -0,0 +1 @@
+from django.db.backends.mysql.introspection import *
diff --git a/frontend/db/backends/afe/validation.py b/frontend/db/backends/afe/validation.py
new file mode 100644
index 00000000..818b34ad
--- /dev/null
+++ b/frontend/db/backends/afe/validation.py
@@ -0,0 +1 @@
+from django.db.backends.mysql.validation import *