Added weight into to the CMS_LINK and provide a `sort' feature for CMS_MENU and related.
Protected cms service from registering many time the same module type.
Moved library/persistence/implementation/* under library/persistence/.
Moved site/www/themes to site/themes
For SQLite storage driver, auto create sqlite db file using associated sql script (to be completed).
Added code in demo module to reuse storage for module purpose.
Always call sql_post_execution in sql_query and sql_change, and not anymore by the callers.
Removed is_web and is_html from {CMS_SETUP}, it was not used.
Reused SHARED_*_ENCODER in CMS_ENCODERS
Added CMS_API.logger rather than using directly the SHARED_LOGGER.log ...
Centralize the implementation of current_user in CMS_REQUEST_UTIL
Removed the inheritance on WSF_FILTER for node handlers, since it is useless and unused.
Added CMS_NODE_API and CMS_USER_API
Prefix html id for block generated html items with "block-", to avoid css name conflict on "main", "content" or similar.
Code cleaning
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
note
|
||||
description: "Abstract class to handle a database connection"
|
||||
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
|
||||
revision: "$Revision: 95678 $"
|
||||
|
||||
deferred class
|
||||
DATABASE_CONNECTION
|
||||
|
||||
inherit
|
||||
|
||||
DATABASE_CONFIG
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_common
|
||||
-- Create a database handler with common settings.
|
||||
deferred
|
||||
ensure
|
||||
db_application_not_void: db_application /= Void
|
||||
db_control_not_void: db_control /= Void
|
||||
end
|
||||
|
||||
make_basic ( a_database_name: STRING)
|
||||
-- Create a database handler with common settings and
|
||||
-- set database_name with `a_database_name'.
|
||||
require
|
||||
database_name_not_void: a_database_name /= Void
|
||||
database_name_not_empty: not a_database_name.is_empty
|
||||
deferred
|
||||
ensure
|
||||
db_application_not_void: db_application /= Void
|
||||
db_control_not_void: db_control /= Void
|
||||
end
|
||||
|
||||
make (a_username: STRING; a_password: STRING; a_hostname: STRING; a_database_name: STRING; connection: BOOLEAN)
|
||||
|
||||
-- Create a database handler with user `a_username', password `a_password',
|
||||
-- host `a_hostname', database_name `a_database_name', and keep_connection `connection'.
|
||||
require
|
||||
username_not_void: a_username /= Void
|
||||
username_not_empty: not a_username.is_empty
|
||||
password_not_void: a_password /= Void
|
||||
hostname_not_void: a_hostname /= Void
|
||||
hotname_not_empty: not a_hostname.is_empty
|
||||
database_name_not_void: a_database_name /= Void
|
||||
database_name_not_empty: not a_database_name.is_empty
|
||||
deferred
|
||||
ensure
|
||||
db_application_not_void: db_application /= Void
|
||||
db_control_not_void: db_control /= Void
|
||||
end
|
||||
|
||||
login_with_connection_string (a_connection_string: STRING)
|
||||
-- Login with `a_connection_string'
|
||||
-- and immediately connect to database.
|
||||
deferred
|
||||
ensure
|
||||
db_application_not_void: db_application /= Void
|
||||
db_control_not_void: db_control /= Void
|
||||
end
|
||||
|
||||
feature -- Database Setup
|
||||
|
||||
db_application: DATABASE_APPL [DATABASE]
|
||||
-- Database application.
|
||||
|
||||
db_control: DB_CONTROL
|
||||
-- Database control.
|
||||
|
||||
keep_connection: BOOLEAN
|
||||
-- Keep connection alive?
|
||||
|
||||
feature -- Transactions
|
||||
|
||||
begin_transaction
|
||||
-- Start a transaction which will be terminated by a call to `rollback' or `commit'.
|
||||
local
|
||||
rescued: BOOLEAN
|
||||
do
|
||||
if not rescued then
|
||||
if db_control.is_ok then
|
||||
db_control.begin
|
||||
else
|
||||
database_error_handler.add_database_error (db_control.error_message_32, db_control.error_code)
|
||||
end
|
||||
end
|
||||
rescue
|
||||
rescued := True
|
||||
exception_as_error ((create {EXCEPTION_MANAGER}).last_exception)
|
||||
db_control.reset
|
||||
retry
|
||||
end
|
||||
|
||||
commit
|
||||
-- Commit updates in the database.
|
||||
local
|
||||
rescued: BOOLEAN
|
||||
do
|
||||
if not rescued then
|
||||
if db_control.is_ok then
|
||||
db_control.commit
|
||||
else
|
||||
database_error_handler.add_database_error (db_control.error_message_32, db_control.error_code)
|
||||
end
|
||||
end
|
||||
rescue
|
||||
rescued := True
|
||||
exception_as_error ((create {EXCEPTION_MANAGER}).last_exception)
|
||||
db_control.reset
|
||||
retry
|
||||
end
|
||||
|
||||
rollback
|
||||
-- Rollback updates in the database.
|
||||
local
|
||||
rescued: BOOLEAN
|
||||
do
|
||||
if not rescued then
|
||||
if db_control.is_ok then
|
||||
db_control.rollback
|
||||
else
|
||||
database_error_handler.add_database_error (db_control.error_message_32, db_control.error_code)
|
||||
end
|
||||
end
|
||||
rescue
|
||||
rescued := True
|
||||
exception_as_error ((create {EXCEPTION_MANAGER}).last_exception)
|
||||
db_control.reset
|
||||
retry
|
||||
end
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
not_keep_connection
|
||||
do
|
||||
keep_connection := False
|
||||
end
|
||||
|
||||
feature -- Conection
|
||||
|
||||
connect
|
||||
-- Connect to the database.
|
||||
require else
|
||||
db_control_not_void: db_control /= Void
|
||||
do
|
||||
if not is_connected then
|
||||
db_control.connect
|
||||
end
|
||||
end
|
||||
|
||||
disconnect
|
||||
-- Disconnect from the database.
|
||||
require else
|
||||
db_control_not_void: db_control /= Void
|
||||
do
|
||||
db_control.disconnect
|
||||
end
|
||||
|
||||
is_connected: BOOLEAN
|
||||
-- True if connected to the database.
|
||||
require else
|
||||
db_control_not_void: db_control /= Void
|
||||
do
|
||||
Result := db_control.is_connected
|
||||
end
|
||||
|
||||
feature -- Error Handling
|
||||
|
||||
database_error_handler: DATABASE_ERROR_HANDLER
|
||||
-- Error handler.
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
has_error: BOOLEAN
|
||||
-- Has error?
|
||||
do
|
||||
Result := database_error_handler.has_error
|
||||
end
|
||||
|
||||
feature -- Helper
|
||||
|
||||
exception_as_error (a_e: like {EXCEPTION_MANAGER}.last_exception)
|
||||
-- Record exception as an error.
|
||||
do
|
||||
if attached a_e as l_e and then attached l_e.trace as l_trace then
|
||||
database_error_handler.add_error_details (l_e.code, once "Exception", l_trace.as_string_32)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user