Factorized code for Eiffel Store + SQL CMS storage.

Revisited database schema to make it simpler for now, and shorter columns name.
See schema.sql under sqlite implementation
This commit is contained in:
2015-01-21 22:15:01 +01:00
parent d23cfbc300
commit db6afb6952
16 changed files with 614 additions and 361 deletions

View File

@@ -1,61 +0,0 @@
-- Creator: MySQL Workbench 6.1.7/ExportSQLite plugin 2009.12.02
-- Author: javier
-- Caption: New Model
-- Project: Name of the project
-- Changed: 2014-09-16 23:12
-- Created: 2014-09-16 23:12
PRAGMA foreign_keys = OFF;
-- Schema: cms_dev
BEGIN;
CREATE TABLE "nodes"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0),
"publication_date" DATE NOT NULL,
"creation_date" DATE NOT NULL,
"modification_date" DATE NOT NULL,
"title" VARCHAR(255) NOT NULL,
"summary" TEXT NOT NULL,
"content" MEDIUMTEXT NOT NULL
);
CREATE TABLE "roles"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0),
"role" VARCHAR(100) NOT NULL,
CONSTRAINT "role"
UNIQUE("role")
);
CREATE TABLE "users"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0),
"username" VARCHAR(100) NOT NULL,
"password" VARCHAR(100) NOT NULL,
"salt" VARCHAR(100) NOT NULL,
"email" VARCHAR(250) NOT NULL,
CONSTRAINT "username"
UNIQUE("username")
);
CREATE TABLE "users_nodes"(
"users_id" INTEGER NOT NULL CHECK("users_id">=0),
"nodes_id" INTEGER NOT NULL CHECK("nodes_id">=0),
PRIMARY KEY("users_id","nodes_id"),
CONSTRAINT "fk_users_has_nodes_nodes1"
FOREIGN KEY("nodes_id")
REFERENCES "nodes"("id"),
CONSTRAINT "fk_users_has_nodes_users"
FOREIGN KEY("users_id")
REFERENCES "users"("id")
);
CREATE INDEX "users_nodes.fk_users_has_nodes_nodes1_idx" ON "users_nodes"("nodes_id");
CREATE INDEX "users_nodes.fk_users_has_nodes_users_idx" ON "users_nodes"("users_id");
CREATE TABLE "users_roles"(
"users_id" INTEGER NOT NULL CHECK("users_id">=0),
"roles_id" INTEGER NOT NULL CHECK("roles_id">=0),
PRIMARY KEY("users_id","roles_id"),
CONSTRAINT "fk_users_has_roles_roles1"
FOREIGN KEY("roles_id")
REFERENCES "roles"("id"),
CONSTRAINT "fk_users_has_roles_users1"
FOREIGN KEY("users_id")
REFERENCES "users"("id")
);
CREATE INDEX "users_roles.fk_users_has_roles_roles1_idx" ON "users_roles"("roles_id");
CREATE INDEX "users_roles.fk_users_has_roles_users1_idx" ON "users_roles"("users_id");
COMMIT;

View File

@@ -0,0 +1,36 @@
PRAGMA foreign_keys = OFF;
BEGIN;
CREATE TABLE "users"(
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("uid">=0),
"name" VARCHAR(100) NOT NULL,
"password" VARCHAR(100) NOT NULL,
"salt" VARCHAR(100) NOT NULL,
"email" VARCHAR(250) NOT NULL,
"status" INTEGER,
"created" DATETIME NOT NULL,
"signed" DATETIME,
CONSTRAINT "name"
UNIQUE("name")
);
CREATE TABLE "users_roles"(
"rid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("rid">=0),
"role" VARCHAR(100) NOT NULL,
CONSTRAINT "role"
UNIQUE("role")
);
CREATE TABLE "nodes"(
"nid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("nid">=0),
"version" INTEGER,
"type" INTEGER,
"title" VARCHAR(255) NOT NULL,
"summary" TEXT NOT NULL,
"content" MEDIUMTEXT NOT NULL,
"author" INTEGER,
"publish" DATETIME,
"created" DATETIME NOT NULL,
"changed" DATETIME NOT NULL
);
COMMIT;

View File

@@ -1,14 +0,0 @@
DROP TABLE IF EXISTS nodes;
CREATE TABLE nodes
(
id smallint unsigned NOT NULL auto_increment,
publication_date date NOT NULL, #When the article was published
creation_date date NOT NULL, #When the article was created
modification_date date NOT NULL, #When the article was updated
title varchar(255) NOT NULL, #Full title of the article
summary text NOT NULL, #A short summary of the articule
content mediumtext NOT NULL, #The HTML content of the article
PRIMARY KEY (ID)
);

View File

@@ -9,6 +9,67 @@ deferred class
inherit
CMS_NODE_STORAGE_SQL
redefine
nodes, recent_nodes
end
feature {NONE} -- Implementation
db_handler: DATABASE_HANDLER
deferred
end
feature -- Access
nodes: LIST [CMS_NODE]
-- List of nodes.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
across nodes_iterator as ic loop
Result.force (ic.item)
end
end
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
-- List of recent `a_count' nodes with an offset of `lower'.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (a_count)
across recent_nodes_iterator (a_lower, a_count) as c loop
Result.force (c.item)
end
end
feature -- Access: iterator
nodes_iterator: DATABASE_ITERATION_CURSOR [CMS_NODE]
-- List of nodes.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".nodes_iterator")
create l_parameters.make (0)
sql_query (select_nodes, l_parameters)
sql_post_execution
create Result.make (db_handler, agent fetch_node)
end
recent_nodes_iterator (a_lower, a_rows: INTEGER): DATABASE_ITERATION_CURSOR [CMS_NODE]
-- The most recent `a_rows'.
local
l_parameters: STRING_TABLE [ANY]
l_query: STRING
do
-- FIXME: check implementation...
error_handler.reset
log.write_information (generator + ".recent_nodes_iterator")
create l_parameters.make (2)
l_parameters.put (a_rows, "rows")
l_parameters.put (a_lower, "offset")
create l_query.make_from_string (select_recent_nodes)
sql_query (l_query, l_parameters)
create Result.make (db_handler, agent fetch_node)
sql_post_execution
end
end

View File

@@ -8,6 +8,8 @@ class
inherit
CMS_STORAGE
CMS_STORAGE_STORE_SQL
CMS_USER_STORAGE_SQLITE
@@ -18,85 +20,93 @@ inherit
create
make
feature {NONE} -- Initialization
--feature {NONE} -- Initialization
make (a_connection: DATABASE_CONNECTION)
--
require
is_connected: a_connection.is_connected
do
connection := a_connection
log.write_information (generator + ".make_with_database is database connected? "+ a_connection.is_connected.out )
-- make (a_connection: DATABASE_CONNECTION)
-- --
-- require
-- is_connected: a_connection.is_connected
-- do
-- connection := a_connection
-- log.write_information (generator + ".make_with_database is database connected? "+ a_connection.is_connected.out )
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
-- create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
create error_handler.make
-- error_handler.add_synchronization (db_handler.database_error_handler)
end
-- create error_handler.make
---- error_handler.add_synchronization (db_handler.database_error_handler)
-- end
db_handler: DATABASE_HANDLER
-- db_handler: DATABASE_HANDLER
connection: DATABASE_CONNECTION
-- Current database connection.
-- connection: DATABASE_CONNECTION
-- -- Current database connection.
feature -- Access: user
--feature -- Access: user
sql_post_execution
-- Post database execution.
do
error_handler.append (db_handler.database_error_handler)
if error_handler.has_error then
log.write_critical (generator + ".post_execution " + error_handler.as_string_representation)
end
end
-- sql_post_execution
-- -- Post database execution.
-- do
-- error_handler.append (db_handler.database_error_handler)
-- if error_handler.has_error then
-- log.write_critical (generator + ".post_execution " + error_handler.as_string_representation)
-- end
-- end
sql_begin_transaction
do
connection.begin_transaction
end
-- sql_begin_transaction
-- do
-- connection.begin_transaction
-- end
sql_commit_transaction
do
connection.commit
end
-- sql_commit_transaction
-- do
-- connection.commit
-- end
sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
do
db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params))
db_handler.execute_query
end
-- sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
-- do
-- check_sql_query_validity (a_sql_statement, a_params)
-- db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params))
-- db_handler.execute_query
-- end
sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
do
db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params))
db_handler.execute_change
end
-- sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
-- do
-- check_sql_query_validity (a_sql_statement, a_params)
-- db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params))
-- db_handler.execute_change
-- end
sql_rows_count: INTEGER
-- Number of rows for last sql execution.
do
Result := db_handler.count
end
-- sql_rows_count: INTEGER
-- -- Number of rows for last sql execution.
-- do
-- Result := db_handler.count
-- end
sql_after: BOOLEAN
-- Are there no more items to iterate over?
do
Result := db_handler.after
end
-- sql_start
-- -- Set the cursor on first element.
-- do
-- db_handler.start
-- end
sql_forth
-- Fetch next row from last sql execution, if any.
do
db_handler.forth
end
-- sql_after: BOOLEAN
-- -- Are there no more items to iterate over?
-- do
-- Result := db_handler.after
-- end
sql_item (a_index: INTEGER): detachable ANY
do
if attached {DB_TUPLE} db_handler.item as l_item and then l_item.count >= a_index then
Result := l_item.item (a_index)
else
check has_item_at_index: False end
end
end
-- sql_forth
-- -- Fetch next row from last sql execution, if any.
-- do
-- db_handler.forth
-- end
-- sql_item (a_index: INTEGER): detachable ANY
-- do
-- if attached {DB_TUPLE} db_handler.item as l_item and then l_item.count >= a_index then
-- Result := l_item.item (a_index)
-- else
-- check has_item_at_index: False end
-- end
-- end
end