Added a common database backend implementation.
Added sqlite (proof of concept)
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
{
|
||||
"database": {
|
||||
"datasource": {
|
||||
"driver": "SQL Server",
|
||||
"environment": "test"
|
||||
"driver": "MySQL",
|
||||
"environment": "development"
|
||||
},
|
||||
"environments": {
|
||||
"test": {
|
||||
"connection_string":"Server=JVELILLA\\SQLEXPRESS;Database=example;Uid=sa;Pwd=Eiffel1405;TrustedConnection=Yes"
|
||||
"connection_string":"Server=localhost;Port=3306;Database=cms_dev;Uid=root;Pwd=;"
|
||||
},
|
||||
"development": {
|
||||
"connection_string":"Server=sql.ise;Database=ESA_DB_TEST;Uid=eiffel2;Pwd=eiffel2;"
|
||||
"connection_string":"Server=localhost;Port=3306;Database=cms;Uid=root;Pwd=;"
|
||||
},
|
||||
"production": {
|
||||
"connection_string":"Server=SQLSERVER;Database=LIVE_DATABASE;Uid=XXX;Pwd=YYY;"
|
||||
"connection_string":""
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -24,7 +24,7 @@
|
||||
"backup_count":"4"
|
||||
},
|
||||
"server": {
|
||||
"mode":"web"
|
||||
"mode":"api"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ feature -- Factory
|
||||
create l_email_service.make ((create {JSON_CONFIGURATION}).new_smtp_configuration(l_layout.application_config_path))
|
||||
|
||||
if attached (create {JSON_CONFIGURATION}).new_database_configuration (l_layout.application_config_path) as l_database_config then
|
||||
create {DATABASE_CONNECTION_MYSQL} l_database.login_with_schema ("cms", "root", "")
|
||||
create {DATABASE_CONNECTION_MYSQL} l_database.login_with_connection_string (l_database_config.connection_string)
|
||||
create l_api_service.make_with_database (l_database)
|
||||
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
||||
if (create {ROC_JSON_CONFIGURATION}).is_web_mode(l_layout.application_config_path) then
|
||||
|
||||
@@ -45,7 +45,4 @@ feature -- Access
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -72,6 +72,13 @@ feature -- Database Setup
|
||||
keep_connection: BOOLEAN
|
||||
-- Keep connection alive?
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
not_keep_connection
|
||||
do
|
||||
keep_connection := False
|
||||
end
|
||||
|
||||
feature -- Conection
|
||||
|
||||
connect
|
||||
@@ -0,0 +1,126 @@
|
||||
note
|
||||
description: "Object that handle a database connection for ODBC"
|
||||
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
|
||||
revision: "$Revision: 95678 $"
|
||||
|
||||
class
|
||||
DATABASE_CONNECTION_ODBC
|
||||
|
||||
inherit
|
||||
|
||||
DATABASE_CONNECTION
|
||||
redefine
|
||||
db_application
|
||||
end
|
||||
|
||||
create
|
||||
make, make_common, make_basic, login_with_connection_string
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make_common
|
||||
-- Create a database handler for ODBC with common settings.
|
||||
local
|
||||
l_retried: BOOLEAN
|
||||
do
|
||||
create db_application.login (username, password)
|
||||
|
||||
if not l_retried then
|
||||
db_application.set_hostname (hostname)
|
||||
db_application.set_data_source (database_name)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
keep_connection := is_keep_connection
|
||||
if keep_connection then
|
||||
connect
|
||||
end
|
||||
set_successful
|
||||
else
|
||||
create db_control.make
|
||||
end
|
||||
rescue
|
||||
create db_control.make
|
||||
set_last_error_from_exception ("Connection execution")
|
||||
log.write_critical (generator + ".make_common:" + last_error_message)
|
||||
if is_connected then
|
||||
disconnect
|
||||
end
|
||||
l_retried := True
|
||||
retry
|
||||
end
|
||||
|
||||
make_basic (a_database_name: STRING)
|
||||
-- Create a database handler and
|
||||
-- set database_name to `a_database_name'.
|
||||
local
|
||||
l_retried: BOOLEAN
|
||||
do
|
||||
create db_application.login (username, password)
|
||||
|
||||
if not l_retried then
|
||||
db_application.set_hostname (hostname)
|
||||
db_application.set_data_source (a_database_name)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
keep_connection := is_keep_connection
|
||||
if keep_connection then
|
||||
connect
|
||||
end
|
||||
set_successful
|
||||
else
|
||||
create db_control.make
|
||||
end
|
||||
rescue
|
||||
create db_control.make
|
||||
set_last_error_from_exception ("Connection execution")
|
||||
log.write_critical (generator + ".make_common:" + last_error_message)
|
||||
if is_connected then
|
||||
disconnect
|
||||
end
|
||||
l_retried := True
|
||||
retry
|
||||
end
|
||||
|
||||
make (a_username: STRING; a_password: STRING; a_hostname: STRING; a_database_name: STRING; connection: BOOLEAN)
|
||||
|
||||
-- Create a database handler for ODBC and set `username' to `a_username',
|
||||
-- `password' to `a_password'
|
||||
-- `database_name' to `a_database_name'
|
||||
-- `connection' to `a_connection'
|
||||
do
|
||||
create db_application.login (a_username, a_password)
|
||||
db_application.set_hostname (a_hostname)
|
||||
db_application.set_data_source (a_database_name)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
keep_connection := connection
|
||||
if keep_connection then
|
||||
connect
|
||||
end
|
||||
end
|
||||
|
||||
login_with_connection_string (a_string: STRING)
|
||||
-- Login with `a_connection_string'and immediately connect to database.
|
||||
do
|
||||
log.write_debug (generator +".login_with_connection_string")
|
||||
create db_application.login_with_connection_string (a_string)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
log.write_debug (generator +".login_with_connection_string, is_keep_connection? "+ is_keep_connection.out )
|
||||
keep_connection := is_keep_connection
|
||||
if keep_connection then
|
||||
connect
|
||||
if not db_control.is_ok then
|
||||
log.write_critical (generator +".login_with_connection_string:"+ db_control.error_code.out )
|
||||
log.write_critical (generator +".login_with_connection_string:"+ db_control.error_message_32 )
|
||||
end
|
||||
log.write_debug (generator +".login_with_connection_string, After connect, is_connected? "+ is_connected.out)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Databse Connection
|
||||
|
||||
db_application: DATABASE_APPL [ODBC]
|
||||
-- Database application.
|
||||
|
||||
end
|
||||
@@ -13,6 +13,7 @@
|
||||
<library name="layout" location="..\..\..\layout\layout.ecf"/>
|
||||
<library name="logging" location="$ISE_LIBRARY\library\runtime\logging\logging-safe.ecf"/>
|
||||
<library name="mysql" location="$ISE_LIBRARY\library\store\dbms\rdbms\mysql\mysql-safe.ecf"/>
|
||||
<library name="odbc" location="$ISE_LIBRARY\library\store\dbms\rdbms\odbc\odbc-safe.ecf"/>
|
||||
<library name="store" location="$ISE_LIBRARY\library\store\store-safe.ecf" readonly="false"/>
|
||||
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||
@@ -24,5 +25,6 @@
|
||||
</file_rule>
|
||||
</cluster>
|
||||
<cluster name="interface" location="..\..\interface\" recursive="true"/>
|
||||
<cluster name="common" location="..\common\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
note
|
||||
description: "Stored procedures paramters names"
|
||||
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
|
||||
revision: "$Revision: 95678 $"
|
||||
|
||||
class
|
||||
DATA_PARAMETERS_NAMES
|
||||
|
||||
feature -- Access
|
||||
|
||||
Contactid_param: STRING = "ContactID"
|
||||
|
||||
Username_param: STRING = "Username"
|
||||
|
||||
Submitter_username_param: STRING = "SubmitterUsername"
|
||||
|
||||
Responsibleid_param: STRING = "ResponsibleID"
|
||||
|
||||
Email_param: STRING = "Email"
|
||||
|
||||
Synopsis_param: STRING = "Synopsis"
|
||||
|
||||
Openonly_param: STRING = "OpenOnly"
|
||||
|
||||
Number_param: STRING = "Number"
|
||||
|
||||
Categoryid_param: STRING = "CategoryID"
|
||||
|
||||
Category_synopsis_param: STRING = "CategorySynopsis"
|
||||
|
||||
Statusid_param: STRING = "StatusID"
|
||||
|
||||
Private_param: STRING = "Private"
|
||||
|
||||
Priorityid_param: STRING = "PriorityID"
|
||||
|
||||
Severityid_param: STRING = "SeverityID"
|
||||
|
||||
Searchtext_param: STRING = "SearchText"
|
||||
|
||||
Searchsynopsis_param: STRING = "SearchSynopsis"
|
||||
|
||||
Searchdescription_param: STRING = "SearchDescription"
|
||||
|
||||
Reportid_param: STRING = "ReportID"
|
||||
|
||||
Interactionid_param: STRING = "InteractionID"
|
||||
|
||||
Attachmentid_param: STRING = "AttachmentID"
|
||||
|
||||
Fieldtitle_param: STRING = "FieldTitle"
|
||||
|
||||
Passwordhash_param: STRING = "PasswordHash"
|
||||
|
||||
Registrationtoken_param: STRING = "RegistrationToken"
|
||||
|
||||
Answerhash_param: STRING = "AnswerHash"
|
||||
|
||||
Classid_param: STRING = "Classid"
|
||||
|
||||
Confidential_param: STRING = "Confidential"
|
||||
|
||||
Release_param: STRING = "Release"
|
||||
|
||||
Environment_param: STRING = "Environment"
|
||||
|
||||
Description_param: STRING = "Description"
|
||||
|
||||
Toreproduce_param: STRING = "ToReproduce"
|
||||
|
||||
Content_param: STRING = "Content"
|
||||
|
||||
Alreadyexists_param: STRING = "AlreadyExists"
|
||||
|
||||
Firstname_param: STRING = "FirstName"
|
||||
|
||||
Lastname_param: STRING = "LastName"
|
||||
|
||||
Responsible_param: STRING = "Responsible"
|
||||
|
||||
Responsible_firstname_param: STRING = "ResponsibleFirstName"
|
||||
|
||||
Responsible_lastname_param: STRING = "ResponsibleLastName"
|
||||
|
||||
Length_param: STRING = "Length"
|
||||
|
||||
Filename_param: STRING = "Filename"
|
||||
|
||||
Position_param: STRING = "Position"
|
||||
|
||||
Address_param: STRING = "Address"
|
||||
|
||||
City_param: STRING = "City"
|
||||
|
||||
Country_param: STRING = "Country"
|
||||
|
||||
Region_param: STRING = "Region"
|
||||
|
||||
Code_param: STRING = "Code"
|
||||
|
||||
Tel_param: STRING = "Tel"
|
||||
|
||||
Fax_param: STRING = "Fax"
|
||||
|
||||
Name_param: STRING = "Name"
|
||||
|
||||
Url_param: STRING = "URL"
|
||||
|
||||
Token_param: STRING = "Token"
|
||||
|
||||
Filter_param: STRING = "Filter"
|
||||
|
||||
feature -- Login
|
||||
|
||||
Passwordsalt_param: STRING = "PasswordSalt"
|
||||
|
||||
Answersalt_param: STRING = "AnswerSalt"
|
||||
|
||||
Questionid_param: STRING = "QuestionID"
|
||||
|
||||
|
||||
feature -- Download Parameter Names
|
||||
|
||||
Subject_param: STRING = "Subject"
|
||||
|
||||
Notes_param: STRING = "Notes"
|
||||
|
||||
Platform_param: STRING = "Platform"
|
||||
|
||||
Newsletter_param: STRING = "Newsletter"
|
||||
|
||||
end
|
||||
@@ -101,21 +101,29 @@ feature -- Initialization
|
||||
|
||||
login_with_connection_string (a_string: STRING)
|
||||
-- Login with `a_connection_string'and immediately connect to database.
|
||||
local
|
||||
l_string: LIST[STRING]
|
||||
l_server: STRING
|
||||
l_port: STRING
|
||||
l_schema: STRING
|
||||
l_user: STRING
|
||||
l_password: STRING
|
||||
do
|
||||
log.write_debug (generator +".login_with_connection_string")
|
||||
create db_application.login_with_connection_string (a_string)
|
||||
l_string := a_string.split (';')
|
||||
l_server := l_string.at (2).split ('=').at (2)
|
||||
l_port := l_string.at (3).split ('=').at (2)
|
||||
l_schema := l_string.at (4).split ('=').at (2)
|
||||
l_user := l_string.at (5).split ('=').at (2)
|
||||
l_password := l_string.at (6).split ('=').at (2)
|
||||
|
||||
create db_application
|
||||
db_application.set_application (l_schema)
|
||||
db_application.set_hostname (l_server + ":" + l_port)
|
||||
db_application.login_and_connect (l_user, l_password)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
log.write_debug (generator +".login_with_connection_string, is_keep_connection? "+ is_keep_connection.out )
|
||||
keep_connection := is_keep_connection
|
||||
if keep_connection then
|
||||
connect
|
||||
if not db_control.is_ok then
|
||||
log.write_critical (generator +".login_with_connection_string:"+ db_control.error_code.out )
|
||||
log.write_critical (generator +".login_with_connection_string:"+ db_control.error_message_32 )
|
||||
end
|
||||
log.write_debug (generator +".login_with_connection_string, After connect, is_connected? "+ is_connected.out)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
login_with_schema (a_schema: STRING; a_username: STRING; a_password: STRING)
|
||||
|
||||
30
persistence/implementation/sqlite/persistence_sqlite.ecf
Normal file
30
persistence/implementation/sqlite/persistence_sqlite.ecf
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="persistence_sqlite" uuid="8FD9D3B3-5FC1-495F-A05D-0205EC966841" library_target="persistence_sqlite">
|
||||
<target name="persistence_sqlite">
|
||||
<root all_classes="true"/>
|
||||
<option warning="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="console_application" value="true"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
|
||||
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/>
|
||||
<library name="layout" location="..\..\..\layout\layout.ecf"/>
|
||||
<library name="logging" location="$ISE_LIBRARY\library\runtime\logging\logging-safe.ecf"/>
|
||||
<library name="mysql" location="$ISE_LIBRARY\library\store\dbms\rdbms\mysql\mysql-safe.ecf"/>
|
||||
<library name="odbc" location="$ISE_LIBRARY\library\store\dbms\rdbms\odbc\odbc-safe.ecf"/>
|
||||
<library name="store" location="$ISE_LIBRARY\library\store\store-safe.ecf" readonly="false"/>
|
||||
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||
<cluster name="common" location="..\common\" recursive="true"/>
|
||||
<cluster name="interface" location="..\..\interface\" recursive="true"/>
|
||||
<cluster name="persistence_sqlite" location=".\src\" recursive="true">
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
</file_rule>
|
||||
</cluster>
|
||||
</target>
|
||||
</system>
|
||||
1
persistence/implementation/sqlite/scripts/Readme.txt
Normal file
1
persistence/implementation/sqlite/scripts/Readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
Added Stored Procedures
|
||||
@@ -0,0 +1,61 @@
|
||||
-- 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;
|
||||
14
persistence/implementation/sqlite/scripts/tables.sql
Normal file
14
persistence/implementation/sqlite/scripts/tables.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
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)
|
||||
);
|
||||
218
persistence/implementation/sqlite/src/cms_storage_sqlite.e
Normal file
218
persistence/implementation/sqlite/src/cms_storage_sqlite.e
Normal file
@@ -0,0 +1,218 @@
|
||||
note
|
||||
description: "Summary description for {CMS_STORAGE_MYSQL}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_STORAGE_SQLITE
|
||||
|
||||
inherit
|
||||
|
||||
CMS_STORAGE
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_connection: DATABASE_CONNECTION)
|
||||
--
|
||||
require
|
||||
is_connected: a_connection.is_connected
|
||||
do
|
||||
log.write_information (generator+".make_with_database is database connected? "+ a_connection.is_connected.out )
|
||||
create node_provider.make (a_connection)
|
||||
create user_provider.make (a_connection)
|
||||
post_node_provider_execution
|
||||
post_user_provider_execution
|
||||
end
|
||||
|
||||
|
||||
feature -- Access: user
|
||||
|
||||
has_user: BOOLEAN
|
||||
-- Has any user?
|
||||
do
|
||||
Result := user_provider.has_user
|
||||
post_user_provider_execution
|
||||
end
|
||||
|
||||
|
||||
all_users: LIST [CMS_USER]
|
||||
do
|
||||
to_implement("Not implemented!!!")
|
||||
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
|
||||
end
|
||||
|
||||
user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER
|
||||
do
|
||||
Result := user_provider.user (a_id)
|
||||
post_user_provider_execution
|
||||
end
|
||||
|
||||
user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER
|
||||
do
|
||||
Result := user_provider.user_by_name (a_name)
|
||||
post_user_provider_execution
|
||||
end
|
||||
|
||||
user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER
|
||||
do
|
||||
Result := user_provider.user_by_email (a_email)
|
||||
post_user_provider_execution
|
||||
end
|
||||
|
||||
is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
|
||||
local
|
||||
l_security: SECURITY_PROVIDER
|
||||
do
|
||||
if attached user_provider.user_salt (l_auth_login) as l_hash then
|
||||
if attached user_provider.user_by_name (l_auth_login) as l_user then
|
||||
create l_security
|
||||
if
|
||||
attached l_user.password as l_password and then
|
||||
l_security.password_hash (l_auth_password, l_hash).is_case_insensitive_equal (l_password)
|
||||
then
|
||||
Result := True
|
||||
else
|
||||
log.write_information (generator + ".login_valid User: wrong username or password" )
|
||||
end
|
||||
else
|
||||
log.write_information (generator + ".login_valid User:" + l_auth_login + "does not exist" )
|
||||
end
|
||||
end
|
||||
post_user_provider_execution
|
||||
end
|
||||
|
||||
feature -- Change: user
|
||||
|
||||
save_user (a_user: CMS_USER)
|
||||
-- Add a new user `a_user'.
|
||||
do
|
||||
if
|
||||
attached a_user.password as l_password and then
|
||||
attached a_user.email as l_email
|
||||
then
|
||||
user_provider.new_user (a_user.name, l_password, l_email)
|
||||
else
|
||||
-- set error
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access: node
|
||||
|
||||
nodes: LIST[CMS_NODE]
|
||||
-- List of nodes.
|
||||
do
|
||||
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||
across node_provider.nodes as c loop
|
||||
Result.force (c.item)
|
||||
end
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
|
||||
-- List of the `a_count' most recent nodes, starting from `a_lower'.
|
||||
do
|
||||
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||
across node_provider.recent_nodes (a_lower,a_count) as c loop
|
||||
Result.force (c.item)
|
||||
end
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
node (a_id: INTEGER_64): detachable CMS_NODE
|
||||
--
|
||||
do
|
||||
Result := node_provider.node (a_id)
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
|
||||
feature -- Node
|
||||
|
||||
save_node (a_node: CMS_NODE)
|
||||
-- Add a new node
|
||||
do
|
||||
node_provider.new_node (a_node)
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
delete_node (a_id: INTEGER_64)
|
||||
do
|
||||
node_provider.delete_node (a_id)
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
update_node (a_node: CMS_NODE)
|
||||
do
|
||||
node_provider.update_node (a_node)
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
|
||||
do
|
||||
node_provider.update_node_title (a_id, a_title)
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
|
||||
do
|
||||
node_provider.update_node_summary (a_id, a_summary)
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
|
||||
do
|
||||
node_provider.update_node_content (a_id, a_content)
|
||||
post_node_provider_execution
|
||||
end
|
||||
|
||||
|
||||
feature -- User
|
||||
|
||||
new_user (a_user: CMS_USER)
|
||||
-- Add a new user `a_user'.
|
||||
do
|
||||
if
|
||||
attached a_user.password as l_password and then
|
||||
attached a_user.email as l_email
|
||||
then
|
||||
user_provider.new_user (a_user.name, l_password, l_email)
|
||||
else
|
||||
-- set error
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Post process
|
||||
|
||||
post_node_provider_execution
|
||||
do
|
||||
if node_provider.successful then
|
||||
set_successful
|
||||
else
|
||||
if attached node_provider.last_error then
|
||||
set_last_error_from_handler (node_provider.last_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
post_user_provider_execution
|
||||
do
|
||||
if user_provider.successful then
|
||||
set_successful
|
||||
else
|
||||
if attached user_provider.last_error then
|
||||
set_last_error_from_handler (user_provider.last_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
node_provider: NODE_DATA_PROVIDER
|
||||
-- Node Data provider.
|
||||
|
||||
user_provider: USER_DATA_PROVIDER
|
||||
-- User Data provider.
|
||||
|
||||
end
|
||||
@@ -0,0 +1,145 @@
|
||||
note
|
||||
description: "Object that handle a database connection for ODBC"
|
||||
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
|
||||
revision: "$Revision: 95678 $"
|
||||
|
||||
class
|
||||
DATABASE_CONNECTION_MYSQL
|
||||
|
||||
inherit
|
||||
|
||||
DATABASE_CONNECTION
|
||||
redefine
|
||||
db_application
|
||||
end
|
||||
|
||||
create
|
||||
make, make_common, make_basic, login_with_connection_string, login_with_schema
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make_common
|
||||
-- Create a database handler for MYSQL with common settings.
|
||||
local
|
||||
l_retried: BOOLEAN
|
||||
do
|
||||
create db_application.login (username, password)
|
||||
|
||||
if not l_retried then
|
||||
db_application.set_hostname (hostname)
|
||||
db_application.set_data_source (database_name)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
keep_connection := is_keep_connection
|
||||
if keep_connection then
|
||||
connect
|
||||
end
|
||||
set_successful
|
||||
else
|
||||
create db_control.make
|
||||
end
|
||||
rescue
|
||||
create db_control.make
|
||||
set_last_error_from_exception ("Connection execution")
|
||||
log.write_critical (generator + ".make_common:" + last_error_message)
|
||||
if is_connected then
|
||||
disconnect
|
||||
end
|
||||
l_retried := True
|
||||
retry
|
||||
end
|
||||
|
||||
make_basic (a_database_name: STRING)
|
||||
-- Create a database handler and
|
||||
-- set database_name to `a_database_name'.
|
||||
local
|
||||
l_retried: BOOLEAN
|
||||
do
|
||||
create db_application.login (username, password)
|
||||
|
||||
if not l_retried then
|
||||
db_application.set_hostname (hostname)
|
||||
db_application.set_data_source (a_database_name)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
keep_connection := is_keep_connection
|
||||
if keep_connection then
|
||||
connect
|
||||
end
|
||||
set_successful
|
||||
else
|
||||
create db_control.make
|
||||
end
|
||||
rescue
|
||||
create db_control.make
|
||||
set_last_error_from_exception ("Connection execution")
|
||||
log.write_critical (generator + ".make_common:" + last_error_message)
|
||||
if is_connected then
|
||||
disconnect
|
||||
end
|
||||
l_retried := True
|
||||
retry
|
||||
end
|
||||
|
||||
make (a_username: STRING; a_password: STRING; a_hostname: STRING; a_database_name: STRING; connection: BOOLEAN)
|
||||
|
||||
-- Create a database handler for ODBC and set `username' to `a_username',
|
||||
-- `password' to `a_password'
|
||||
-- `database_name' to `a_database_name'
|
||||
-- `connection' to `a_connection'
|
||||
do
|
||||
create db_application.login (a_username, a_password)
|
||||
db_application.set_hostname (a_hostname)
|
||||
db_application.set_data_source (a_database_name)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
keep_connection := connection
|
||||
if keep_connection then
|
||||
connect
|
||||
end
|
||||
end
|
||||
|
||||
login_with_connection_string (a_string: STRING)
|
||||
-- Login with `a_connection_string'and immediately connect to database.
|
||||
local
|
||||
l_string: LIST[STRING]
|
||||
l_server: STRING
|
||||
l_port: STRING
|
||||
l_schema: STRING
|
||||
l_user: STRING
|
||||
l_password: STRING
|
||||
do
|
||||
l_string := a_string.split (';')
|
||||
l_server := l_string.at (2).split ('=').at (2)
|
||||
l_port := l_string.at (3).split ('=').at (2)
|
||||
l_schema := l_string.at (4).split ('=').at (2)
|
||||
l_user := l_string.at (5).split ('=').at (2)
|
||||
l_password := l_string.at (6).split ('=').at (2)
|
||||
|
||||
create db_application
|
||||
db_application.set_application (l_schema)
|
||||
db_application.set_hostname (l_server + ":" + l_port)
|
||||
db_application.login_and_connect (l_user, l_password)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
keep_connection := is_keep_connection
|
||||
|
||||
end
|
||||
|
||||
login_with_schema (a_schema: STRING; a_username: STRING; a_password: STRING)
|
||||
-- Login with `a_connection_string'and immediately connect to database.
|
||||
do
|
||||
create db_application
|
||||
db_application.set_application (a_schema)
|
||||
db_application.login_and_connect (a_username, a_password)
|
||||
db_application.set_base
|
||||
create db_control.make
|
||||
keep_connection := is_keep_connection
|
||||
end
|
||||
|
||||
feature -- Databse Connection
|
||||
|
||||
db_application: DATABASE_APPL [MYSQL]
|
||||
-- Database application.
|
||||
|
||||
end
|
||||
@@ -0,0 +1,289 @@
|
||||
note
|
||||
description: "Database access for node uses cases."
|
||||
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
|
||||
revision: "$Revision: 95678 $"
|
||||
|
||||
class
|
||||
NODE_DATA_PROVIDER
|
||||
|
||||
inherit
|
||||
|
||||
PARAMETER_NAME_HELPER
|
||||
|
||||
SHARED_ERROR
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (a_connection: DATABASE_CONNECTION)
|
||||
-- Create a data provider.
|
||||
do
|
||||
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
|
||||
post_execution
|
||||
end
|
||||
|
||||
db_handler: DATABASE_HANDLER
|
||||
-- Db handler.
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
is_successful: BOOLEAN
|
||||
-- Is the last execution sucessful?
|
||||
do
|
||||
Result := db_handler.successful
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
nodes: DATABASE_ITERATION_CURSOR [CMS_NODE]
|
||||
-- List of nodes.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".nodes")
|
||||
create l_parameters.make (0)
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_nodes, l_parameters))
|
||||
db_handler.execute_query
|
||||
create Result.make (db_handler, agent fetch_node)
|
||||
post_execution
|
||||
end
|
||||
|
||||
recent_nodes (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
|
||||
log.write_information (generator + ".recent_nodes")
|
||||
create l_parameters.make (2)
|
||||
l_parameters.put (a_rows, "rows")
|
||||
create l_query.make_from_string (select_recent_nodes)
|
||||
l_query.replace_substring_all ("$offset", a_lower.out)
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (l_query, l_parameters))
|
||||
db_handler.execute_query
|
||||
create Result.make (db_handler, agent fetch_node)
|
||||
post_execution
|
||||
end
|
||||
|
||||
node (a_id: INTEGER_64): detachable CMS_NODE
|
||||
-- Node for the given id `a_id', if any.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".node")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_id,"id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_node_by_id, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := fetch_node
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
count: INTEGER
|
||||
-- Number of items nodes.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".count")
|
||||
create l_parameters.make (0)
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := db_handler.read_integer_32 (1)
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
new_node (a_node: CMS_NODE)
|
||||
-- Create a new node.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".new_node")
|
||||
create l_parameters.make (6)
|
||||
l_parameters.put (a_node.title, "title")
|
||||
l_parameters.put (a_node.summary, "summary")
|
||||
l_parameters.put (a_node.content, "content")
|
||||
l_parameters.put (a_node.publication_date, "publication_date")
|
||||
l_parameters.put (a_node.creation_date, "creation_date")
|
||||
l_parameters.put (a_node.modification_date, "modification_date")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_node, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
|
||||
-- Update node title for the corresponding the report with id `a_id'.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".update_node_title")
|
||||
create l_parameters.make (3)
|
||||
l_parameters.put (a_title, "title")
|
||||
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
|
||||
l_parameters.put (a_id, "id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_title, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
|
||||
-- Update node summary for the corresponding the report with id `a_id'.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".update_node_summary")
|
||||
create l_parameters.make (3)
|
||||
l_parameters.put (a_summary, "summary")
|
||||
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
|
||||
l_parameters.put (a_id, "id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_summary, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
|
||||
-- Update node content for the corresponding the report with id `a_id'.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".update_node_content")
|
||||
create l_parameters.make (3)
|
||||
l_parameters.put (a_content, "content")
|
||||
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
|
||||
l_parameters.put (a_id, "id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_content, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
update_node (a_node: CMS_NODE)
|
||||
-- Update node.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".update_node")
|
||||
create l_parameters.make (7)
|
||||
l_parameters.put (a_node.title, "title")
|
||||
l_parameters.put (a_node.summary, "summary")
|
||||
l_parameters.put (a_node.content, "content")
|
||||
l_parameters.put (a_node.publication_date, "publication_date")
|
||||
l_parameters.put (a_node.creation_date, "creation_date")
|
||||
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
|
||||
l_parameters.put (a_node.id, "id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
delete_node (a_id: INTEGER_64;)
|
||||
-- Delete node with id `a_id'.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".delete_node")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_id, "id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_delete_node, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
feature -- Connection
|
||||
|
||||
connect
|
||||
-- Connect to the database.
|
||||
do
|
||||
if not db_handler.is_connected then
|
||||
db_handler.connect
|
||||
end
|
||||
end
|
||||
|
||||
disconnect
|
||||
-- Disconnect to the database.
|
||||
do
|
||||
if db_handler.is_connected then
|
||||
db_handler.disconnect
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Queries
|
||||
|
||||
Select_count: STRING = "select count(*) from Nodes;"
|
||||
|
||||
Select_nodes: STRING = "select * from Nodes;"
|
||||
-- SQL Query to retrieve all nodes.
|
||||
|
||||
Select_node_by_id: STRING = "select * from Nodes where id =:id order by id desc, publication_date desc;"
|
||||
|
||||
Select_recent_nodes: STRING = "select * from Nodes order by id desc, publication_date desc Limit $offset , :rows "
|
||||
|
||||
SQL_Insert_node: STRING = "insert into nodes (title, summary, content, publication_date, creation_date, modification_date) values (:title, :summary, :content, :publication_date, :creation_date, :modification_date);"
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
SQL_Update_node_title: STRING ="update nodes SET title=:title, modification_date=:modification_date where id=:id;"
|
||||
-- SQL update node title.
|
||||
|
||||
SQL_Update_node_summary: STRING ="update nodes SET summary=:summary, modification_date=:modification_date where id=:id;"
|
||||
-- SQL update node summary.
|
||||
|
||||
SQL_Update_node_content: STRING ="update nodes SET content=:content, modification_date=:modification_date where id=:id;"
|
||||
-- SQL node content.
|
||||
|
||||
SQL_Update_node : STRING = "update nodes SET title=:title, summary=:summary, content=:content, publication_date=:publication_date, creation_date=:creation_date, modification_date=:modification_date where id=:id;"
|
||||
-- SQL node.
|
||||
|
||||
SQL_Delete_node: STRING = "delete from nodes where id=:id;"
|
||||
|
||||
|
||||
feature -- New Object
|
||||
|
||||
fetch_node: CMS_NODE
|
||||
do
|
||||
create Result.make ("", "", "")
|
||||
if attached db_handler.read_integer_32 (1) as l_id then
|
||||
Result.set_id (l_id)
|
||||
end
|
||||
if attached db_handler.read_date_time (2) as l_pd then
|
||||
Result.set_publication_date (l_pd)
|
||||
end
|
||||
if attached db_handler.read_date_time (3) as l_cd then
|
||||
Result.set_creation_date (l_cd)
|
||||
end
|
||||
if attached db_handler.read_date_time (4) as l_md then
|
||||
Result.set_modification_date (l_md)
|
||||
end
|
||||
if attached db_handler.read_string (5) as l_t then
|
||||
Result.set_title (l_t)
|
||||
end
|
||||
if attached db_handler.read_string (6) as l_s then
|
||||
Result.set_summary (l_s)
|
||||
end
|
||||
if attached db_handler.read_string (7) as l_c then
|
||||
Result.set_content (l_c)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
post_execution
|
||||
-- Post database execution.
|
||||
do
|
||||
if db_handler.successful then
|
||||
set_successful
|
||||
else
|
||||
if attached db_handler.last_error then
|
||||
set_last_error_from_handler (db_handler.last_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,206 @@
|
||||
note
|
||||
description: "Summary description for {USER_DATA_PROVIDER}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
USER_DATA_PROVIDER
|
||||
|
||||
inherit
|
||||
|
||||
PARAMETER_NAME_HELPER
|
||||
|
||||
SHARED_ERROR
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (a_connection: DATABASE_CONNECTION)
|
||||
-- Create a data provider.
|
||||
do
|
||||
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
|
||||
post_execution
|
||||
end
|
||||
|
||||
db_handler: DATABASE_HANDLER
|
||||
-- Db handler.
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
is_successful: BOOLEAN
|
||||
-- Is the last execution sucessful?
|
||||
do
|
||||
Result := db_handler.successful
|
||||
end
|
||||
|
||||
has_user: BOOLEAN
|
||||
-- Has any user?
|
||||
do
|
||||
Result := count > 0
|
||||
end
|
||||
|
||||
feature -- Basic Operations
|
||||
|
||||
new_user (a_user_name: READABLE_STRING_32; a_password: READABLE_STRING_32; a_email: READABLE_STRING_32)
|
||||
-- Create a new node.
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_password_salt, l_password_hash: STRING
|
||||
l_security: SECURITY_PROVIDER
|
||||
do
|
||||
create l_security
|
||||
l_password_salt := l_security.salt
|
||||
l_password_hash := l_security.password_hash (a_password, l_password_salt)
|
||||
|
||||
log.write_information (generator + ".new_user")
|
||||
create l_parameters.make (4)
|
||||
l_parameters.put (a_user_name,"username")
|
||||
l_parameters.put (l_password_hash,"password")
|
||||
l_parameters.put (l_password_salt,"salt")
|
||||
l_parameters.put (a_email,"email")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_user, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
user (a_id: INTEGER_64): detachable CMS_USER
|
||||
-- User for the given id `a_id', if any.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".user")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_id,"id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_id, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := fetch_user
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
user_by_name (a_name: READABLE_STRING_32): detachable CMS_USER
|
||||
-- User for the given name `a_name', if any.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".user_by_name")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_name,"name")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_name, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := fetch_user
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
|
||||
user_by_email (a_email: detachable READABLE_STRING_32): detachable CMS_USER
|
||||
-- User for the given email `a_email', if any.
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
log.write_information (generator + ".user_by_email")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_email,"email")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_email, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := fetch_user
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
user_salt (a_username: READABLE_STRING_32): detachable READABLE_STRING_32
|
||||
-- User salt for the given user `a_username', if any.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".user_salt")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_username,"name")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_salt_by_username, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
if attached db_handler.read_string (1) as l_salt then
|
||||
Result := l_salt.as_string_32
|
||||
end
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
count: INTEGER
|
||||
-- Number of items users.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".count")
|
||||
create l_parameters.make (0)
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := db_handler.read_integer_32 (1)
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
feature -- New Object
|
||||
|
||||
fetch_user: CMS_USER
|
||||
do
|
||||
create Result.make ("")
|
||||
if attached db_handler.read_integer_32 (1) as l_id then
|
||||
Result.set_id (l_id)
|
||||
end
|
||||
if attached db_handler.read_string (2) as l_u then
|
||||
Result.set_name (l_u)
|
||||
end
|
||||
if attached db_handler.read_string (3) as l_p then
|
||||
Result.set_password (l_p)
|
||||
end
|
||||
if attached db_handler.read_string (5) as l_e then
|
||||
Result.set_email (l_e)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Sql Queries
|
||||
|
||||
Select_count: STRING = "select count(*) from Users;"
|
||||
-- Number of users.
|
||||
|
||||
Select_user_by_id: STRING = "select * from Users where id =:id;"
|
||||
-- Retrieve user by id if exists.
|
||||
|
||||
Select_user_by_name: STRING = "select * from Users where username =:name;"
|
||||
-- Retrieve user by name if exists.
|
||||
|
||||
Select_user_by_email: STRING = "select * from Users where email =:email;"
|
||||
-- Retrieve user by email if exists.
|
||||
|
||||
Select_salt_by_username: STRING = "select salt from Users where username =:name;"
|
||||
-- Retrieve salt by username if exists.
|
||||
|
||||
SQL_Insert_user: STRING = "insert into users (username, password, salt, email) values (:username, :password, :salt, :email);"
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
post_execution
|
||||
-- Post database execution.
|
||||
do
|
||||
if db_handler.successful then
|
||||
set_successful
|
||||
else
|
||||
if attached db_handler.last_error then
|
||||
set_last_error_from_handler (db_handler.last_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
31
persistence/implementation/sqlite/tests/application.e
Normal file
31
persistence/implementation/sqlite/tests/application.e
Normal file
@@ -0,0 +1,31 @@
|
||||
note
|
||||
description : "tests application root class"
|
||||
date : "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
|
||||
revision : "$Revision: 95678 $"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
ARGUMENTS
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Run application.
|
||||
local
|
||||
user: USER_DATA_PROVIDER
|
||||
node: NODE_DATA_PROVIDER
|
||||
l_security: SECURITY_PROVIDER
|
||||
do
|
||||
create connection.make_basic ("cms_dev")
|
||||
create user.make (connection)
|
||||
user.new_user ("test", "test", "test")
|
||||
end
|
||||
|
||||
connection: DATABASE_CONNECTION_ODBC
|
||||
|
||||
end
|
||||
225
persistence/implementation/sqlite/tests/nodes/node_test_set.e
Normal file
225
persistence/implementation/sqlite/tests/nodes/node_test_set.e
Normal file
@@ -0,0 +1,225 @@
|
||||
note
|
||||
description: "[
|
||||
Eiffel tests that can be executed by testing tool.
|
||||
]"
|
||||
author: "EiffelStudio test wizard"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
testing: "type/manual"
|
||||
|
||||
class
|
||||
NODE_TEST_SET
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare,
|
||||
on_clean
|
||||
select
|
||||
default_create
|
||||
end
|
||||
ABSTRACT_DB_TEST
|
||||
rename
|
||||
default_create as default_db_test
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
-- <Precursor>
|
||||
do
|
||||
(create {CLEAN_DB}).clean_db(connection)
|
||||
assert ("Empty Nodes", node_provider.nodes.after)
|
||||
end
|
||||
|
||||
on_clean
|
||||
-- <Precursor>
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_new_node
|
||||
do
|
||||
assert ("Empty Nodes", node_provider.nodes.after)
|
||||
node_provider.new_node (default_node)
|
||||
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
|
||||
-- Exist node with id 1
|
||||
assert ("Exist node with id 1", attached node_provider.node (1))
|
||||
-- Not exist node with id 2
|
||||
assert ("Not exist node with id 2", node_provider.node (2) = Void)
|
||||
end
|
||||
|
||||
|
||||
test_update_node
|
||||
local
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
assert ("Empty Nodes", node_provider.nodes.after)
|
||||
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
|
||||
node_provider.new_node (l_node)
|
||||
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
|
||||
-- Exist node with id 1
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
|
||||
|
||||
-- Update node (content and summary)
|
||||
|
||||
if attached {CMS_NODE} node_provider.node (1) as l_un then
|
||||
l_un.set_content ("<h1>Updating test node udpate </h1>")
|
||||
l_un.set_summary ("updating summary")
|
||||
node_provider.update_node (l_un)
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title )
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
|
||||
end
|
||||
|
||||
-- Update node (content and summary and title)
|
||||
if attached {CMS_NODE} node_provider.node (1) as l_un then
|
||||
l_un.set_content ("<h1>Updating test node udpate </h1>")
|
||||
l_un.set_summary ("updating summary")
|
||||
l_un.set_title ("Updating Test case")
|
||||
node_provider.update_node (l_un)
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) )
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
|
||||
end
|
||||
end
|
||||
|
||||
test_update_title
|
||||
local
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
assert ("Empty Nodes", node_provider.nodes.after)
|
||||
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
|
||||
node_provider.new_node (l_node)
|
||||
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
|
||||
-- Exist node with id 1
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
|
||||
|
||||
-- Update node title
|
||||
|
||||
if attached {CMS_NODE} node_provider.node (1) as l_un then
|
||||
node_provider.update_node_title (l_un.id, "New Title")
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" )
|
||||
end
|
||||
end
|
||||
|
||||
test_update_summary
|
||||
local
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
assert ("Empty Nodes", node_provider.nodes.after)
|
||||
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
|
||||
node_provider.new_node (l_node)
|
||||
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
|
||||
-- Exist node with id 1
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
|
||||
|
||||
-- Update node summary
|
||||
|
||||
if attached {CMS_NODE} node_provider.node (1) as l_un then
|
||||
node_provider.update_node_summary (l_un.id,"New Summary")
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title)
|
||||
end
|
||||
end
|
||||
|
||||
test_update_content
|
||||
local
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
assert ("Empty Nodes", node_provider.nodes.after)
|
||||
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
|
||||
node_provider.new_node (l_node)
|
||||
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
|
||||
-- Exist node with id 1
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
|
||||
|
||||
-- Update node content
|
||||
|
||||
if attached {CMS_NODE} node_provider.node (1) as l_un then
|
||||
node_provider.update_node_content (l_un.id,"New Content")
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
test_delete_node
|
||||
local
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
assert ("Empty Nodes", node_provider.nodes.after)
|
||||
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
|
||||
node_provider.new_node (l_node)
|
||||
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
|
||||
-- Exist node with id 1
|
||||
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
|
||||
|
||||
-- Delte node 1
|
||||
|
||||
node_provider.delete_node (1)
|
||||
assert ("Node does not exist", node_provider.node (1) = Void)
|
||||
end
|
||||
|
||||
test_recent_nodes
|
||||
-- Content_10, Summary_10, Title_10
|
||||
-- Content_9, Summary_9, Title_9
|
||||
-- ..
|
||||
-- Content_1, Summary_1, Title_1
|
||||
local
|
||||
i : INTEGER
|
||||
do
|
||||
assert ("Empty Nodes", node_provider.nodes.after)
|
||||
across 1 |..| 10 as c loop
|
||||
node_provider.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
|
||||
end
|
||||
|
||||
-- Scenario (0,10) rows, recents (10 down to 1)
|
||||
i := 10
|
||||
across node_provider.recent_nodes (0, 10) as c loop
|
||||
assert ("Same id:" + i.out, c.item.id = i)
|
||||
i := i - 1
|
||||
end
|
||||
|
||||
-- Scenario (5, 10) rows, recent nodes (5 down to 1)
|
||||
i := 5
|
||||
across node_provider.recent_nodes (5, 10) as c loop
|
||||
assert ("Same id:" + i.out, c.item.id = i)
|
||||
i := i - 1
|
||||
end
|
||||
|
||||
-- Scenario (9,10) rows, recent node 1
|
||||
i := 1
|
||||
across node_provider.recent_nodes (9, 10) as c loop
|
||||
assert ("Same id:" + i.out, c.item.id = i)
|
||||
i := i - 1
|
||||
end
|
||||
|
||||
-- Scenrario 10..10 empty
|
||||
assert ("Empty", node_provider.recent_nodes (10, 10).after)
|
||||
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
node_provider: NODE_DATA_PROVIDER
|
||||
-- node provider.
|
||||
once
|
||||
create Result.make (connection)
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- Implementation Fixture Factories
|
||||
|
||||
default_node: CMS_NODE
|
||||
do
|
||||
Result := custom_node ("Default content", "default summary", "Default")
|
||||
end
|
||||
|
||||
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
|
||||
do
|
||||
create Result.make (a_content, a_summary, a_title)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
note
|
||||
description: "Summary description for {STORAGE_TEST_SET}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
STORAGE_TEST_SET
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare,
|
||||
on_clean
|
||||
select
|
||||
default_create
|
||||
end
|
||||
ABSTRACT_DB_TEST
|
||||
rename
|
||||
default_create as default_db_test
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
-- <Precursor>
|
||||
do
|
||||
(create {CLEAN_DB}).clean_db(connection)
|
||||
end
|
||||
|
||||
on_clean
|
||||
-- <Precursor>
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_has_user
|
||||
do
|
||||
assert ("Not has user", not storage.has_user)
|
||||
end
|
||||
|
||||
test_all_users
|
||||
do
|
||||
assert ("to implement all_users", False)
|
||||
end
|
||||
|
||||
test_user_by_id_not_exist
|
||||
do
|
||||
assert ("User does not exist", storage.user_by_id (1) = Void)
|
||||
end
|
||||
|
||||
test_user_by_name_not_exist
|
||||
do
|
||||
assert ("User does not exist", storage.user_by_name ("test") = Void)
|
||||
end
|
||||
|
||||
test_user_by_email_not_exist
|
||||
do
|
||||
assert ("User does not exist", storage.user_by_name ("test@test.com") = Void)
|
||||
end
|
||||
|
||||
test_user_with_bad_id
|
||||
local
|
||||
l_retry: BOOLEAN
|
||||
l_user: detachable CMS_USER
|
||||
do
|
||||
if not l_retry then
|
||||
l_user := storage.user_by_id (0)
|
||||
assert ("Precondition does not get the wrong value", False)
|
||||
else
|
||||
assert ("Expected precondition violation", True)
|
||||
end
|
||||
rescue
|
||||
l_retry := True
|
||||
retry
|
||||
end
|
||||
|
||||
test_user_with_bad_name_empty
|
||||
local
|
||||
l_retry: BOOLEAN
|
||||
l_user: detachable CMS_USER
|
||||
do
|
||||
if not l_retry then
|
||||
l_user := storage.user_by_name ("")
|
||||
assert ("Precondition does not get the wrong value", False)
|
||||
else
|
||||
assert ("Expected precondition violation", True)
|
||||
end
|
||||
rescue
|
||||
l_retry := True
|
||||
retry
|
||||
end
|
||||
|
||||
test_user_with_bad_email_empty
|
||||
local
|
||||
l_retry: BOOLEAN
|
||||
l_user: detachable CMS_USER
|
||||
do
|
||||
if not l_retry then
|
||||
l_user := storage.user_by_email ("")
|
||||
assert ("Precondition does not get the wrong value", False)
|
||||
else
|
||||
assert ("Expected precondition violation", True)
|
||||
end
|
||||
rescue
|
||||
l_retry := True
|
||||
retry
|
||||
end
|
||||
|
||||
test_save_user
|
||||
do
|
||||
storage.save_user (default_user)
|
||||
assert ("Has user", storage.has_user)
|
||||
end
|
||||
|
||||
test_user_by_id
|
||||
do
|
||||
storage.save_user (default_user)
|
||||
assert ("Has user", storage.has_user)
|
||||
if attached {CMS_USER} storage.user_by_id (1) as l_user then
|
||||
assert ("Exist", True)
|
||||
assert ("User test", l_user.name ~ "test")
|
||||
assert ("User id = 1", l_user.id = 1)
|
||||
else
|
||||
assert ("Wrong Implementation", False)
|
||||
end
|
||||
end
|
||||
|
||||
test_user_by_name
|
||||
do
|
||||
storage.save_user (default_user)
|
||||
assert ("Has user", storage.has_user)
|
||||
if attached {CMS_USER} storage.user_by_name ("test") as l_user then
|
||||
assert ("Exist", True)
|
||||
assert ("User nane: test", l_user.name ~ "test")
|
||||
else
|
||||
assert ("Wrong Implementation", False)
|
||||
end
|
||||
end
|
||||
|
||||
test_user_by_email
|
||||
do
|
||||
storage.save_user (default_user)
|
||||
assert ("Has user", storage.has_user)
|
||||
if attached {CMS_USER} storage.user_by_email ("test@test.com") as l_user then
|
||||
assert ("Exist", True)
|
||||
assert ("User email: test@test.com", l_user.email ~ "test@test.com")
|
||||
else
|
||||
assert ("Wrong Implementation", False)
|
||||
end
|
||||
end
|
||||
|
||||
test_invalid_credential
|
||||
do
|
||||
storage.save_user (default_user)
|
||||
assert ("Has user test", attached storage.user_by_name ("test"))
|
||||
assert ("Wrong password", not storage.is_valid_credential ("test", "test"))
|
||||
assert ("Wrong user", not storage.is_valid_credential ("test1", "test"))
|
||||
end
|
||||
|
||||
test_valid_credential
|
||||
do
|
||||
storage.save_user (default_user)
|
||||
assert ("Has user test", attached storage.user_by_name ("test"))
|
||||
assert ("Valid password", storage.is_valid_credential ("test", "password"))
|
||||
end
|
||||
|
||||
test_recent_nodes_empty
|
||||
do
|
||||
assert ("No recent nodes", storage.recent_nodes (0, 10).is_empty)
|
||||
end
|
||||
|
||||
test_recent_nodes
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
do
|
||||
across 1 |..| 10 as c loop
|
||||
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
|
||||
end
|
||||
l_nodes := storage.recent_nodes (0, 10)
|
||||
assert ("10 recent nodes", l_nodes.count = 10)
|
||||
assert ("First node id=10", l_nodes.first.id = 10)
|
||||
assert ("Last node id=1", l_nodes.last.id = 1)
|
||||
|
||||
|
||||
l_nodes := storage.recent_nodes (5, 10)
|
||||
assert ("5 recent nodes", l_nodes.count = 5)
|
||||
assert ("First node id=5", l_nodes.first.id = 5)
|
||||
assert ("Last node id=1", l_nodes.last.id = 1)
|
||||
|
||||
l_nodes := storage.recent_nodes (9, 10)
|
||||
assert ("1 recent nodes", l_nodes.count = 1)
|
||||
assert ("First node id=1", l_nodes.first.id = 1)
|
||||
assert ("Last node id=1", l_nodes.last.id = 1)
|
||||
|
||||
l_nodes := storage.recent_nodes (10, 10)
|
||||
assert ("Is empty", l_nodes.is_empty)
|
||||
end
|
||||
|
||||
test_node_does_not_exist
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
do
|
||||
across 1 |..| 10 as c loop
|
||||
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
|
||||
end
|
||||
assert ("Not exist node id: 12", storage.node (12) = Void)
|
||||
end
|
||||
|
||||
test_node
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
do
|
||||
across 1 |..| 10 as c loop
|
||||
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
|
||||
end
|
||||
assert ("Node id: 10", attached storage.node (10) as l_node and then l_node.title ~ "Title_10" )
|
||||
end
|
||||
|
||||
test_update_node
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
storage.save_node (custom_node ("Content", "Summary", "Title"))
|
||||
if attached {CMS_NODE} storage.node (1) as ll_node then
|
||||
l_node := ll_node.twin
|
||||
l_node.set_content ("New Content")
|
||||
l_node.set_summary ("New Summary")
|
||||
l_node.set_title("New Title")
|
||||
|
||||
storage.update_node (l_node)
|
||||
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
|
||||
end
|
||||
end
|
||||
|
||||
test_update_node_title
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
storage.save_node (custom_node ("Content", "Summary", "Title"))
|
||||
if attached {CMS_NODE} storage.node (1) as ll_node then
|
||||
storage.update_node_title (ll_node.id, "New Title")
|
||||
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
|
||||
end
|
||||
end
|
||||
|
||||
test_update_node_summary
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
storage.save_node (custom_node ("Content", "Summary", "Title"))
|
||||
if attached {CMS_NODE} storage.node (1) as ll_node then
|
||||
storage.update_node_summary (ll_node.id, "New Summary")
|
||||
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
|
||||
end
|
||||
end
|
||||
|
||||
test_update_node_content
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
storage.save_node (custom_node ("Content", "Summary", "Title"))
|
||||
if attached {CMS_NODE} storage.node (1) as ll_node then
|
||||
storage.update_node_content (ll_node.id, "New Content")
|
||||
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
|
||||
end
|
||||
end
|
||||
|
||||
test_delete_node
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
do
|
||||
across 1 |..| 10 as c loop
|
||||
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
|
||||
end
|
||||
assert ("Exist node id: 10", attached storage.node (10) as l_node and then l_node.title ~ "Title_10" )
|
||||
storage.delete_node (10)
|
||||
assert ("Not exist node id: 10", storage.node (10) = Void)
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
storage: CMS_STORAGE
|
||||
-- Storage
|
||||
once
|
||||
create {CMS_STORAGE_SQLITE}Result.make (connection)
|
||||
end
|
||||
|
||||
feature {NONE} -- Fixture Factory: Users
|
||||
|
||||
default_user: CMS_USER
|
||||
do
|
||||
Result := custom_user ("test", "password", "test@test.com")
|
||||
end
|
||||
|
||||
custom_user (a_name, a_password, a_email: READABLE_STRING_32): CMS_USER
|
||||
do
|
||||
create Result.make (a_name)
|
||||
Result.set_password (a_password)
|
||||
Result.set_email (a_email)
|
||||
end
|
||||
|
||||
feature {NONE} -- Fixture Factories: Nodes
|
||||
|
||||
default_node: CMS_NODE
|
||||
do
|
||||
Result := custom_node ("Default content", "default summary", "Default")
|
||||
end
|
||||
|
||||
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
|
||||
do
|
||||
create Result.make (a_content, a_summary, a_title)
|
||||
end
|
||||
|
||||
end
|
||||
22
persistence/implementation/sqlite/tests/tests.ecf
Normal file
22
persistence/implementation/sqlite/tests/tests.ecf
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="tests" uuid="FE27C81D-3F7D-4E46-992B-55F4BBDA4F8B">
|
||||
<target name="tests">
|
||||
<root class="APPLICATION" feature="make"/>
|
||||
<option warning="true" void_safety="conformance">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
|
||||
<library name="persitence_sqlite" location="..\persistence_sqlite.ecf" readonly="false"/>
|
||||
<library name="process" location="$ISE_LIBRARY\library\process\process-safe.ecf"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<cluster name="tests" location=".\" recursive="true">
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
</file_rule>
|
||||
</cluster>
|
||||
</target>
|
||||
</system>
|
||||
@@ -0,0 +1,78 @@
|
||||
note
|
||||
description: "[
|
||||
Eiffel tests that can be executed by testing tool.
|
||||
]"
|
||||
author: "EiffelStudio test wizard"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
testing: "type/manual"
|
||||
|
||||
class
|
||||
USER_TEST_SET
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare,
|
||||
on_clean
|
||||
select
|
||||
default_create
|
||||
end
|
||||
ABSTRACT_DB_TEST
|
||||
rename
|
||||
default_create as default_db_test
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
-- <Precursor>
|
||||
do
|
||||
(create {CLEAN_DB}).clean_db(connection)
|
||||
user_provider.new_user ("admin", "admin","admin@admin.com")
|
||||
end
|
||||
|
||||
on_clean
|
||||
-- <Precursor>
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_user_exist
|
||||
-- User admin exist
|
||||
do
|
||||
assert ("Not void", attached user_provider.user_by_email ("admin@admin.com"))
|
||||
assert ("Not void", attached user_provider.user (1))
|
||||
assert ("Not void", attached user_provider.user_by_name ("admin"))
|
||||
end
|
||||
|
||||
test_user_not_exist
|
||||
-- Uset test does not exist.
|
||||
do
|
||||
assert ("Void", user_provider.user_by_email ("test@admin.com") = Void)
|
||||
assert ("Void", user_provider.user(2) = Void )
|
||||
assert ("Void", user_provider.user_by_name ("test") = Void)
|
||||
end
|
||||
|
||||
test_new_user
|
||||
do
|
||||
user_provider.new_user ("test", "test","test@admin.com")
|
||||
assert ("Not void", attached user_provider.user_by_email ("test@admin.com"))
|
||||
assert ("Not void", attached user_provider.user (2))
|
||||
assert ("Not void", attached user_provider.user (2) as l_user and then l_user.id = 2 and then l_user.name ~ "test")
|
||||
assert ("Not void", attached user_provider.user_by_name ("test"))
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
user_provider: USER_DATA_PROVIDER
|
||||
-- user provider.
|
||||
once
|
||||
create Result.make (connection)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
note
|
||||
description: "Summary description for {ABSTRACT_DB_TEST}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
ABSTRACT_DB_TEST
|
||||
|
||||
|
||||
feature -- Database connection
|
||||
|
||||
connection: DATABASE_CONNECTION_ODBC
|
||||
-- odbc database connection
|
||||
once
|
||||
-- create Result.login_with_connection_string ("Driver=SQLite3 ODBC Driver;Database=PATH/SQLITE.FILE;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
|
||||
create Result.make_basic ("cms_dev")
|
||||
end
|
||||
|
||||
end
|
||||
66
persistence/implementation/sqlite/tests/util/clean_db.e
Normal file
66
persistence/implementation/sqlite/tests/util/clean_db.e
Normal file
@@ -0,0 +1,66 @@
|
||||
note
|
||||
description: "[
|
||||
Setting up database tests
|
||||
1. Put the database in a known state before running your test suite.
|
||||
2. Data reinitialization. For testing in developer sandboxes, something that you should do every time you rebuild the system, you may want to forgo dropping and rebuilding the database in favor of simply reinitializing the source data.
|
||||
You can do this either by erasing all existing data and then inserting the initial data vales back into the database, or you can simple run updates to reset the data values.
|
||||
The first approach is less risky and may even be faster for large amounts of data. - See more at: http://www.agiledata.org/essays/databaseTesting.html#sthash.6yVp35g8.dpuf
|
||||
]"
|
||||
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
EIS: "name=Database Testing", "src=http://www.agiledata.org/essays/databaseTesting.html", "protocol=uri"
|
||||
|
||||
class
|
||||
CLEAN_DB
|
||||
|
||||
feature
|
||||
|
||||
clean_db (a_connection: DATABASE_CONNECTION)
|
||||
-- Clean db test.
|
||||
local
|
||||
l_parameters: STRING_TABLE[STRING]
|
||||
do
|
||||
create l_parameters.make (0)
|
||||
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_nodes, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
-- Clean Users
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_users, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
-- -- Reset Autoincremente
|
||||
-- db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Rest_users_autoincrement, l_parameters))
|
||||
-- db_handler(a_connection).execute_change
|
||||
|
||||
-- db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Rest_nodes_autoincrement, l_parameters))
|
||||
-- db_handler(a_connection).execute_change
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Database Hanlder
|
||||
|
||||
db_handler (a_connection: DATABASE_CONNECTION): DATABASE_HANDLER
|
||||
-- Db handler
|
||||
once
|
||||
create {DATABASE_HANDLER_IMPL} Result.make (a_connection)
|
||||
end
|
||||
|
||||
|
||||
feature -- Sql delete queries
|
||||
|
||||
Sql_delete_users: STRING = "delete from Users"
|
||||
-- Clean Users.
|
||||
|
||||
Sql_delete_nodes: STRING = "delete from Nodes"
|
||||
-- Clean Nodes.
|
||||
|
||||
Rest_users_autoincrement: STRING = "ALTER TABLE Users AUTO_INCREMENT = 1"
|
||||
-- reset autoincrement
|
||||
|
||||
Rest_nodes_autoincrement: STRING = "ALTER TABLE Nodes AUTO_INCREMENT = 1"
|
||||
-- reset autoincrement.
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user