Refactored persistence with mysql and sqlite to factorize more things with a CMS_STORAGE_SQL .. based only on sql statement execution.

Various changes
This commit is contained in:
2015-01-21 12:02:36 +01:00
parent 4dcc1b0e04
commit bba0364a2c
43 changed files with 1545 additions and 2350 deletions

View File

@@ -153,22 +153,22 @@ feature -- Status Report
end
connection: DATABASE_CONNECTION
-- Database connection.
-- Database connection.
db_control: DB_CONTROL
-- Database control.
-- Database control.
do
Result := connection.db_control
end
db_result: detachable DB_RESULT
-- Database query result.
-- Database query result.
db_selection: detachable DB_SELECTION
-- Database selection.
-- Database selection.
db_change: detachable DB_CHANGE
-- Database modification.
-- Database modification.
feature -- Error handling

View File

@@ -7,7 +7,6 @@ class
DATABASE_QUERY
inherit
REFACTORING_HELPER
SHARED_LOGGER
@@ -17,7 +16,7 @@ create
feature {NONE} -- Intialization
data_reader (a_query: STRING; a_parameters: STRING_TABLE [detachable ANY])
data_reader (a_query: STRING; a_parameters: like parameters)
-- SQL data reader for the query `a_query' with arguments `a_parameters'
do
log.write_information (generator + ".data_reader" + " execute query: " + a_query)
@@ -65,7 +64,7 @@ feature -- Access
query: STRING
-- SQL query to execute.
parameters: STRING_TABLE [detachable ANY]
parameters: detachable STRING_TABLE [detachable ANY]
-- query parameters.
feature {NONE} -- Implementation
@@ -73,26 +72,24 @@ feature {NONE} -- Implementation
set_map_name (a_base_selection: DB_EXPRESSION)
-- Store parameters `item' and their `key'.
do
from
parameters.start
until
parameters.after
loop
a_base_selection.set_map_name (parameters.item_for_iteration, parameters.key_for_iteration)
parameters.forth
if attached parameters as l_parameters then
across
l_parameters as ic
loop
a_base_selection.set_map_name (ic.item, ic.key)
end
end
end
unset_map_name (a_base_selection: DB_EXPRESSION)
-- Remove parameters item associated with key `key'.
do
from
parameters.start
until
parameters.after
loop
a_base_selection.unset_map_name (parameters.key_for_iteration)
parameters.forth
if attached parameters as l_parameters then
across
l_parameters as ic
loop
a_base_selection.unset_map_name (ic.key)
end
end
end
@@ -101,26 +98,25 @@ feature {NONE} -- Implementation
-- exclude sensitive information.
do
create Result.make_empty
from
a_parameters.start
until
a_parameters.after
loop
Result.append ("name:")
Result.append (a_parameters.key_for_iteration.as_string_32)
Result.append (", value:")
if
a_parameters.key_for_iteration.has_substring ("Password") or else
a_parameters.key_for_iteration.has_substring ("password")
then
-- Data to exclude
else
if attached a_parameters.item_for_iteration as l_item then
Result.append (l_item.out)
if a_parameters /= Void then
across
a_parameters as ic
loop
Result.append ("name:")
Result.append (ic.key.as_string_32)
Result.append (", value:")
if
ic.key.has_substring ("Password") or else
ic.key.has_substring ("password")
then
-- Data to exclude
else
if attached ic.item as l_item then
Result.append (l_item.out)
end
end
Result.append ("%N")
end
Result.append ("%N")
a_parameters.forth
end
end

View File

@@ -3,6 +3,7 @@ note
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision: "$Revision: 95678 $"
EIS: "SQL server injection", "src=http://blogs.msdn.com/b/raulga/archive/2007/01/04/dynamic-sql-sql-injection.aspx", "protocol=url"
expanded class
DATABASE_SQL_SERVER_ENCODER
@@ -12,7 +13,7 @@ inherit
feature -- Escape SQL input
encode (a_string:READABLE_STRING_32): READABLE_STRING_32
encode (a_string: READABLE_STRING_32): READABLE_STRING_32
-- Escape single quote (') and braces ([,]).
local
l_string: STRING

View File

@@ -1,7 +1,7 @@
note
description: "Error from database"
date: "$Date: 2013-08-08 16:39:49 -0300 (ju. 08 de ago. de 2013) $"
revision: "$Revision: 195 $"
date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
class
DATABASE_ERROR

View File

@@ -1,7 +1,7 @@
note
description: "Database error handler"
date: "$Date: 2013-08-08 16:39:49 -0300 (ju. 08 de ago. de 2013) $"
revision: "$Revision: 195 $"
date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
class
DATABASE_ERROR_HANDLER

View File

@@ -1,8 +1,8 @@
note
description: "Summary description for {DATABASE_NO_CHANGE_ERROR}."
author: ""
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
class
DATABASE_NO_CHANGE_ERROR

View File

@@ -1,153 +0,0 @@
note
description: "Provides security routine helpers"
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision: "$Revision: 95678 $"
class
SECURITY_PROVIDER
inherit
REFACTORING_HELPER
feature -- Access
token: STRING
-- Cryptographic random base 64 string.
do
Result := salt_with_size (5)
-- Remove trailing equal sign
Result.keep_head (Result.count - 1)
end
salt: STRING
-- Cryptographic random number of 16 bytes.
do
Result := salt_with_size (16)
end
password: STRING
-- Cryptographic random password of 10 bytes.
do
Result := salt_with_size (10)
-- Remove trailing equal signs
Result.keep_head (Result.count - 2)
end
password_hash (a_password, a_salt: STRING): STRING
-- Password hash based on password `a_password' and salt value `a_salt'.
do
Result := sha1_string (a_password + a_salt )
end
feature {NONE} -- Implementation
salt_with_size (a_val: INTEGER): STRING
-- Return a salt with size `a_val'.
local
l_salt: SALT_XOR_SHIFT_64_GENERATOR
l_array: ARRAY [INTEGER_8]
i: INTEGER
do
create l_salt.make (a_val)
create l_array.make_empty
i := 1
across
l_salt.new_sequence as c
loop
l_array.force (c.item.as_integer_8, i)
i := i + 1
end
Result := encode_base_64 (l_array)
end
sha1_string (a_str: STRING): STRING
-- SHA1 diggest of `a_str'.
do
sha1.update_from_string (a_str)
Result := sha1.digest_as_string
sha1.reset
end
sha1: SHA1
-- Create a SHA1 object.
once
create Result.make
end
feature -- Encoding
encode_base_64 (bytes: SPECIAL [INTEGER_8]): STRING_8
-- Encodes a byte array into a STRING doing base64 encoding.
local
l_output: SPECIAL [INTEGER_8]
l_remaining: INTEGER
i, ptr: INTEGER
char: CHARACTER
do
to_implement ("Check existing code to do that!!!.")
create l_output.make_filled (0, ((bytes.count + 2) // 3) * 4)
l_remaining := bytes.count
from
i := 0
ptr := 0
until
l_remaining <= 3
loop
l_output [ptr] := encode_value (bytes [i] |>> 2)
ptr := ptr + 1
l_output [ptr] := encode_value (((bytes [i] & 0x3) |<< 4) | ((bytes [i + 1] |>> 4) & 0xF))
ptr := ptr + 1
l_output [ptr] := encode_value (((bytes [i + 1] & 0xF) |<< 2) | ((bytes [i + 2] |>> 6) & 0x3))
ptr := ptr + 1
l_output [ptr] := encode_value (bytes [i + 2] & 0x3F)
ptr := ptr + 1
l_remaining := l_remaining - 3
i := i + 3
end
-- encode when exactly 1 element (left) to encode
char := '='
if l_remaining = 1 then
l_output [ptr] := encode_value (bytes [i] |>> 2)
ptr := ptr + 1
l_output [ptr] := encode_value (((bytes [i]) & 0x3) |<< 4)
ptr := ptr + 1
l_output [ptr] := char.code.as_integer_8
ptr := ptr + 1
l_output [ptr] := char.code.as_integer_8
ptr := ptr + 1
end
-- encode when exactly 2 elements (left) to encode
if l_remaining = 2 then
l_output [ptr] := encode_value (bytes [i] |>> 2)
ptr := ptr + 1
l_output [ptr] := encode_value (((bytes [i] & 0x3) |<< 4) | ((bytes [i + 1] |>> 4) & 0xF));
ptr := ptr + 1
l_output [ptr] := encode_value ((bytes [i + 1] & 0xF) |<< 2);
ptr := ptr + 1
l_output [ptr] := char.code.as_integer_8
ptr := ptr + 1
end
Result := ""
across
l_output as elem
loop
Result.append_character (elem.item.to_character_8)
end
end
base64_map: SPECIAL [CHARACTER_8]
-- Table for Base64 encoding.
once
Result := ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").area
end
encode_value (i: INTEGER_8): INTEGER_8
-- Encode `i'.
do
Result := base64_map [i & 0x3F].code.as_integer_8
end
end

View File

@@ -1,53 +0,0 @@
note
description: "Summary description for {STRING_HELPER}."
date: "$Date: 2014-08-08 16:02:11 -0300 (vi., 08 ago. 2014) $"
revision: "$Revision: 95593 $"
class
STRING_HELPER
feature -- Access
is_blank (s: detachable READABLE_STRING_32): BOOLEAN
local
i,n: INTEGER
do
Result := True
if s /= Void then
from
i := 1
n := s.count
until
i > n or not Result
loop
Result := s[i].is_space
i := i + 1
end
end
end
indented_text (pre: READABLE_STRING_8; t: READABLE_STRING_8): READABLE_STRING_8
-- Indendted text.
local
s8: STRING_8
do
s8 := t.string
s8.prepend (pre)
s8.replace_substring_all ("%N", "%N" + pre)
Result := s8
end
json_encode (a_string: STRING): STRING
-- json encode `a_string'.
local
encode: SHARED_JSON_ENCODER
do
create encode
Result := encode.json_encoder.encoded_string (a_string)
debug
print ("%NResult" + Result)
end
end
end

View File

@@ -0,0 +1,75 @@
note
description: "Summary description for {CMS_NODE_STORAGE_MYSQL}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_NODE_STORAGE_MYSQL
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)
create Result.make (db_handler, agent fetch_node)
sql_post_execution
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

@@ -9,6 +9,11 @@ class
inherit
CMS_STORAGE
CMS_USER_STORAGE_MYSQL
CMS_NODE_STORAGE_MYSQL
REFACTORING_HELPER
create
@@ -22,249 +27,76 @@ feature {NONE} -- Initialization
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 node_provider.make (a_connection)
create user_provider.make (a_connection)
log.write_information (generator + ".make - is database connected? "+ a_connection.is_connected.out )
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
create error_handler.make
end
feature -- Access: user
has_user: BOOLEAN
-- Has any user?
do
Result := user_provider.has_user
end
all_users: LIST [CMS_USER]
do
to_implement (generator + ".all_users")
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)
end
user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER
do
Result := user_provider.user_by_name (a_name)
end
user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER
do
Result := user_provider.user_by_email (a_email)
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
end
feature -- User Nodes
user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is a collaborator.
do
to_implement (generator + ".user_collaborator_nodes")
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
end
user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is the author.
do
to_implement (generator + ".user_author_nodes")
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
end
feature -- Access: roles and permissions
user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE
do
to_implement (generator + ".user_role_by_id")
end
user_roles: LIST [CMS_USER_ROLE]
do
to_implement (generator + ".user_roles")
create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0)
end
feature -- Change: roles and permissions
save_user_role (a_user_role: CMS_USER_ROLE)
do
to_implement (generator + ".save_user_role")
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
connection.begin_transaction
user_provider.new_user (a_user.name, l_password, l_email)
connection.commit
else
debug ("refactor_fixme")
fixme ("maybe we should not always carry password, in this case, to implement the else part..")
end
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
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
end
node (a_id: INTEGER_64): detachable CMS_NODE
-- <Precursor>
do
Result := node_provider.node (a_id)
end
node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER
-- <Precursor>
do
Result := node_provider.node_author (a_id)
end
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
-- Possible list of node's collaborator.
do
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
across node_provider.node_collaborators (a_id) as c loop Result.force (c.item) end
end
feature -- Node
save_node (a_node: CMS_NODE)
-- <Precursor>
do
node_provider.new_node (a_node)
end
delete_node (a_id: INTEGER_64)
do
node_provider.delete_from_user_nodes(a_id)
node_provider.delete_node (a_id)
end
update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE)
-- <Precursor>
do
node_provider.update_node (a_id, a_node)
end
update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- <Precursor>
do
node_provider.update_node_title (a_node_id, a_title)
internal_node_update (a_id, a_node_id)
end
update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- <Precursor>
do
node_provider.update_node_summary (a_node_id, a_summary)
internal_node_update (a_id, a_node_id)
end
update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- <Precursor>
do
node_provider.update_node_content (a_node_id, a_content)
internal_node_update (a_id, a_node_id)
end
feature {NONE} -- NODE Implemenation
internal_node_update (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id)
-- Update node editor or add collaborator.
do
if not node_provider.is_collaborator (a_id, a_node_id) then
node_provider.add_collaborator (a_id, a_node_id)
else
node_provider.update_node_last_editor (a_id, a_node_id)
end
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
node_provider: NODE_DATA_PROVIDER
-- Node Data provider.
user_provider: USER_DATA_PROVIDER
-- User Data provider.
db_handler: DATABASE_HANDLER
connection: DATABASE_CONNECTION
-- Current database connection.
-- Current database connection.
feature -- Query
sql_post_execution
-- Post database execution.
do
-- error_handler.add_synchronization (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_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, Void))
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, Void))
db_handler.execute_change
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_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

View File

@@ -0,0 +1,14 @@
note
description: "Summary description for {CMS_USER_STORAGE_MYSQL}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_USER_STORAGE_MYSQL
inherit
CMS_USER_STORAGE_SQL
end

View File

@@ -1,511 +0,0 @@
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
REFACTORING_HELPER
SHARED_LOGGER
create
make
feature -- Initialization
make (a_connection: DATABASE_CONNECTION)
-- Create a data provider.
do
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
create error_handler.make
post_execution
end
db_handler: DATABASE_HANDLER
-- Db handler.
feature -- Status Report
is_successful: BOOLEAN
-- Is the last execution sucessful?
do
Result := not error_handler.has_error
end
feature -- Error Handler
error_handler: ERROR_HANDLER
feature -- Access
nodes: DATABASE_ITERATION_CURSOR [CMS_NODE]
-- List of nodes.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
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
error_handler.reset
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
error_handler.reset
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
error_handler.reset
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
last_inserted_node_id: INTEGER
-- Last insert node id.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".last_inserted_node_id")
create l_parameters.make (0)
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Sql_last_insert_node_id, 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
error_handler.reset
log.write_information (generator + ".new_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 (a_node.modification_date, "modification_date")
if
attached a_node.author as l_author and then
l_author.id > 0
then
l_parameters.put (l_author.id, "author_id")
end
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_node, l_parameters))
db_handler.execute_change
a_node.set_id (last_inserted_node_id)
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
error_handler.reset
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
error_handler.reset
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
error_handler.reset
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_id: like {CMS_USER}.id; a_node: CMS_NODE)
-- Update node.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
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 (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_node.id, "id")
l_parameters.put (a_id, "editor")
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
error_handler.reset
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
delete_from_user_nodes (a_id: INTEGER_64)
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".delete_from_user_nodes")
create l_parameters.make (1)
l_parameters.put (a_id, "id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_delete_from_user_node, l_parameters))
db_handler.execute_change
post_execution
end
feature -- Basic Operations: User_Nodes
add_author (a_user_id: INTEGER_64; a_node_id: INTEGER_64)
-- Add author `a_user_id' to node `a_node_id'
local
l_parameters: STRING_TABLE [detachable ANY]
do
error_handler.reset
log.write_information (generator + ".add_author")
create l_parameters.make (2)
l_parameters.put (a_user_id,"user_id")
l_parameters.put (a_node_id,"id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Sql_update_node_author, l_parameters))
db_handler.execute_change
post_execution
end
add_collaborator (a_user_id: INTEGER_64; a_node_id: INTEGER_64)
-- Add collaborator `a_user_id' to node `a_node_id'
local
l_parameters: STRING_TABLE [detachable ANY]
do
error_handler.reset
log.write_information (generator + ".add_collaborator")
create l_parameters.make (2)
l_parameters.put (a_user_id,"users_id")
l_parameters.put (a_node_id,"nodes_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Sql_insert_users_nodes, l_parameters))
db_handler.execute_change
post_execution
end
update_node_last_editor (a_user_id: INTEGER_64; a_node_id: INTEGER_64)
-- Update node last editor.
local
l_parameters: STRING_TABLE [detachable ANY]
do
error_handler.reset
log.write_information (generator + ".add_collaborator")
create l_parameters.make (2)
l_parameters.put (a_user_id,"users_id")
l_parameters.put (a_node_id,"nodes_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Slq_update_editor, l_parameters))
db_handler.execute_change
post_execution
end
author_nodes (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_NODE]
-- List of Nodes for the given user `a_id'. (the user is the author of the node)
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".author_nodes")
create l_parameters.make (1)
l_parameters.put (a_id, "user_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_author, l_parameters))
db_handler.execute_query
create Result.make (db_handler, agent fetch_node)
post_execution
end
collaborator_nodes (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_NODE]
-- List of Nodes for the given user `a_id' as collaborator.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".collaborator_nodes")
create l_parameters.make (1)
l_parameters.put (a_id, "user_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_collaborator, l_parameters))
db_handler.execute_query
create Result.make (db_handler, agent fetch_node)
post_execution
end
node_author (a_id: INTEGER_64): detachable CMS_USER
-- Node's author for the given node id.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".node_author")
create l_parameters.make (1)
l_parameters.put (a_id, "node_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_node_author, l_parameters))
db_handler.execute_query
if not db_handler.after then
Result := fetch_user
end
post_execution
end
node_collaborators (a_id: INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_USER]
-- List of possible node's collaborator.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".node_collaborators")
create l_parameters.make (1)
l_parameters.put (a_id, "node_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_node_collaborators, l_parameters))
db_handler.execute_query
create Result.make (db_handler, agent fetch_user)
post_execution
end
is_collaborator (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id): BOOLEAN
-- Is the user `a_user_id' a collaborator of node `a_node_id'
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".node_collaborators")
create l_parameters.make (2)
l_parameters.put (a_user_id, "user_id")
l_parameters.put (a_node_id, "node_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_exist_user_node, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := db_handler.read_integer_32 (1) = 1
end
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, author_id) values (:title, :summary, :content, :publication_date, :creation_date, :modification_date, :author_id);"
-- SQL Insert to add a new node.
SQL_Update_node_title: STRING ="update nodes SET title=:title, modification_date=:modification_date, version = version + 1 where id=:id;"
-- SQL update node title.
SQL_Update_node_summary: STRING ="update nodes SET summary=:summary, modification_date=:modification_date, version = version + 1 where id=:id;"
-- SQL update node summary.
SQL_Update_node_content: STRING ="update nodes SET content=:content, modification_date=:modification_date, version = version + 1 where id=:id;"
-- SQL node content.
Slq_update_editor: STRING ="update nodes SET editor_id=:users_id where id=:nodes_id;"
-- SQL node content.
SQL_Update_node : STRING = "update nodes SET title=:title, summary=:summary, content=:content, publication_date=:publication_date, modification_date=:modification_date, version = version + 1, editor_id=:editor where id=:id;"
-- SQL node.
SQL_Delete_node: STRING = "delete from nodes where id=:id;"
Sql_update_node_author: STRING = "update nodes SET author_id=:user_id where id=:id;"
Sql_last_insert_node_id: STRING = "SELECT MAX(id) from nodes;"
feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
Sql_insert_users_nodes: STRING = "insert into users_nodes (users_id, nodes_id) values (:users_id, :nodes_id);"
select_node_collaborators: STRING = "SELECT * FROM Users INNER JOIN users_nodes ON users.id=users_nodes.users_id and users_nodes.nodes_id = :node_id;"
Select_user_author: STRING = "SELECT * FROM Nodes INNER JOIN users ON nodes.author_id=users.id and users.id = :user_id;"
Select_node_author: STRING = "SELECT * FROM Users INNER JOIN nodes ON nodes.author_id=users.id and nodes.id =:node_id;"
Select_user_collaborator: STRING = "SELECT * FROM Nodes INNER JOIN users_nodes ON users_nodes.nodes_id = nodes.id and users_nodes.users_id = :user_id;"
Select_exist_user_node: STRING= "Select Count(*) from Users_nodes where users_id=:user_id and nodes_id=:node_id;"
sql_delete_from_user_node: STRING = "delete from users_nodes where nodes_id=:id"
feature --
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
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 {NONE} -- Implementation
post_execution
-- Post database execution.
do
error_handler.add_synchronization (db_handler.database_error_handler)
if error_handler.has_error then
log.write_critical (generator + ".post_execution " + error_handler.as_string_representation)
end
end
end

View File

@@ -1,216 +0,0 @@
note
description: "Summary description for {ROLE_DATA_PROVIDER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
ROLE_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_roles: BOOLEAN
-- Has any role?
do
Result := count > 0
end
feature -- Access
roles: DATABASE_ITERATION_CURSOR [CMS_USER_ROLE]
-- List of roles.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".roles")
create l_parameters.make (0)
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_roles, l_parameters))
db_handler.execute_query
create Result.make (db_handler, agent fetch_role)
post_execution
end
feature -- Basic Operations
new_role (a_role: READABLE_STRING_32)
-- Create a new node.
local
l_parameters: STRING_TABLE [detachable ANY]
do
log.write_information (generator + ".new_role")
create l_parameters.make (1)
l_parameters.put (a_role,"name")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_role, l_parameters))
db_handler.execute_change
post_execution
end
role (a_id: INTEGER_64): detachable CMS_USER_ROLE
-- Role for the given id `a_id', if any.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".role")
create l_parameters.make (1)
l_parameters.put (a_id,"id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_role_by_id, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := fetch_role
end
post_execution
end
role_by_name (a_name: READABLE_STRING_32): detachable CMS_USER_ROLE
-- Role for the given name `a_name', if any.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".role_by_name")
create l_parameters.make (1)
l_parameters.put (a_name,"name")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_role_by_name, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := fetch_role
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
save_role_permission (a_role_id: INTEGER; a_permission: READABLE_STRING_32)
-- Add permission `a_permission' to the role id `a_role_id'.
require
valid_id: a_role_id > 0
local
l_parameters: STRING_TABLE [detachable ANY]
do
log.write_information (generator + ".save_role_permission")
create l_parameters.make (1)
l_parameters.put (a_permission,"name")
l_parameters.put (a_role_id,"id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (SQL_Insert_permissions, l_parameters))
db_handler.execute_change
post_execution
end
permission_by_role (a_role_id: INTEGER_64): DATABASE_ITERATION_CURSOR [READABLE_STRING_32]
-- List of permission by role `a_role_id'.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".permission_by_role")
create l_parameters.make (1)
l_parameters.put (a_role_id, "id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_permissions, l_parameters))
db_handler.execute_query
create Result.make (db_handler, agent fetch_permission)
post_execution
end
feature -- New Object
fetch_role: CMS_USER_ROLE
do
create Result.make_with_id (0,"")
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
end
fetch_permission: STRING_32
do
create Result.make_empty
if attached db_handler.read_string (1) as l_u then
Result := l_u
end
end
feature {NONE} -- Sql Queries: Roles
Select_count: STRING = "select count(*) from Roles;"
-- Number of roles.
Select_roles: STRING = "select * from Roles;"
-- roles.
Select_role_by_id: STRING = "select * from Roles where id =:id;"
-- Retrieve role by id if exists.
Select_role_by_name: STRING = "select * from Roles where role =:name;"
-- Retrieve user by name if exists.
SQL_Insert_role: STRING = "insert into roles (role) values (:name);"
-- SQL Insert to add a new node.
feature {NONE} -- Sql Queries: Permissions
Select_permissions_count: STRING = "select count(*) from permissions where roles_id=:id;"
-- Number of permissions for a given role.
Select_permissions: STRING = "select * from permissions where roles_id=:id;"
-- List of permissions for a given role.
Select_permissions_by_id: STRING = "select name from permissions where roles_id=:id and id=:permissionid;"
-- Permission for a given role and permission id
SQL_Insert_permissions: STRING = "insert into permissions (name, roles_id) values (:name, :id);"
-- SQL Insert to add a new node.
feature {NONE} -- Implementation
post_execution
-- Post database execution.
do
end
end

View File

@@ -1,337 +0,0 @@
note
description: "Summary description for {USER_DATA_PROVIDER}."
date: "$Date$"
revision: "$Revision$"
class
USER_DATA_PROVIDER
inherit
PARAMETER_NAME_HELPER
REFACTORING_HELPER
SHARED_LOGGER
create
make
feature -- Initialization
make (a_connection: DATABASE_CONNECTION)
-- Create a data provider.
do
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
create error_handler.make
post_execution
end
db_handler: DATABASE_HANDLER
-- Db handler.
feature -- Error Handler
error_handler: ERROR_HANDLER
feature -- Status Report
is_successful: BOOLEAN
-- Is the last execution sucessful?
do
Result := not error_handler.has_error
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
error_handler.reset
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
error_handler.reset
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
error_handler.reset
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
error_handler.reset
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
error_handler.reset
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
error_handler.reset
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: User Roles
add_role (a_user_id: INTEGER; a_role_id: INTEGER)
-- Add Role `a_role_id' to user `a_user_id'
local
l_parameters: STRING_TABLE [detachable ANY]
do
error_handler.reset
log.write_information (generator + ".add_role")
create l_parameters.make (2)
l_parameters.put (a_user_id,"users_id")
l_parameters.put (a_role_id,"roles_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (slq_insert_users_roles, l_parameters))
db_handler.execute_change
post_execution
end
user_roles (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [INTEGER]
-- List of Roles id for the given user `a_id'.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".user_roles")
create l_parameters.make (1)
l_parameters.put (a_id, "user_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_roles, l_parameters))
db_handler.execute_query
create Result.make (db_handler, agent fetch_role_id)
post_execution
end
feature -- Basic operations: User Profiles
save_profile_item (a_user_id: INTEGER_64; a_key: READABLE_STRING_32; a_value: READABLE_STRING_32)
-- Save a profile item with (a_key and a_value) to the given user `user_id'.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".save_profile_item")
create l_parameters.make (3)
l_parameters.put (a_key, "key")
l_parameters.put (a_value, "value")
l_parameters.put (a_user_id, "users_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_instert_profile_item, l_parameters))
db_handler.execute_change
post_execution
end
save_profile (a_user_id: INTEGER_64; a_user_profile: CMS_USER_PROFILE)
-- Save a profile item with (a_key and a_value) to the given user `user_id'.
local
l_cursor: TABLE_ITERATION_CURSOR [READABLE_STRING_8, READABLE_STRING_GENERAL]
do
error_handler.reset
log.write_information (generator + ".save_profile")
from
l_cursor := a_user_profile.new_cursor
until
l_cursor.after
loop
save_profile_item (a_user_id, l_cursor.key.as_string_32, l_cursor.item)
l_cursor.forth
end
post_execution
end
user_profile (a_user_id: INTEGER_64): CMS_USER_PROFILE
-- User profile for a user with id `a_user_id'.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".user_profile")
create l_parameters.make (1)
l_parameters.put (a_user_id, "users_id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_profile, l_parameters))
db_handler.execute_query
create Result.make
if not db_handler.after then
from
db_handler.start
until
db_handler.after
loop
if
attached db_handler.read_string (1) as l_key and then
attached db_handler.read_string (2) as l_value
then
Result.force (l_value, l_key)
end
db_handler.forth
end
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
fetch_role_id: INTEGER
do
if attached db_handler.read_integer_32 (1) as l_id then
Result := l_id
end
end
feature {NONE} -- Sql Queries: USER
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} -- Sql Queries: USER_ROLES
Slq_insert_users_roles: STRING = "insert into users_roles (users_id, roles_id) values (:users_id, :roles_id);"
Select_user_roles: STRING = "Select roles_id from users_roles where users_id = :user_id"
feature {NONE} -- SQL Queries: Profile
Select_instert_profile_item: STRING = "insert into profiles (profiles.key, value, users_id) values (:key, :value, :users_id);"
Select_user_profile: STRING = "Select profiles.key, value from profiles where users_id = :users_id;"
feature {NONE} -- Implementation
post_execution
-- Post database execution.
do
error_handler.add_synchronization (db_handler.database_error_handler)
if error_handler.has_error then
log.write_critical (generator + ".post_execution " + error_handler.as_string_representation)
end
end
end

View File

@@ -7,6 +7,7 @@
</option>
<setting name="console_application" value="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="..\..\..\..\cms-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="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
@@ -19,7 +20,6 @@
<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>

View File

@@ -0,0 +1,14 @@
note
description: "Summary description for {CMS_NODE_STORAGE_SQLITE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_NODE_STORAGE_SQLITE
inherit
CMS_NODE_STORAGE_SQL
end

View File

@@ -7,8 +7,12 @@ class
CMS_STORAGE_SQLITE
inherit
CMS_STORAGE
CMS_USER_STORAGE_SQLITE
CMS_NODE_STORAGE_SQLITE
REFACTORING_HELPER
create
@@ -21,229 +25,77 @@ feature {NONE} -- Initialization
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)
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 error_handler.make
end
db_handler: DATABASE_HANDLER
connection: DATABASE_CONNECTION
-- Current database connection.
feature -- Access: user
has_user: BOOLEAN
-- Has any user?
sql_post_execution
-- Post database execution.
do
Result := user_provider.has_user
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)
end
user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER
do
Result := user_provider.user_by_name (a_name)
end
user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER
do
Result := user_provider.user_by_email (a_email)
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
-- error_handler.add_synchronization (db_handler.database_error_handler)
if error_handler.has_error then
log.write_critical (generator + ".post_execution " + error_handler.as_string_representation)
end
end
feature -- Change: user
save_user (a_user: CMS_USER)
-- Add a new user `a_user'.
sql_begin_transaction
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)
connection.begin_transaction
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, Void))
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, Void))
db_handler.execute_change
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_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
-- set error
check has_item_at_index: False end
end
end
feature -- User Nodes
user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is a collaborator.
do
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
to_implement ("Not implemented")
end
user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is the author.
do
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
to_implement ("Not implemented")
end
feature -- Users roles and permissions
user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE
-- User role by id `a_id', if any.
do
to_implement ("Not implemented")
end
user_roles: LIST [CMS_USER_ROLE]
-- Possible list of user roles.
do
create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0)
to_implement ("Not implemented")
end
feature -- Change: roles and permissions
save_user_role (a_user_role: CMS_USER_ROLE)
-- Save user role `a_user_role'
do
to_implement ("Not implemented")
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
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
end
node (a_id: INTEGER_64): detachable CMS_NODE
--
do
Result := node_provider.node (a_id)
end
feature -- Node
save_node (a_node: CMS_NODE)
-- Add a new node
do
node_provider.new_node (a_node)
end
delete_node (a_id: INTEGER_64)
do
node_provider.delete_node (a_id)
end
update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE)
do
node_provider.update_node (a_node)
end
update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
do
node_provider.update_node_title (a_id, a_title)
end
update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
do
node_provider.update_node_summary (a_id, a_summary)
end
update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
do
node_provider.update_node_content (a_id, a_content)
end
node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER
-- Node's author. if any.
do
to_implement ("Not implemented")
end
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
-- Possible list of node's collaborator.
do
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
to_implement ("Not implemented")
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} -- Implementation
node_provider: NODE_DATA_PROVIDER
-- Node Data provider.
user_provider: USER_DATA_PROVIDER
-- User Data provider.
end

View File

@@ -0,0 +1,43 @@
note
description: "[
Objects that ...
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
class
CMS_STORAGE_SQLITE_BUILDER
inherit
CMS_STORAGE_BUILDER
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
end
feature -- Factory
storage (a_setup: CMS_SETUP): detachable CMS_STORAGE_SQLITE
local
s: STRING
do
if attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.layout.application_config_path) as l_database_config then
s := "Driver=SQLite3 ODBC Driver;Database="
if attached l_database_config.database_name as db_name then
s.append (db_name)
end
s.append (";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
create Result.make (create {DATABASE_CONNECTION_ODBC}.login_with_connection_string (s))
--create Result.make (create {DATABASE_CONNECTION_ODBC}.login_with_connection_string (l_database_config.connection_string))
end
end
end

View File

@@ -0,0 +1,14 @@
note
description: "Summary description for {CMS_USER_STORAGE_SQLITE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_USER_STORAGE_SQLITE
inherit
CMS_USER_STORAGE_SQL
end

View File

@@ -1,275 +0,0 @@
note
description: "Database access for node uses cases."
date: "$Date: 2014-11-13 12:23:47 -0300 (ju., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
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)
end
db_handler: DATABASE_HANDLER
-- Db handler.
feature -- Status Report
is_successful: BOOLEAN
-- Is the last execution sucessful?
do
Result := not db_handler.has_error
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)
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)
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
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
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
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
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
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
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
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
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
end

View File

@@ -1,193 +0,0 @@
note
description: "Summary description for {USER_DATA_PROVIDER}."
date: "$Date: 2014-11-13 12:23:47 -0300 (ju., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
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)
end
db_handler: DATABASE_HANDLER
-- Db handler.
feature -- Status Report
is_successful: BOOLEAN
-- Is the last execution sucessful?
do
Result := not db_handler.has_error
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
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
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
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
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
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
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.
end

View File

@@ -216,6 +216,7 @@ feature -- Test routines
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 ("has nodes", storage.nodes.count > 5)
assert ("Node id: 10", attached storage.node (10) as l_node and then l_node.title ~ "Title_10" )
end

View File

@@ -7,6 +7,7 @@
</option>
<setting name="concurrency" value="thread"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="..\..\..\..\..\cms-safe.ecf" readonly="false"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="model" location="..\..\..\..\model\cms_model-safe.ecf"/>
<library name="persitence_sqlite" location="..\persistence_sqlite-safe.ecf" readonly="false"/>

View File

@@ -12,8 +12,8 @@ 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")
create Result.login_with_connection_string ("Driver=SQLite3 ODBC Driver;Database=cms_lite.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
-- create Result.make_basic ("cms_lite.db")
end
end