Add new expression type 'xser' to represent series expressions,
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 27 May 2010 16:10:50 +0000 (16:10 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 27 May 2010 16:10:50 +0000 (16:10 +0000)
i.e. a series of expressions separated by operators, such as a
chain of ANDed conditions.

M    Open-ILS/src/sql/Pg/002.schema.config.sql
M    Open-ILS/src/sql/Pg/008.schema.query.sql
A    Open-ILS/src/sql/Pg/upgrade/0280.schema.query-xser.sql
M    Open-ILS/examples/fm_IDL.xml

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16521 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/008.schema.query.sql
Open-ILS/src/sql/Pg/upgrade/0280.schema.query-xser.sql [new file with mode: 0644]

index 2992e75..db79806 100644 (file)
@@ -6864,7 +6864,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
                        <link field="subquery" reltype="has_a" key="id" map="" class="qsq"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <link field="subquery" reltype="has_a" key="id" map="" class="qsq"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
@@ -6899,8 +6899,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
-                       <link field="function_id" reltype="might_have" key="id" map="" class="qfs"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+                       <link field="function_id" reltype="has_a" key="id" map="" class="qfs"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
@@ -6917,9 +6917,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
-                       <link field="left_operand" reltype="might_have" key="id" map="" class="qxp"/>
-                       <link field="subquery" reltype="might_have" key="id" map="" class="qsq"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+                       <link field="left_operand" reltype="has_a" key="id" map="" class="qxp"/>
+                       <link field="subquery" reltype="has_a" key="id" map="" class="qsq"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
@@ -6935,8 +6935,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
-                       <link field="left_operand" reltype="might_have" key="id" map="" class="qxp"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+                       <link field="left_operand" reltype="has_a" key="id" map="" class="qxp"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
@@ -6951,7 +6951,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
@@ -6966,7 +6966,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Literal" name="literal" reporter:datatype="text"/>
                </fields>
                <links>
                        <field reporter:label="Literal" name="literal" reporter:datatype="text"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
@@ -6984,9 +6984,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
                        <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
-                       <link field="left_operand" reltype="might_have" key="id" map="" class="qxp"/>
-                       <link field="right_operand" reltype="might_have" key="id" map="" class="qxp"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+                       <link field="left_operand" reltype="has_a" key="id" map="" class="qxp"/>
+                       <link field="right_operand" reltype="has_a" key="id" map="" class="qxp"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+               </permacrud>
+       </class>
+
+       <class id="xser" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="query::expr_xser" oils_persist:tablename="query.expr_xser" reporter:label="Operator Expression">
+               <fields oils_persist:primary="id" oils_persist:sequence="expression_id_seq">
+                       <field reporter:label="Expression ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Is Parenthesized" name="parenthesize" reporter:datatype="bool"/>
+                       <field reporter:label="Parent Expression" name="parent_expr" reporter:datatype="link"/>
+                       <field reporter:label="Sequence Number" name="seq_no" reporter:datatype="int"/>
+                       <field reporter:label="Operator" name="operator" reporter:datatype="text"/>
+                       <field reporter:label="Negate?" name="negate" reporter:datatype="bool"/>
+               </fields>
+               <links>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
@@ -7001,7 +7017,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Literal" name="literal" reporter:datatype="text"/>
                </fields>
                <links>
                        <field reporter:label="Literal" name="literal" reporter:datatype="text"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
@@ -7016,8 +7032,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Subquery" name="subquery" reporter:datatype="link"/>
                </fields>
                <links>
                        <field reporter:label="Subquery" name="subquery" reporter:datatype="link"/>
                </fields>
                <links>
-                       <link field="parent_expr" reltype="might_have" key="id" map="" class="qxp"/>
-                       <link field="subquery" reltype="might_have" key="id" map="" class="qsq"/>
+                       <link field="parent_expr" reltype="has_a" key="id" map="" class="qxp"/>
+                       <link field="subquery" reltype="has_a" key="id" map="" class="qsq"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                </permacrud>
index 132ddaf..93f2a6d 100644 (file)
@@ -65,7 +65,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0279'); -- atz / senator
+INSERT INTO config.upgrade_log (version) VALUES ('0280'); -- Scott McKellar
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index dccb1a6..1a91d66 100644 (file)
@@ -138,6 +138,7 @@ CREATE TABLE query.expression (
                                        'xnull',   -- null
                                                                        'xnum',    -- number
                                                                        'xop',     -- operator
                                        'xnull',   -- null
                                                                        'xnum',    -- number
                                                                        'xop',     -- operator
+                                                                       'xser',    -- series
                                                                        'xstr',    -- string
                                                'xsubq'    -- subquery
                                                                ) ),
                                                                        'xstr',    -- string
                                                'xsubq'    -- subquery
                                                                ) ),
@@ -1085,6 +1086,61 @@ CREATE OR REPLACE RULE query_expr_xop_delete_rule AS
     DO INSTEAD
     DELETE FROM query.expression WHERE id = OLD.id;
 
     DO INSTEAD
     DELETE FROM query.expression WHERE id = OLD.id;
 
+-- Create updatable view for series expressions,
+-- i.e. series of expressions separated by operators
+
+CREATE OR REPLACE VIEW query.expr_xser AS
+    SELECT
+               id,
+               parenthesize,
+               parent_expr,
+               seq_no,
+               operator,
+               negate
+    FROM
+        query.expression
+    WHERE
+        type = 'xser';
+
+CREATE OR REPLACE RULE query_expr_xser_insert_rule AS
+    ON INSERT TO query.expr_xser
+    DO INSTEAD
+    INSERT INTO query.expression (
+               id,
+               type,
+               parenthesize,
+               parent_expr,
+               seq_no,
+               operator,
+               negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xser',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+               NEW.operator,
+               NEW.negate
+    );
+
+CREATE OR REPLACE RULE query_expr_xser_update_rule AS
+    ON UPDATE TO query.expr_xser
+    DO INSTEAD
+    UPDATE query.expression SET
+        id = NEW.id,
+        parenthesize = NEW.parenthesize,
+        parent_expr = NEW.parent_expr,
+        seq_no = NEW.seq_no,
+               operator = NEW.operator,
+               negate = NEW.negate
+    WHERE
+        id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xser_delete_rule AS
+    ON DELETE TO query.expr_xser
+    DO INSTEAD
+    DELETE FROM query.expression WHERE id = OLD.id;
+
 -- Create updatable view for string literal expressions
 
 CREATE OR REPLACE VIEW query.expr_xstr AS
 -- Create updatable view for string literal expressions
 
 CREATE OR REPLACE VIEW query.expr_xstr AS
diff --git a/Open-ILS/src/sql/Pg/upgrade/0280.schema.query-xser.sql b/Open-ILS/src/sql/Pg/upgrade/0280.schema.query-xser.sql
new file mode 100644 (file)
index 0000000..be85fb6
--- /dev/null
@@ -0,0 +1,87 @@
+BEGIN;
+
+-- Create new expression type 'xser' for serial expressions,
+-- i.e. series of expressions separated by operators
+
+INSERT INTO config.upgrade_log (version) VALUES ('0280'); -- Scott McKellar
+
+ALTER TABLE query.expression
+       DROP CONSTRAINT expression_type;
+
+ALTER TABLE query.expression
+       ADD CONSTRAINT expression_type CHECK
+    ( type IN (
+         'xbet',    -- between
+         'xbind',   -- bind variable
+         'xbool',   -- boolean
+         'xcase',   -- case
+         'xcast',   -- cast
+         'xcol',    -- column
+         'xex',     -- exists
+         'xfld',    -- field
+         'xfunc',   -- function
+         'xin',     -- in
+         'xisnull', -- is null
+         'xnull',   -- null
+         'xnum',    -- number
+         'xop',     -- operator
+         'xser',    -- series
+         'xstr',    -- string
+         'xsubq'    -- subquery
+    ) );
+
+-- Create updatable view for series expressions
+
+CREATE OR REPLACE VIEW query.expr_xser AS
+    SELECT
+               id,
+               parenthesize,
+               parent_expr,
+               seq_no,
+               operator,
+               negate
+    FROM
+        query.expression
+    WHERE
+        type = 'xser';
+
+CREATE OR REPLACE RULE query_expr_xser_insert_rule AS
+    ON INSERT TO query.expr_xser
+    DO INSTEAD
+    INSERT INTO query.expression (
+               id,
+               type,
+               parenthesize,
+               parent_expr,
+               seq_no,
+               operator,
+               negate
+    ) VALUES (
+        COALESCE(NEW.id, NEXTVAL('query.expression_id_seq'::REGCLASS)),
+        'xser',
+        COALESCE(NEW.parenthesize, FALSE),
+        NEW.parent_expr,
+        COALESCE(NEW.seq_no, 1),
+               NEW.operator,
+               NEW.negate
+    );
+
+CREATE OR REPLACE RULE query_expr_xser_update_rule AS
+    ON UPDATE TO query.expr_xser
+    DO INSTEAD
+    UPDATE query.expression SET
+        id = NEW.id,
+        parenthesize = NEW.parenthesize,
+        parent_expr = NEW.parent_expr,
+        seq_no = NEW.seq_no,
+               operator = NEW.operator,
+               negate = NEW.negate
+    WHERE
+        id = OLD.id;
+
+CREATE OR REPLACE RULE query_expr_xser_delete_rule AS
+    ON DELETE TO query.expr_xser
+    DO INSTEAD
+    DELETE FROM query.expression WHERE id = OLD.id;
+
+COMMIT;