|
|
(68 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
− | Please [[#Share_a_code_snippet|share your code snippets]]! <br>
| + | * [[EDT:Declaring data|Declaring values of EGL native types]] |
| | | |
− | [[Declaring_data | Declaring data]] | + | * [[EDT:Working with custom types|Working with custom types]] |
| | | |
| + | * [[EDT:Writing statements|Writing statements]] |
| | | |
− | == Declaring data <br> ==
| + | * [[EDT:Working with a database|Working with a database]] |
| | | |
− | Native types:
| + | * [[EDT:Accessing a service|Accessing a service]] |
| | | |
− | :Simple value types: | + | * [[EDT:Writing a Rich UI application|Writing a Rich UI application]] |
| | | |
− | ::BigInt, Bytes(''n''), Date, Decimal(''n''), Decimal(''n'', ''p''),
| + | <br><br> |
| | | |
− | ::Float, Int, SmallFloat, SmallInt, Timestamp(''pattern'') | + | To share a code snippet: |
| | | |
− | :Simple reference types: | + | *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> <source lang="java"> |
| + | // put code here |
| + | </source> |
| + | |
| + | </pre> |
| + | *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 [[EDT:How to Create/Edit Wiki pages|these instructions]]. |
| | | |
− | ::Bytes, Decimal, Number, String (now a value type),
| + | For help with editing, see [http://meta.wikimedia.org/wiki/Help:Wikitext_examples Wikitext examples]. |
− | | + | |
− | ::String(''n''), Timestamp (now a value type) | + | |
− | | + | |
− | :Other reference types:
| + | |
− | | + | |
− | ::Any, Dictionary, List
| + | |
− | | + | |
− | Classifiers for custom types:
| + | |
− | | + | |
− | :Delegate, Enumeration, ExternalType, Handler,
| + | |
− | :Interface, Library, Program, Record, Service
| + | |
− | | + | |
− | | + | |
− | | + | |
− | | + | |
− | '''Variables of simple value types'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | // defaults to 0 | + | |
− | someVal Int;
| + | |
− | | + | |
− | // defaults to null.
| + | |
− | someVal Int?;
| + | |
− | | + | |
− | // initializes value to 15 (future value can be null).
| + | |
− | someVal Int? = 15;
| + | |
− | | + | |
− | // initializes value to 23. | + | |
− | someVal Int = 23;
| + | |
− | | + | |
− | // defaults to "".
| + | |
− | firstName String;
| + | |
− | | + | |
− | // defaults to null.
| + | |
− | firstName String?;
| + | |
− | | + | |
− | // initializes value to "John".
| + | |
− | firstName String = "John";
| + | |
− | | + | |
− | // number with 5 total digits (2 after the decimal point). Defaults to 000.00.
| + | |
− | amount Decimal(5,2);
| + | |
− | | + | |
− | // defaults to 0.0.
| + | |
− | coord Float;
| + | |
− | | + | |
− | // defaults to false
| + | |
− | toggle Boolean;
| + | |
− | | + | |
− | // defaults to today's date.
| + | |
− | dob Date;
| + | |
− | | + | |
− | // defaults to the current timestamp.
| + | |
− | ts Timestamp?;
| + | |
− | | + | |
− | // value can be set to any value (primitive, object, etc). See the casting examples later.
| + | |
− | x Any?;
| + | |
− | </source>
| + | |
− | | + | |
− | '''Lists'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | | + | |
− | vals Int[]; // new dynamic array of size 0
| + | |
− | vals Int[]?; // dynamic list, but not instantiated (vals must be instantiated before it can be accessed)
| + | |
− | vals Int[] = new Int[4]; // new dynamic array of size 4; all values set to their default value (0 in this example)
| + | |
− | | + | |
− | names String[] = [ "Paul", "John", "George", "Ringo" ]; // dynamic array, initialized with 4 values
| + | |
− | names[1] = "Bob"; // assigns the first index in the array to "Bob"
| + | |
− | names[names.getSize()] = "Ken"; // assigns the last index in the array to "Ken"
| + | |
− | | + | |
− | cities String[]; // new dynamic array of size 0
| + | |
− | cities.appendElement("Delta"); // appends a new value to the end of the array
| + | |
− | cities.appendAll([ "Denver", "Pueblo" ]); // appends two new values to the end of the list cities.removeElement(2); // removes the second value in the array
| + | |
− | cities.removeAll(); // removes all values from the array
| + | |
− | | + | |
− | </source>
| + | |
− | | + | |
− | <br> '''Constants'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | // The value is not changeable.
| + | |
− | const NUMBEROFDAYS Int = 7;
| + | |
− | | + | |
− | // The element values are changeable, but the name cannot refer to another list.
| + | |
− | const MINIMUMNUMBERS INT[] = [1,2,3,4,5];
| + | |
− | </source>
| + | |
− | | + | |
− | <br>
| + | |
− | | + | |
− | <br> <br>
| + | |
− | | + | |
− | <br>
| + | |
− | | + | |
− | == Rich UI ==
| + | |
− | | + | |
− | == Services ==
| + | |
− | | + | |
− | '''Calling a REST service'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | http HttpRest{request.uri="http:host\\myService"};
| + | |
− | srvc IRest?;
| + | |
− | srvc = ServiceLib.completeBind(srvc, http);
| + | |
− | </source>
| + | |
− | | + | |
− | '''Accessing HTTP request headers'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | http HttpRest{};
| + | |
− | http.request.headers = new Dictionary { param1 = "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 ==
| + | |
− | | + | |
− | '''Defining a record'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | record CUSTOMER type Entity{@table{name = "CUSTOMER"}} // record is bound to the CUSTOMER table (or view)
| + | |
− | CUSTID string{@id}; // primary key field
| + | |
− | NAME string;
| + | |
− | COUNTRY string;
| + | |
− | STATE string?; // nullable field
| + | |
− | end
| + | |
− | </source>
| + | |
− | | + | |
− | '''Getting a record'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | function getCustomer(someId String in} returns (Customer)
| + | |
− | ds SQLDataSource?{@resource {}}; // declares a data source that will use binding name "ds" (since a name is not specified)
| + | |
− | | + | |
− | aCust Customer; // declares and empty customer record
| + | |
− | get aCust from ds using(someId); // gets the record in the table that has a key value of someID and populates the customer record
| + | |
− | | + | |
− | get aCust from ds using(someId) with #sql{ // alternative approach for getting a single record (allows for customizing the SQL)
| + | |
− | SELECT *
| + | |
− | FROM CUSTOMER
| + | |
− | WHERE id = ?
| + | |
− | };
| + | |
− | | + | |
− | vals Dictionary; // declares a new dictionary
| + | |
− | get vals from ds using(someId) with #sql{ // alternative approach for getting a single record (does not require a Record definition)
| + | |
− | SELECT *
| + | |
− | FROM CUSTOMER
| + | |
− | WHERE id = ?
| + | |
− | }; // creates a key/value pair in the dictionary for each column in the result set
| + | |
− | | + | |
− | return (aCust);
| + | |
− | end
| + | |
− | </source>
| + | |
− | | + | |
− | '''Getting multiple records''' <source lang="java">
| + | |
− | function getCustomer(} returns (Customer[])
| + | |
− | ds SQLDataSource?{@resource {}}; // declares a data source that will use binding name "ds" (since a name is not specified)
| + | |
− | | + | |
− | custs Customer[]; // declares a new dynamic array of customer records
| + | |
− | get custs from ds; // populates the array with a Customer record for each row in the result set
| + | |
− | | + | |
− | get custs from ds with #sql {
| + | |
− | select * from customer where state = 'CO'
| + | |
− | }; // populates the array, but with a limited set of Customer records
| + | |
− | | + | |
− | state String = "CO";
| + | |
− | get custs from ds using(state) with #sql {
| + | |
− | select * from customer where state = ?
| + | |
− | }; // parameterized version of the previous example
| + | |
− | | + | |
− | | + | |
− | end
| + | |
− | </source>
| + | |
− | | + | |
− | '''Inserting a record'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | function addCustomer{customer Customer in}
| + | |
− | ds SQLDataSource?{@resource {}};
| + | |
− | add customer to ds;
| + | |
− | end
| + | |
− | </source>
| + | |
− | | + | |
− | '''Looping through a SQL result set'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | function loopCust()
| + | |
− | ds SQLDataSource?{@resource{uri = "binding:myDB" }}; // declares a new data source
| + | |
− | rs SQLResultSet?; // declares a new result set
| + | |
− | | + | |
− | open rs from ds with #sql{ // opens a result set using the specified SQL query
| + | |
− | 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]] |