Merge branch 'v1' into es17.01
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
<library name="encoder" location="..\..\..\library\text\encoder\encoder.ecf" readonly="false"/>
|
||||
<library name="http" location="..\..\..\library\network\protocol\http\http.ecf" readonly="false"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
|
||||
<library name="simple_db" location="support\simple_db\simple_db.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
|
||||
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri.ecf"/>
|
||||
<library name="uri_template" location="..\..\..\library\text\parser\uri_template\uri_template.ecf" readonly="false"/>
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {ORDER_JSON_SERIALIZATION}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
ORDER_JSON_SERIALIZATION
|
||||
|
||||
inherit
|
||||
JSON_SERIALIZER
|
||||
|
||||
JSON_DESERIALIZER
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
to_json (obj: detachable ANY; ctx: JSON_SERIALIZER_CONTEXT): JSON_VALUE
|
||||
-- JSON value representing the JSON serialization of Eiffel value `obj', in the eventual context `ctx'.
|
||||
local
|
||||
j_order: JSON_OBJECT
|
||||
j_item: JSON_OBJECT
|
||||
ja: JSON_ARRAY
|
||||
do
|
||||
has_error := False
|
||||
if attached {ORDER} obj as l_order then
|
||||
create j_order.make_with_capacity (4)
|
||||
Result := j_order
|
||||
j_order.put_string (l_order.id, id_key)
|
||||
if attached l_order.location as loc then
|
||||
j_order.put_string (loc, location_key)
|
||||
end
|
||||
j_order.put_string (l_order.status, status_key)
|
||||
if attached l_order.items as l_items and then not l_items.is_empty then
|
||||
create ja.make (l_items.count)
|
||||
j_order.put (ja, items_key)
|
||||
across
|
||||
l_items as ic
|
||||
loop
|
||||
if attached {ORDER_ITEM} ic.item as l_item then
|
||||
create j_item.make_with_capacity (4)
|
||||
j_item.put_string (l_item.name, name_key)
|
||||
j_item.put_string (l_item.size, size_key)
|
||||
j_item.put_integer (l_item.quantity, quantity_key)
|
||||
j_item.put_string (l_item.option, option_key)
|
||||
ja.extend (j_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
create {JSON_NULL} Result
|
||||
has_error := True
|
||||
end
|
||||
end
|
||||
|
||||
from_json (a_json: detachable JSON_VALUE; ctx: JSON_DESERIALIZER_CONTEXT; a_type: detachable TYPE [detachable ANY]): detachable ORDER
|
||||
-- <Precursor/>.
|
||||
local
|
||||
l_status: detachable STRING_32
|
||||
q: NATURAL_8
|
||||
is_valid_from_json: BOOLEAN
|
||||
l_name, l_size, l_option: detachable READABLE_STRING_32
|
||||
do
|
||||
has_error := False
|
||||
is_valid_from_json := True
|
||||
if attached {JSON_OBJECT} a_json as jobj then
|
||||
-- Either new order (i.e no id and no status)
|
||||
-- or an existing order with `id` and `status` (could be Void, thus use default).
|
||||
if attached {JSON_STRING} jobj.item (status_key) as j_status then
|
||||
l_status := j_status.unescaped_string_32
|
||||
end
|
||||
if
|
||||
attached {JSON_STRING} jobj.item (id_key) as j_id
|
||||
then
|
||||
-- Note: the id has to be valid string 8 value!
|
||||
create Result.make (j_id.unescaped_string_8, l_status)
|
||||
elseif attached {JSON_NUMBER} jobj.item (id_key) as j_id then
|
||||
-- Be flexible and accept json number as id.
|
||||
create Result.make (j_id.integer_64_item.out, l_status)
|
||||
else
|
||||
create Result.make_empty
|
||||
if l_status /= Void then
|
||||
Result.set_status (l_status)
|
||||
end
|
||||
end
|
||||
if attached {JSON_STRING} jobj.item (location_key) as j_location then
|
||||
Result.set_location (j_location.unescaped_string_32)
|
||||
end
|
||||
if attached {JSON_ARRAY} jobj.item (items_key) as j_items then
|
||||
across
|
||||
j_items as ic
|
||||
loop
|
||||
if attached {JSON_OBJECT} ic.item as j_item then
|
||||
if
|
||||
attached {JSON_NUMBER} j_item.item (quantity_key) as j_quantity and then
|
||||
j_quantity.integer_64_item < {NATURAL_8}.Max_value
|
||||
then
|
||||
q := j_quantity.integer_64_item.to_natural_8
|
||||
else
|
||||
q := 0
|
||||
end
|
||||
if
|
||||
attached {JSON_STRING} j_item.item (name_key) as j_name and then
|
||||
attached {JSON_STRING} j_item.item (size_key) as j_size and then
|
||||
attached {JSON_STRING} j_item.item (option_key) as j_option
|
||||
then
|
||||
l_name := j_name.unescaped_string_32
|
||||
l_size := j_size.unescaped_string_32
|
||||
l_option := j_option.unescaped_string_32
|
||||
if is_valid_item_customization (l_name, l_size, l_option, q) then
|
||||
Result.add_item (create {ORDER_ITEM}.make (l_name, l_size, l_option, q))
|
||||
else
|
||||
is_valid_from_json := False
|
||||
end
|
||||
else
|
||||
is_valid_from_json := False
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if not is_valid_from_json or Result.items.is_empty then
|
||||
Result := Void
|
||||
end
|
||||
else
|
||||
is_valid_from_json := a_json = Void or else attached {JSON_NULL} a_json
|
||||
Result := Void
|
||||
end
|
||||
has_error := not is_valid_from_json
|
||||
end
|
||||
|
||||
has_error: BOOLEAN
|
||||
-- Error occurred during last `from_json` or `to_json` execution.
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
id_key: STRING = "id"
|
||||
|
||||
location_key: STRING = "location"
|
||||
|
||||
status_key: STRING = "status"
|
||||
|
||||
items_key: STRING = "items"
|
||||
|
||||
name_key: STRING = "name"
|
||||
|
||||
size_key: STRING = "size"
|
||||
|
||||
quantity_key: STRING = "quantity"
|
||||
|
||||
option_key: STRING = "option"
|
||||
|
||||
feature -- Validation
|
||||
|
||||
is_valid_item_customization (name: READABLE_STRING_GENERAL; size: READABLE_STRING_GENERAL; option: READABLE_STRING_GENERAL; quantity: NATURAL_8): BOOLEAN
|
||||
local
|
||||
ic: ORDER_ITEM_VALIDATION
|
||||
do
|
||||
create ic
|
||||
Result := ic.is_valid_coffee_type (name) and
|
||||
ic.is_valid_milk_type (option) and
|
||||
ic.is_valid_size_option (size) and
|
||||
quantity > 0
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2017, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
end
|
||||
@@ -13,10 +13,9 @@ feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
local
|
||||
db: BASIC_JSON_FS_DATABASE
|
||||
db: BASIC_SED_FS_DATABASE
|
||||
do
|
||||
create db.make (database_path)
|
||||
db.serialization.register (create {ORDER_JSON_SERIALIZATION}, {ORDER})
|
||||
database := db
|
||||
end
|
||||
|
||||
|
||||
@@ -332,24 +332,135 @@ feature {NONE} -- Implementation Repository Layer
|
||||
|
||||
feature {NONE} -- Conversion
|
||||
|
||||
order_to_json (obj: ORDER): JSON_VALUE
|
||||
order_to_json (obj: ORDER): JSON_OBJECT
|
||||
local
|
||||
j_order: JSON_OBJECT
|
||||
j_item: JSON_OBJECT
|
||||
ja: JSON_ARRAY
|
||||
do
|
||||
Result := order_serialization.to_json (obj)
|
||||
end
|
||||
|
||||
order_from_json (jv: JSON_VALUE): detachable ORDER
|
||||
do
|
||||
if attached {ORDER} order_serialization.from_json (jv, {ORDER}) as o then
|
||||
Result := o
|
||||
create Result.make_with_capacity (4)
|
||||
Result.put_string (obj.id, id_key)
|
||||
if attached obj.location as loc then
|
||||
Result.put_string (loc, location_key)
|
||||
end
|
||||
Result.put_string (obj.status, status_key)
|
||||
if attached obj.items as l_items and then not l_items.is_empty then
|
||||
create ja.make (l_items.count)
|
||||
Result.put (ja, items_key)
|
||||
across
|
||||
l_items as ic
|
||||
loop
|
||||
if attached {ORDER_ITEM} ic.item as l_item then
|
||||
create j_item.make_with_capacity (4)
|
||||
j_item.put_string (l_item.name, name_key)
|
||||
j_item.put_string (l_item.size, size_key)
|
||||
j_item.put_integer (l_item.quantity, quantity_key)
|
||||
j_item.put_string (l_item.option, option_key)
|
||||
ja.extend (j_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
order_serialization: JSON_SERIALIZATION
|
||||
order_from_json (a_json: JSON_VALUE): detachable ORDER
|
||||
local
|
||||
l_status: detachable STRING_32
|
||||
q: NATURAL_8
|
||||
is_valid_from_json: BOOLEAN
|
||||
l_name, l_size, l_option: detachable READABLE_STRING_32
|
||||
do
|
||||
create Result
|
||||
Result.register (create {ORDER_JSON_SERIALIZATION}, {ORDER})
|
||||
is_valid_from_json := True
|
||||
if attached {JSON_OBJECT} a_json as jobj then
|
||||
-- Either new order (i.e no id and no status)
|
||||
-- or an existing order with `id` and `status` (could be Void, thus use default).
|
||||
if attached {JSON_STRING} jobj.item (status_key) as j_status then
|
||||
l_status := j_status.unescaped_string_32
|
||||
end
|
||||
if
|
||||
attached {JSON_STRING} jobj.item (id_key) as j_id
|
||||
then
|
||||
-- Note: the id has to be valid string 8 value!
|
||||
create Result.make (j_id.unescaped_string_8, l_status)
|
||||
elseif attached {JSON_NUMBER} jobj.item (id_key) as j_id then
|
||||
-- Be flexible and accept json number as id.
|
||||
create Result.make (j_id.integer_64_item.out, l_status)
|
||||
else
|
||||
create Result.make_empty
|
||||
if l_status /= Void then
|
||||
Result.set_status (l_status)
|
||||
end
|
||||
end
|
||||
if attached {JSON_STRING} jobj.item (location_key) as j_location then
|
||||
Result.set_location (j_location.unescaped_string_32)
|
||||
end
|
||||
if attached {JSON_ARRAY} jobj.item (items_key) as j_items then
|
||||
across
|
||||
j_items as ic
|
||||
loop
|
||||
if attached {JSON_OBJECT} ic.item as j_item then
|
||||
if
|
||||
attached {JSON_NUMBER} j_item.item (quantity_key) as j_quantity and then
|
||||
j_quantity.integer_64_item < {NATURAL_8}.Max_value
|
||||
then
|
||||
q := j_quantity.integer_64_item.to_natural_8
|
||||
else
|
||||
q := 0
|
||||
end
|
||||
if
|
||||
attached {JSON_STRING} j_item.item (name_key) as j_name and then
|
||||
attached {JSON_STRING} j_item.item (size_key) as j_size and then
|
||||
attached {JSON_STRING} j_item.item (option_key) as j_option
|
||||
then
|
||||
l_name := j_name.unescaped_string_32
|
||||
l_size := j_size.unescaped_string_32
|
||||
l_option := j_option.unescaped_string_32
|
||||
if is_valid_item_customization (l_name, l_size, l_option, q) then
|
||||
Result.add_item (create {ORDER_ITEM}.make (l_name, l_size, l_option, q))
|
||||
else
|
||||
is_valid_from_json := False
|
||||
end
|
||||
else
|
||||
is_valid_from_json := False
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if not is_valid_from_json or Result.items.is_empty then
|
||||
Result := Void
|
||||
end
|
||||
else
|
||||
is_valid_from_json := a_json = Void or else attached {JSON_NULL} a_json
|
||||
Result := Void
|
||||
end
|
||||
end
|
||||
|
||||
is_valid_item_customization (name: READABLE_STRING_GENERAL; size: READABLE_STRING_GENERAL; option: READABLE_STRING_GENERAL; quantity: NATURAL_8): BOOLEAN
|
||||
local
|
||||
ic: ORDER_ITEM_VALIDATION
|
||||
do
|
||||
create ic
|
||||
Result := ic.is_valid_coffee_type (name) and
|
||||
ic.is_valid_milk_type (option) and
|
||||
ic.is_valid_size_option (size) and
|
||||
quantity > 0
|
||||
end
|
||||
|
||||
id_key: STRING = "id"
|
||||
|
||||
location_key: STRING = "location"
|
||||
|
||||
status_key: STRING = "status"
|
||||
|
||||
items_key: STRING = "items"
|
||||
|
||||
name_key: STRING = "name"
|
||||
|
||||
size_key: STRING = "size"
|
||||
|
||||
quantity_key: STRING = "quantity"
|
||||
|
||||
option_key: STRING = "option"
|
||||
|
||||
note
|
||||
copyright: "2011-2017, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<redirection xmlns="http://www.eiffel.com/developers/xml/configuration-1-16-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.eiffel.com/developers/xml/configuration-1-16-0.xsd" uuid="1A6B9D12-25F5-4BB8-98C0-DB6FDE9CCE18" message="Obsolete: use simple_db.ecf !" location="simple_db.ecf">
|
||||
</redirection>
|
||||
24
examples/rest/restbucks_CRUD/support/simple_db/simple_db.ecf
Normal file
24
examples/rest/restbucks_CRUD/support/simple_db/simple_db.ecf
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-16-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.eiffel.com/developers/xml/configuration-1-16-0.xsd" name="simple_db" uuid="1A6B9D12-25F5-4BB8-98C0-DB6FDE9CCE18" library_target="simple_db">
|
||||
<target name="simple_db">
|
||||
<root all_classes="true"/>
|
||||
<option warning="true">
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
|
||||
<cluster name="src" location="src\" recursive="true">
|
||||
<file_rule>
|
||||
<exclude>/.*json.*\.e$</exclude>
|
||||
<condition>
|
||||
<version type="compiler" max="17.0.0.0"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
<file_rule>
|
||||
<exclude>/basic_memory_database\.e$</exclude>
|
||||
<condition>
|
||||
<concurrency value="scoop"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
</cluster>
|
||||
</target>
|
||||
</system>
|
||||
@@ -38,6 +38,12 @@ feature -- Access
|
||||
ensure
|
||||
has_not_item: not has (a_entry_type, a_id)
|
||||
end
|
||||
|
||||
wipe_out
|
||||
-- Remove all items, and delete the database
|
||||
deferred
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2017, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
@@ -1,21 +1,14 @@
|
||||
note
|
||||
description: "[
|
||||
Basic database for simple example using JSON files.
|
||||
|
||||
(no concurrency access control, ...)
|
||||
]"
|
||||
description: "Summary description for {BASIC_FS_DATABASE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
BASIC_JSON_FS_DATABASE
|
||||
deferred class
|
||||
BASIC_FS_DATABASE
|
||||
|
||||
inherit
|
||||
BASIC_DATABASE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_location: PATH)
|
||||
@@ -23,30 +16,36 @@ feature {NONE} -- Initialization
|
||||
d: DIRECTORY
|
||||
do
|
||||
location := a_location
|
||||
create serialization
|
||||
ensure_directory_exists (a_location)
|
||||
end
|
||||
|
||||
feature -- Access serialization
|
||||
|
||||
serialization: JSON_SERIALIZATION
|
||||
|
||||
feature -- Access
|
||||
|
||||
location: PATH
|
||||
|
||||
feature {NONE} -- Access
|
||||
|
||||
default_extension: detachable STRING_32
|
||||
-- Default file extension, if any.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
count_of (a_entry_type: TYPE [detachable ANY]): INTEGER
|
||||
local
|
||||
d: DIRECTORY
|
||||
ext: like default_extension
|
||||
do
|
||||
create d.make_with_path (location.extended (entry_type_name (a_entry_type)))
|
||||
if d.exists then
|
||||
ext := default_extension
|
||||
across
|
||||
d.entries as ic
|
||||
loop
|
||||
if attached ic.item.extension as e and then e.is_case_insensitive_equal ("json") then
|
||||
if
|
||||
ext = Void or else
|
||||
attached ic.item.extension as e and then e.is_case_insensitive_equal (ext) then
|
||||
Result := Result + 1
|
||||
end
|
||||
end
|
||||
@@ -62,41 +61,24 @@ feature -- Access
|
||||
end
|
||||
|
||||
item (a_entry_type: TYPE [detachable ANY]; a_id: READABLE_STRING_GENERAL): detachable ANY
|
||||
local
|
||||
f: RAW_FILE
|
||||
s: STRING
|
||||
do
|
||||
create f.make_with_path (entry_path (a_entry_type, a_id))
|
||||
if f.exists then
|
||||
create s.make (f.count)
|
||||
f.open_read
|
||||
from
|
||||
until
|
||||
f.exhausted or f.end_of_file
|
||||
loop
|
||||
f.read_stream (1_024)
|
||||
s.append (f.last_string)
|
||||
end
|
||||
f.close
|
||||
Result := serialization.from_json_string (s, a_entry_type)
|
||||
end
|
||||
Result := item_from_location (a_entry_type, entry_path (a_entry_type, a_id))
|
||||
end
|
||||
|
||||
save (a_entry_type: TYPE [detachable ANY]; a_entry: detachable ANY; cl_entry_id: CELL [detachable READABLE_STRING_GENERAL])
|
||||
local
|
||||
f: RAW_FILE
|
||||
l_id: detachable READABLE_STRING_GENERAL
|
||||
p: PATH
|
||||
do
|
||||
l_id := cl_entry_id.item
|
||||
if l_id = Void then
|
||||
l_id := next_identifier (a_entry_type)
|
||||
cl_entry_id.replace (l_id)
|
||||
end
|
||||
create f.make_with_path (entry_path (a_entry_type, l_id))
|
||||
ensure_directory_exists (f.path.parent)
|
||||
f.open_write
|
||||
f.put_string (serialization.to_json (a_entry).representation)
|
||||
f.close
|
||||
p := entry_path (a_entry_type, l_id)
|
||||
ensure_directory_exists (p.parent)
|
||||
save_item_to_location (a_entry, p)
|
||||
end
|
||||
|
||||
delete (a_entry_type: TYPE [detachable ANY]; a_id: READABLE_STRING_GENERAL)
|
||||
@@ -109,8 +91,26 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
wipe_out
|
||||
local
|
||||
d: DIRECTORY
|
||||
do
|
||||
create d.make_with_path (location)
|
||||
if d.exists then
|
||||
d.recursive_delete
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
item_from_location (a_entry_type: TYPE [detachable ANY]; p: PATH): like item
|
||||
deferred
|
||||
end
|
||||
|
||||
save_item_to_location (a_entry: detachable ANY; p: PATH)
|
||||
deferred
|
||||
end
|
||||
|
||||
ensure_directory_exists (dn: PATH)
|
||||
local
|
||||
d: DIRECTORY
|
||||
@@ -0,0 +1,75 @@
|
||||
note
|
||||
description: "[
|
||||
Basic database for simple example using JSON files.
|
||||
|
||||
(no concurrency access control, ...)
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
BASIC_JSON_FS_DATABASE
|
||||
|
||||
inherit
|
||||
BASIC_FS_DATABASE
|
||||
redefine
|
||||
make
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_location: PATH)
|
||||
do
|
||||
Precursor (a_location)
|
||||
create serialization
|
||||
end
|
||||
|
||||
feature -- Access serialization
|
||||
|
||||
serialization: JSON_SERIALIZATION
|
||||
|
||||
feature {NONE} -- Access
|
||||
|
||||
default_extension: STRING_32 = "json"
|
||||
-- Default file extension, if any.
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
item_from_location (a_entry_type: TYPE [detachable ANY]; p: PATH): like item
|
||||
local
|
||||
f: RAW_FILE
|
||||
s: STRING
|
||||
do
|
||||
create f.make_with_path (p)
|
||||
if f.exists then
|
||||
create s.make (f.count)
|
||||
f.open_read
|
||||
from
|
||||
until
|
||||
f.exhausted or f.end_of_file
|
||||
loop
|
||||
f.read_stream (1_024)
|
||||
s.append (f.last_string)
|
||||
end
|
||||
f.close
|
||||
Result := serialization.from_json_string (s, a_entry_type)
|
||||
end
|
||||
end
|
||||
|
||||
save_item_to_location (a_entry: detachable ANY; p: PATH)
|
||||
local
|
||||
f: RAW_FILE
|
||||
do
|
||||
create f.make_with_path (p)
|
||||
f.open_write
|
||||
f.put_string (serialization.to_json (a_entry).representation)
|
||||
f.close
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2017, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
@@ -1,6 +1,8 @@
|
||||
note
|
||||
description: "[
|
||||
Basic database for simple example based on memory.
|
||||
|
||||
WARNING: for now, this is a database per instance, this is not shared memory inside the same process.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
@@ -17,6 +19,8 @@ create
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
local
|
||||
b: SED_MEMORY_READER_WRITER
|
||||
do
|
||||
create collections.make (0)
|
||||
end
|
||||
@@ -72,6 +76,11 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
wipe_out
|
||||
do
|
||||
collections.wipe_out
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
next_identifier (a_entry_type: TYPE [detachable ANY]): STRING_8
|
||||
@@ -79,20 +88,22 @@ feature {NONE} -- Implementation
|
||||
i: INTEGER
|
||||
f: RAW_FILE
|
||||
s: STRING
|
||||
tb: detachable STRING_TABLE [detachable ANY]
|
||||
do
|
||||
if attached collections.item (a_entry_type) as tb then
|
||||
tb := collections.item (a_entry_type)
|
||||
if tb /= Void then
|
||||
i := tb.count
|
||||
from
|
||||
i := i + 1
|
||||
Result := i.out
|
||||
until
|
||||
not tb.has_key (Result)
|
||||
loop
|
||||
i := i + 1
|
||||
Result := i.out
|
||||
end
|
||||
else
|
||||
i := 0
|
||||
end
|
||||
from
|
||||
i := i + 1
|
||||
Result := i.out
|
||||
until
|
||||
not has (a_entry_type, Result)
|
||||
loop
|
||||
i := i + 1
|
||||
Result := i.out
|
||||
Result := "1"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
note
|
||||
description: "[
|
||||
Basic database for simple example using SED files.
|
||||
|
||||
(no concurrency access control, ...)
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
BASIC_SED_FS_DATABASE
|
||||
|
||||
inherit
|
||||
BASIC_FS_DATABASE
|
||||
redefine
|
||||
make
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_location: PATH)
|
||||
do
|
||||
Precursor (a_location)
|
||||
create serialization
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
serialization: SED_STORABLE_FACILITIES
|
||||
|
||||
feature {NONE} -- Access
|
||||
|
||||
default_extension: STRING_32 = "sed"
|
||||
-- Default file extension, if any.
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
item_from_location (a_entry_type: TYPE [detachable ANY]; p: PATH): like item
|
||||
local
|
||||
f: RAW_FILE
|
||||
l_reader: SED_MEDIUM_READER_WRITER
|
||||
s: STRING
|
||||
do
|
||||
create f.make_with_path (p)
|
||||
if f.exists then
|
||||
create s.make (f.count)
|
||||
f.open_read
|
||||
create l_reader.make_for_reading (f)
|
||||
Result := serialization.retrieved (l_reader, True)
|
||||
f.close
|
||||
end
|
||||
end
|
||||
|
||||
save_item_to_location (a_entry: detachable ANY; p: PATH)
|
||||
local
|
||||
f: RAW_FILE
|
||||
l_writer: SED_MEDIUM_READER_WRITER
|
||||
do
|
||||
create f.make_with_path (p)
|
||||
f.open_write
|
||||
if a_entry /= Void then
|
||||
create l_writer.make_for_writing (f)
|
||||
serialization.store (a_entry, l_writer)
|
||||
end
|
||||
f.close
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2017, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
38
examples/rest/restbucks_CRUD/support/simple_db/tests/a.e
Normal file
38
examples/rest/restbucks_CRUD/support/simple_db/tests/a.e
Normal file
@@ -0,0 +1,38 @@
|
||||
note
|
||||
description: "Summary description for {A}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
A
|
||||
|
||||
create
|
||||
make_with_name
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_with_name (n: STRING)
|
||||
do
|
||||
name := n
|
||||
create items.make (0)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING
|
||||
|
||||
count: INTEGER
|
||||
|
||||
items: ARRAYED_LIST [B]
|
||||
|
||||
feature -- Element change
|
||||
|
||||
extend (b: B)
|
||||
do
|
||||
items.extend (b)
|
||||
count := items.count
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
30
examples/rest/restbucks_CRUD/support/simple_db/tests/b.e
Normal file
30
examples/rest/restbucks_CRUD/support/simple_db/tests/b.e
Normal file
@@ -0,0 +1,30 @@
|
||||
note
|
||||
description: "Summary description for {B}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
B
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature
|
||||
|
||||
make (k: STRING; b: BOOLEAN; v: STRING)
|
||||
do
|
||||
key := k
|
||||
value := v
|
||||
state := b
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
key: STRING
|
||||
|
||||
value: STRING
|
||||
|
||||
state: BOOLEAN
|
||||
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
note
|
||||
description: "Summary description for {TEST_BASIC_DB_I}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
TEST_BASIC_DB_I
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_object: ANY
|
||||
local
|
||||
a: A
|
||||
b: B
|
||||
do
|
||||
create a.make_with_name ("Test")
|
||||
create b.make ("foo", True, "test-foo")
|
||||
a.extend (b)
|
||||
create b.make ("bar", True, "test-bar")
|
||||
a.extend (b)
|
||||
Result := a
|
||||
end
|
||||
|
||||
same_object (a,b: like new_object): BOOLEAN
|
||||
local
|
||||
b1,b2: B
|
||||
do
|
||||
if attached {A} a as l_a1 and attached {A} b as l_a2 then
|
||||
Result := l_a1.name.same_string (l_a2.name) and
|
||||
l_a1.count = l_a2.count
|
||||
if Result then
|
||||
from
|
||||
l_a1.items.start
|
||||
l_a2.items.start
|
||||
until
|
||||
not Result or l_a1.items.after or l_a2.items.after
|
||||
loop
|
||||
b1 := l_a1.items.item
|
||||
b2 := l_a1.items.item
|
||||
|
||||
l_a1.items.forth
|
||||
l_a2.items.forth
|
||||
end
|
||||
Result := Result and l_a1.items.after = l_a2.items.after
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,47 @@
|
||||
note
|
||||
description: "Summary description for {TEST_JSON_DB}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
TEST_JSON_DB
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
|
||||
TEST_BASIC_DB_I
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_json_db
|
||||
-- New test routine
|
||||
local
|
||||
db: BASIC_JSON_FS_DATABASE
|
||||
obj: like new_object
|
||||
cl: CELL [detachable READABLE_STRING_GENERAL]
|
||||
l_type: TYPE [detachable ANY]
|
||||
l_id: detachable READABLE_STRING_GENERAL
|
||||
do
|
||||
create db.make (create {PATH}.make_from_string ("json-db"))
|
||||
db.serialization.set_pretty_printing
|
||||
db.serialization.register_default (create{JSON_REFLECTOR_SERIALIZATION})
|
||||
|
||||
obj := new_object
|
||||
l_type := obj.generating_type
|
||||
create cl.put ("0")
|
||||
db.save (l_type, obj, cl)
|
||||
l_id := cl.item
|
||||
assert ("new id", l_id /= Void and then not l_id.is_whitespace)
|
||||
if l_id /= Void then
|
||||
assert ("has previous entry", db.has (l_type, l_id))
|
||||
if attached db.item (l_type, l_id) as l_stored_obj then
|
||||
assert ("same object", same_object (l_stored_obj, obj))
|
||||
else
|
||||
assert ("found", False)
|
||||
end
|
||||
end
|
||||
|
||||
db.wipe_out
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,47 @@
|
||||
note
|
||||
description: "Summary description for {TEST_MEMORY_DB}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
TEST_MEMORY_DB
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
|
||||
TEST_BASIC_DB_I
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_memory_db
|
||||
-- New test routine
|
||||
local
|
||||
db: BASIC_MEMORY_DATABASE
|
||||
obj: like new_object
|
||||
cl: CELL [detachable READABLE_STRING_GENERAL]
|
||||
l_type: TYPE [detachable ANY]
|
||||
l_id: detachable READABLE_STRING_GENERAL
|
||||
do
|
||||
create db.make
|
||||
obj := new_object
|
||||
l_type := obj.generating_type
|
||||
create cl.put ("0")
|
||||
db.save (l_type, obj, cl)
|
||||
l_id := cl.item
|
||||
assert ("new id", l_id /= Void and then not l_id.is_whitespace)
|
||||
if l_id /= Void then
|
||||
assert ("has previous entry", db.has (l_type, l_id))
|
||||
if attached db.item (l_type, l_id) as l_stored_obj then
|
||||
assert ("same object", l_stored_obj.is_deep_equal (obj))
|
||||
else
|
||||
assert ("found", False)
|
||||
end
|
||||
end
|
||||
db.wipe_out
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
note
|
||||
description: "[
|
||||
Eiffel tests that can be executed by testing tool.
|
||||
]"
|
||||
author: "EiffelStudio test wizard"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
testing: "type/manual"
|
||||
|
||||
class
|
||||
TEST_SED_DB
|
||||
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
|
||||
TEST_BASIC_DB_I
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_sed_db
|
||||
-- New test routine
|
||||
local
|
||||
db: BASIC_SED_FS_DATABASE
|
||||
obj: like new_object
|
||||
cl: CELL [detachable READABLE_STRING_GENERAL]
|
||||
l_type: TYPE [detachable ANY]
|
||||
l_id: detachable READABLE_STRING_GENERAL
|
||||
do
|
||||
create db.make (create {PATH}.make_from_string ("sed-db"))
|
||||
obj := new_object
|
||||
l_type := obj.generating_type
|
||||
create cl.put ("0")
|
||||
db.save (l_type, obj, cl)
|
||||
l_id := cl.item
|
||||
assert ("new id", l_id /= Void and then not l_id.is_whitespace)
|
||||
if l_id /= Void then
|
||||
assert ("has previous entry", db.has (l_type, l_id))
|
||||
if attached db.item (l_type, l_id) as l_stored_obj then
|
||||
assert ("same object", l_stored_obj.is_deep_equal (obj))
|
||||
else
|
||||
assert ("found", False)
|
||||
end
|
||||
end
|
||||
db.wipe_out
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="test_simple_db" uuid="2A955961-2B7F-4075-BD05-F75225D8A711">
|
||||
<target name="test_simple_db">
|
||||
<file_rule>
|
||||
<exclude>/\.svn$</exclude>
|
||||
<exclude>/\.git$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<root class="ANY" feature="default_create"/>
|
||||
<option warning="true" void_safety="all">
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
||||
<library name="simple_db" location="..\simple_db-safe.ecf" readonly="False"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<cluster name="tests" location=".\" recursive="true">
|
||||
<file_rule>
|
||||
<exclude>/.*json.*\.e$</exclude>
|
||||
<condition>
|
||||
<version type="compiler" max="17.0.0.0"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
<file_rule>
|
||||
<exclude>/.*memory.*\.e$</exclude>
|
||||
<condition>
|
||||
<concurrency value="scoop"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
</cluster>
|
||||
</target>
|
||||
<target name="test_simple_db_st" extends="test_simple_db">
|
||||
<setting name="concurrency" value="none"/>
|
||||
</target>
|
||||
</system>
|
||||
|
||||
Reference in New Issue
Block a user