Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EDT:Default SQL Generation"

 
(55 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=== '''         Quick Assist Support for Default SQL Generation''' ===
+
= Overview =
  
  EDT 0.7.0 release provides quick assist support for the following EGL action statements to  
+
EDT 0.7.0 release supports the following EGL action statements to generate default SQL statements:  
generate default SQL statements:
+
 
1 ADD Statement
+
#ADD Statement  
2 DELETE Statement
+
#DELETE Statement  
3 GET Statement
+
#GET Statement  
4 OPEN Statement
+
#OPEN Statement  
5 REPLACE Statement
+
#REPLACE Statement
+
 
Use examples to show how to use the feature in EDT plugin.
+
The following sections show how to use the feature in EDT.<br>
+
 
'''EGL Record Definition:'''
+
= EGL Records Definition =
''    record Product{@Table {name="Product"}}''
+
<pre>record Product{@Table {name="Product"}}
''      id bigint{@Id};''
+
  id bigint{@Id};
  name string;
+
&nbsp; &nbsp;name string;
  price float;
+
&nbsp; &nbsp;price float;  
end
+
end  
+
</pre>
+
In that Record type, the '''Id''' annotation specifies which record field is used as the primary key.&nbsp; The optional '''@Table''' annotation specifies the table to which the record is mapped.  
The above is a basic record definition, one must use annotation '''@Id''' to specific which record  
+
<pre>record OrderItem type Entity {@table{name = "OrderItem"}}
field is used as primary key, also can use annotation '''@Table''' to specify to which table the record  
+
&nbsp; &nbsp;ITEM_ID int{@Id};  
is mapped, just as 'Product' definition shows, but this is optional.
+
&nbsp; &nbsp;NAME string{ @Column { insertable=true } };  
+
&nbsp; &nbsp;IMAGE string?{ @Column { updateable=true } };  
record OrderItem type '''Entity'''{@table{name = "OrderItem"}}
+
&nbsp; &nbsp;PRICE decimal(7, 2)?;  
ITEM_ID int{@Id};
+
&nbsp; &nbsp;DESCRIPTION string?;  
NAME string{ @Column { insertable=true } };
+
end  
IMAGE string?{ @Column { updateable=true } };
+
</pre>
PRICE decimal(7, 2)?;
+
The previous definition was created from a database table schema, by use of the EGL retrieve feature.<br>
DESCRIPTION string?;
+
 
end
+
= EGL Variables Declaration =
+
<pre>basicRec Product; &nbsp; &nbsp;  
The above is an entity record definition that is generated from a table schema.
+
itemEntity OrderItem;  
+
rs SQLResultSet?;  
   
+
ds SQLDataSource? = new SQLDataSource("jdbc:derby:C:/databases/EGLDerbyR7;create=true"); &nbsp; &nbsp;
+
'''EGL Variable Definition'''
+
basicRec Product; &nbsp; &nbsp;
+
itemEntity OrderItem;
+
rs SQLResultSet?;
+
ds SQLDataSource? = new SQLDataSource("jdbc:derby:C:/databases/EGLDerbyR7;create=true"); &nbsp; &nbsp;
+
+
+
'''ADD Statement'''
+
+
'''Click anywhere in the EGL statement and press CTRL+1, and press “Add SQL Statement” proposal, '''
+
default SQL statement will be added to the above statement:
+
    (1) add basicRec to ds; //for basic record
+
+
Change To:
+
    add basicRec to ds with
+
        #sql{ insert into Product (id, name, price) values (?,&nbsp;?,&nbsp;?)};
+
+
    (2) add itemEntity to ds; //for entity record
+
+
Change To:
+
      add itemEntity to ds with
+
#sql{
+
insert into OrderItem
+
(ITEM_ID, Name, IMAGE, price, description)
+
values
+
(?,&nbsp;?,&nbsp;?,&nbsp;?,&nbsp;?)
+
};
+
+
'''DELETE Statement'''
+
    (3) delete basicRec from ds; // for basic record
+
+
Change To:
+
      delete basicRec from ds with
+
#sql{
+
delete from Product
+
where id =&nbsp;?
+
};
+
 
+
    (4) delete itemEntity from ds; //for entity record
+
+
Change To:
+
        delete itemEntity from ds with
+
#sql{
+
delete from OrderItem
+
where ITEM_ID = ?
+
};
+
+
'''GET Statement'''
+
   
+
 
   
 
   
 +
</pre>
 +
= Default SQL Generation  =
 +
 +
== ADD Statement&nbsp;<br>  ==
 +
 +
Click anywhere in the EGL SQL statement, press ctrl-1, and click '''Add SQL Statement'''.
 +
 +
Here is an example:<br>
 +
 +
*From this:<br>
 +
<pre>  add basicRec to ds;
 +
 +
</pre>
 +
*To this:
 +
<pre>  add basicRec to ds
 +
      with #sql{ insert into Product (id, name, price) values (?,&nbsp;?,&nbsp;?)};
 +
</pre>
 +
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (2) add itemEntity to ds; //for entity record <br>Change To: <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;add itemEntity to ds with <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#sql{ insert into OrderItem (ITEM_ID, Name, IMAGE, price, description) values (?,&nbsp;?,&nbsp;?,&nbsp;?,&nbsp;?) };&nbsp;
 +
 +
== DELETE Statement  ==
 +
 +
&nbsp; &nbsp; &nbsp; &nbsp; (3) delete basicRec from ds; // for basic record <br>Change To: <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delete basicRec from ds with <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #sql{ delete from Product where id =&nbsp;? };
 +
 +
&nbsp; &nbsp; &nbsp; (4) delete itemEntity from ds; //for entity record <br>Change To: <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delete itemEntity from ds with <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#sql{ delete from OrderItem where ITEM_ID =&nbsp;? };
 +
 +
== GET Statement<br>  ==
 +
 +
&nbsp; &nbsp; &nbsp;(5) GET basicRec from ds; //for basic record <br>Change To: <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GET basicRec from ds using basicRec.id with <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#sql{ select id, rtrim(name), price from Product where id =&nbsp;? };
 +
 +
&nbsp; &nbsp; &nbsp;(6) GET itemEntity from ds; //for entity record <br>Change To:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GET itemEntity from ds using itemEntity.ITEM_ID with <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#sql{ select ITEM_ID, rtrim(Name), rtrim(IMAGE), price, rtrim(description) from OrderItem where ITEM_ID =&nbsp;? };
 +
 +
== OPEN Statement  ==
 +
 +
'''&nbsp; &nbsp; &nbsp;'''(7) rows OrderItem; open rs from ds for rows; <br>Change To: <br>&nbsp; &nbsp; &nbsp; &nbsp; open rs from ds using rows.ITEM_ID with<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #sql{ select ITEM_ID, rtrim(Name), rtrim(IMAGE), price, rtrim(description) from OrderItem where ITEM_ID = &nbsp;? }; <br>
 +
 +
== REPLACE(Update) Statement&nbsp;  ==
 +
 +
'''&nbsp; &nbsp;''' (8) replace itemEntity to ds&nbsp;; <br>Change To: <br>&nbsp; &nbsp; &nbsp; &nbsp;replace itemEntity to ds with <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #sql{ update OrderItem set Name =&nbsp;?,IMAGE =&nbsp;?, price =&nbsp;?,description =&nbsp;? where ITEM_ID =&nbsp;? }&nbsp;;
 +
 +
= Current Limitation  =
  
*OPEN Statement
+
&nbsp; Note the feature can only generate default SQL statements for basic record or entity record that does not contain any entity relationship field.&nbsp;<br>
*REPLACE Statement
+
  
 
<br>  
 
<br>  
  
<br>
+
<br> <br>

Latest revision as of 14:54, 29 January 2012

Overview

EDT 0.7.0 release supports the following EGL action statements to generate default SQL statements:

  1. ADD Statement
  2. DELETE Statement
  3. GET Statement
  4. OPEN Statement
  5. REPLACE Statement

The following sections show how to use the feature in EDT.

EGL Records Definition

record Product{@Table {name="Product"}}
   id bigint{@Id};
   name string;
   price float; 
end 

In that Record type, the Id annotation specifies which record field is used as the primary key.  The optional @Table annotation specifies the table to which the record is mapped.

record OrderItem type Entity {@table{name = "OrderItem"}}
   ITEM_ID int{@Id}; 
   NAME string{ @Column { insertable=true } }; 
   IMAGE string?{ @Column { updateable=true } }; 
   PRICE decimal(7, 2)?; 
   DESCRIPTION string?; 
end 

The previous definition was created from a database table schema, by use of the EGL retrieve feature.

EGL Variables Declaration

basicRec Product;     
itemEntity OrderItem; 
rs SQLResultSet?; 
ds SQLDataSource? = new SQLDataSource("jdbc:derby:C:/databases/EGLDerbyR7;create=true");    
 

Default SQL Generation

ADD Statement 

Click anywhere in the EGL SQL statement, press ctrl-1, and click Add SQL Statement.

Here is an example:

  • From this:
   add basicRec to ds; 

  • To this:
   add basicRec to ds 
      with #sql{ insert into Product (id, name, price) values (?, ?, ?)}; 


            (2) add itemEntity to ds; //for entity record
Change To:
             add itemEntity to ds with
                             #sql{ insert into OrderItem (ITEM_ID, Name, IMAGE, price, description) values (?, ?, ?, ?, ?) }; 

DELETE Statement

        (3) delete basicRec from ds; // for basic record
Change To:
          delete basicRec from ds with
                  #sql{ delete from Product where id = ? };

      (4) delete itemEntity from ds; //for entity record
Change To:
         delete itemEntity from ds with
                 #sql{ delete from OrderItem where ITEM_ID = ? };

GET Statement

     (5) GET basicRec from ds; //for basic record
Change To:
         GET basicRec from ds using basicRec.id with
                   #sql{ select id, rtrim(name), price from Product where id = ? };

     (6) GET itemEntity from ds; //for entity record
Change To:
         GET itemEntity from ds using itemEntity.ITEM_ID with
                   #sql{ select ITEM_ID, rtrim(Name), rtrim(IMAGE), price, rtrim(description) from OrderItem where ITEM_ID = ? };

OPEN Statement

     (7) rows OrderItem; open rs from ds for rows;
Change To:
        open rs from ds using rows.ITEM_ID with
                  #sql{ select ITEM_ID, rtrim(Name), rtrim(IMAGE), price, rtrim(description) from OrderItem where ITEM_ID =  ? };

REPLACE(Update) Statement 

    (8) replace itemEntity to ds ;
Change To:
       replace itemEntity to ds with
                #sql{ update OrderItem set Name = ?,IMAGE = ?, price = ?,description = ? where ITEM_ID = ? } ;

Current Limitation

  Note the feature can only generate default SQL statements for basic record or entity record that does not contain any entity relationship field. 




Back to the top