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.
Difference between revisions of "EDT:Tutorial: RUI With DataBase Lesson 6 Code"
(New page: Access a database with EGL Rich UI > Resources = Finished code for SQLService.egl...) |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | [[EDT:Tutorial: Access a database with EGL Rich UI|Access a database with EGL Rich UI]] > [[EDT:Tutorial: | + | |
+ | [[EDT:Tutorial: Access a database with EGL Rich UI|Access a database with EGL Rich UI]] > [[EDT:Tutorial: RUI With Database Resources|Resources]] | ||
= Finished code for SQLService.egl after lesson 6 = | = Finished code for SQLService.egl after lesson 6 = | ||
− | The following code is the text of the | + | The following code is the text of the '''SQLService.egl''' file |
after Lesson 6. | after Lesson 6. | ||
<code> | <code> | ||
package services; | package services; | ||
+ | |||
import records.paymentRec; | import records.paymentRec; | ||
+ | |||
service SQLService | service SQLService | ||
+ | |||
ds SQLDataSource?{@Resource{bindingKey = "Derby"}}; | ds SQLDataSource?{@Resource{bindingKey = "Derby"}}; | ||
+ | |||
function addPayment(newPayment paymentRec in) | function addPayment(newPayment paymentRec in) | ||
− | + | logEntry ( "addPayment" ) ; | |
− | + | try | |
− | + | add newPayment to ds | |
− | + | with #sql{ | |
− | + | insert into PAYMENT | |
− | + | (CATEGORY, DESCRIPTION, AMOUNT, FIXED_PAYMENT, DUE_DATE, | |
− | + | PAYEE_NAME, PAYEE_ADDRESS1, PAYEE_ADDRESS2) | |
− | + | values | |
+ | (?, ?, ?, ?, ?, ?, ?, ?) | ||
+ | }; | ||
+ | onException(ex sqlException) | ||
+ | logException(ex); | ||
+ | end | ||
end | end | ||
Line 121: | Line 131: | ||
''' Related tasks '''<br /> | ''' Related tasks '''<br /> | ||
− | [[EDT:Tutorial: | + | [[EDT:Tutorial: RUI With DataBase Lesson 6|Lesson 6: Add code for the service functions]] |
[[Category:EDT]] | [[Category:EDT]] |
Latest revision as of 10:11, 1 December 2011
Access a database with EGL Rich UI > Resources
Finished code for SQLService.egl after lesson 6
The following code is the text of the SQLService.egl file
after Lesson 6.
package services; import records.paymentRec; service SQLService ds SQLDataSource?{@Resource{bindingKey = "Derby"}}; function addPayment(newPayment paymentRec in) logEntry ( "addPayment" ) ; try add newPayment to ds with #sql{ insert into PAYMENT (CATEGORY, DESCRIPTION, AMOUNT, FIXED_PAYMENT, DUE_DATE, PAYEE_NAME, PAYEE_ADDRESS1, PAYEE_ADDRESS2) values (?, ?, ?, ?, ?, ?, ?, ?) }; onException(ex sqlException) logException(ex); end end function getAllPayments() returns(paymentRec[]) payments paymentRec[]; logEntry("getAllPayments"); try get payments from ds; onException(ex sqlException) logException(ex); end return(payments); end function editPayment(chgPayment paymentRec in) logEntry("editPayment"); try replace chgPayment to ds; onException(ex SQLException) logException(ex); end end function deletePayment(delPayment paymentRec in) logEntry("deletePayment"); try delete delPayment from ds; onException(ex SQLException) if(ex.SQLState != "02000") // sql state is five digits logException sqlException; end end end function createDefaultTable() returns(paymentRec[]) payments paymentRec[]; logEntry("createDefaultTable"); try try execute from ds with #sql{ delete from PAYMENT }; onException(ex SQLException) if(ex.SQLState != "02000") // sqlState is five digits throw ex; end end ispDate date = dateTimeLib.dateFromGregorian(20140405); addPayment(new paymentRec{category = 1, description = "Apartment" , amount = 880, fixedPayment = yes, dueDate = new date , payeeName = "A Jones", payeeAddress1 = "100 Jones Dr" , payeeAddress2 = "Jonesboro, NC" }); addPayment(new paymentRec{category = 2, description = "Groceries" , amount = 450, fixedPayment = no, dueDate = new date , payeeName = "B Jones", payeeAddress1 = "200 Jones Dr" , payeeAddress2 = "Jonesboro, NC" }); addPayment(new paymentRec{category = 5, description = "ISP" , amount = 19.99, fixedPayment = no, dueDate = ispDate , payeeName = "C Jones", payeeAddress1 = "300 Jones Dr" , payeeAddress2 = "Jonesboro, NC" }); payments = getAllPayments(); onException(ex anyException) logException(ex); end return(payments); end logActive boolean = true; activeService string; private function logEntry(serviceFunction string in) activeService = serviceFunction; log("Entry: SQLService, " + serviceFunction); end private function logException(ex sqlException?) accumulatedMessage string = "Exception: SQLService, " + activeService; while(ex != null) accumulatedMessage = accumulatedMessage + ", SQLSTATE = " + ex.SQLState + ", message = " + ex.message; ex = ex.nextException; end log(accumulatedMessage); throw new anyException{message = accumulatedMessage}; end private function log(text string in) if(logActive) sysLib.writeStdOut(text); end end end
Related tasks