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:Code snippets"

(Declare variable)
 
(103 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Real code for real people!
+
* [[EDT:Declaring data|Declaring values of EGL native types]]
  
Please [[#Share_a_code_snippet|share your code snippets]]! <br>
+
* [[EDT:Working with custom types|Working with custom types]]  
  
== General  ==
+
* [[EDT:Writing statements|Writing statements]]
  
==== Declare variable  ====
+
* [[EDT:Working with a database|Working with a database]]
  
<source lang="java">
+
* [[EDT:Accessing a service|Accessing a service]]
someVal int;                // defaults to 0
+
someVal int?;              // defaults to null
+
someVal int? = 15;          // initializes value to 15 (future value can be null)
+
someVal int = 23;          // initializes value to 23
+
  
firstName string;          // defaults to ""
+
* [[EDT:Writing a Rich UI application|Writing a Rich UI application]]
firstName string?;          // defaults to null
+
firstName string = "John";  // initializes value to "John"
+
  
largeVal bigint;            // defaults to 0
+
<br><br>
amount decimal(5,2);        // number with 5 total digits (2 after the decimal point). Defaults to 000.00;
+
coord float;                // defaults to 0.0
+
toggle boolean;            // defaults to false
+
  
dob date;                  // defaults to today's date
+
To share a code snippet:
ts timestamp?;
+
  
x any?;                     // value can be set to any value (primitive, object, etc). See casting examples below.
+
*On the page of interest, click '''Edit''' and, if necessary, log in to eclipse.org.
 +
*Add a section or update an existing one; but always include your code in the following wikitext markup:<br>
 +
<pre>        &lt;source lang="java"&gt;
 +
          // put code here
 +
        &lt;/source&gt;
 +
 +
</pre>
 +
*The &lt;source&gt; tag is used instead of &lt;code&gt; or &lt;pre&gt; since it provides syntax highlighting similar to an advanced source code editor. We use the Java language highlighting, since a highlighter for EGL doesn't exist (yet). If you are interested in writing a syntax highlighter for EGL, the GeSHi (Generic Syntax Highlighter) extension is used.
 +
* For longer examples, consider adding line numbers using line="GESHI_NORMAL_LINE_NUMBERS" in the source tag, though for some reason then the snippet doesn't appear in a colored background.
 +
*To add most of your content, click Wikitext or disable the Rich Editor.
 +
*Before you create a new page, read [[EDT:How to Create/Edit Wiki pages|these instructions]].
  
</source>
+
For help with editing, see [http://meta.wikimedia.org/wiki/Help:Wikitext_examples Wikitext examples]. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
 
+
==== Declare constant  ====
+
 
+
<source lang="java">
+
const NUMBEROFDAYS INT = 7;
+
</source>
+
 
+
==== Denote Nullability  ====
+
 
+
<source lang="java">
+
myInt Int[]?;
+
</source>
+
 
+
<br>
+
 
+
<br>
+
 
+
== Rich UI  ==
+
 
+
== Services  ==
+
 
+
==== Dynamic URI  ====
+
 
+
<source lang="java">
+
http HttpRest{request.uri="http:host\\myService"};
+
srvc IRest?;
+
srvc = ServiceLib.completeBind(srvc, http);
+
</source>
+
 
+
==== HTTP Request Headers  ====
+
 
+
<source lang="java">
+
http HttpRest{};
+
http.request.headers = new Dictionary{key1="a value to pass to my service"};
+
srvc IRest?{@Resource {}};
+
srvc = ServiceLib.completeBind(srvc, http);
+
</source>
+
 
+
==== HTTP Request and Response  ====
+
 
+
<source lang="java">
+
function invokeDoSomething()
+
    call srvc.doSomething() returning to serviceCallback;
+
end
+
 
+
function serviceCallback(returnValueOne String, callbackHttp IHTTP in)
+
  // process callback request or response
+
end
+
</source>
+
 
+
== Database access  ==
+
 
+
==== Record definition  ====
+
 
+
<source lang="java">
+
record CUSTOMER type Entity{@table{name = "CUSTOMER"}}
+
    NAME string
+
    COUNTRY string{@id};
+
    STATE string?;
+
    CUSTID string;
+
end
+
</source>
+
 
+
==== Get a record  ====
+
 
+
<source lang="java">
+
function getCust{id String in} returns (Customer)
+
    ds SQLDataSource?{@resource {}};
+
    aCust Customer;
+
    get aCust from ds using(id);
+
    return (aCust);
+
end
+
</source>
+
 
+
==== Add a record  ====
+
 
+
<source lang="java">
+
function addCust{customer Customer in}
+
    ds SQLDataSource?{@resource {}};
+
    add customer to ds;
+
end
+
</source>
+
 
+
==== Loop through a SQL result set  ====
+
 
+
<source lang="java">
+
function loopCust()
+
    ds SQLDataSource?{@resource{bindingkey = "MyDB"}};
+
    rs SQLResultSet?;
+
 
+
    open rs from ds with #sql{
+
SELECT * FROM CUSTOMER
+
    };
+
 
+
    myCust Customer;
+
 
+
    //Loop through results and write out customer name
+
    while(rs.getNext())
+
        get myCust from rs;
+
        Syslib.writeStdOut ("Customer name: " + myCust.name);
+
    end
+
 
+
end
+
</source>
+
 
+
<br>
+
 
+
== Share a code snippet  ==
+
 
+
Edit this page by logging in to eclipse.org and clicking the Edit tab. Use the Wikitext editor to add a new snippet. Add the title using Heading 4. Use the '''source lang="java"''' tag to provide a background for your snippet and some syntax highlighting.
+
  
 
[[Category:EDT]]
 
[[Category:EDT]]

Latest revision as of 15:15, 6 March 2012



To share a code snippet:

  • On the page of interest, click Edit and, if necessary, log in to eclipse.org.
  • Add a section or update an existing one; but always include your code in the following wikitext markup:
        <source lang="java">
          // put code here 
        </source>
 
  • The <source> tag is used instead of <code> or <pre> since it provides syntax highlighting similar to an advanced source code editor. We use the Java language highlighting, since a highlighter for EGL doesn't exist (yet). If you are interested in writing a syntax highlighter for EGL, the GeSHi (Generic Syntax Highlighter) extension is used.
  • For longer examples, consider adding line numbers using line="GESHI_NORMAL_LINE_NUMBERS" in the source tag, though for some reason then the snippet doesn't appear in a colored background.
  • To add most of your content, click Wikitext or disable the Rich Editor.
  • Before you create a new page, read these instructions.

For help with editing, see Wikitext examples.       

Back to the top