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"

Line 34: Line 34:
  
 
<source lang="java">
 
<source lang="java">
http HttpRest{request.uri="http:host\myService"};
+
http HttpRest{request.uri="http:host\\myService"};
 
srvc IRest?;
 
srvc IRest?;
 
srvc = ServiceLib.completeBind(srvc, http);
 
srvc = ServiceLib.completeBind(srvc, http);
Line 46: Line 46:
 
srvc IRest?{@Resource {}};
 
srvc IRest?{@Resource {}};
 
srvc = ServiceLib.completeBind(srvc, http);
 
srvc = ServiceLib.completeBind(srvc, http);
</source>
+
</source>  
  
 
==== HTTP Request and Response  ====
 
==== HTTP Request and Response  ====
Line 58: Line 58:
 
   // process callback request or response
 
   // process callback request or response
 
end
 
end
</source>
+
</source>  
  
 
== Database access  ==
 
== Database access  ==

Revision as of 11:10, 6 January 2012

Real code for real people!

Please share your code snippets!

General

Declare variable

NumberOfWeeks Int;

Declare constant

const NUMBEROFDAYS INT = 7;

Denote Nullability

myInt Int[]?;



Rich UI

Services

Dynamic URI

http HttpRest{request.uri="http:host\\myService"};
srvc IRest?;
srvc = ServiceLib.completeBind(srvc, http);

HTTP Request Headers

http HttpRest{};
http.request.headers = new Dictionary{key1="a value to pass to my service"};
srvc IRest?{@Resource {}};
srvc = ServiceLib.completeBind(srvc, http);

HTTP Request and Response

function invokeDoSomething()
    call srvc.doSomething() returning to serviceCallback;
end
 
function serviceCallback(returnValueOne String, callbackHttp IHTTP in)
  // process callback request or response
end

Database access

Record definition

 record CUSTOMER type Entity{@table{name = "CUSTOMER"}}
     NAME string
     COUNTRY string{@id};
     STATE string?;
     CUSTID string;
 end

Get a record

 function getCust{id String in} returns (Customer)
     ds SQLDataSource?{@resource {}};
     aCust Customer;
     get aCust from ds using(id);
     return (aCust);
 end

Add a record

 function addCust{customer Customer in}
     ds SQLDataSource?{@resource {}};
     add customer to ds;
 end

Loop through a SQL result set

 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.setNext())
        get myCust from rs;
        Syslib.writeStdOut (Customer name: " + myCust.name);
     end
 
 end


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.

Back to the top