Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Scout/Concepts/Sql Service"
m (Category changed) |
(→Minimal configuration) |
||
Line 17: | Line 17: | ||
* {{ScoutProp|SqlStyle}} provides the class of the {{ScoutLink|Concepts|SqlStyle|Sql Style}} that should be used. | * {{ScoutProp|SqlStyle}} provides the class of the {{ScoutLink|Concepts|SqlStyle|Sql Style}} that should be used. | ||
+ | |||
+ | |||
+ | ===Delegation of the configuration to config.ini=== | ||
+ | If the Property {{ScoutProp|JdbcMappingName}} is set (using the {{ScoutLink|SDK|Object Properties View}}), the Java code looks like this: | ||
+ | |||
+ | <source lang="java"> | ||
+ | package myapp.server.services.common.sql; | ||
+ | |||
+ | import org.eclipse.scout.rt.services.common.jdbc.AbstractSqlService; | ||
+ | import org.eclipse.scout.service.IService; | ||
+ | |||
+ | public class MySqlService extends AbstractSqlService implements IService { | ||
+ | @Override | ||
+ | protected String getConfiguredJdbcMappingName() { | ||
+ | return "jdbc:derby:C:/MyDB"; | ||
+ | } | ||
+ | // + other configurations... | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | The path to the database is hard coded in the code. You might want to delegate this configuration to the <code>config.ini</code> to have more flexibility (e.g one path for development and one path for production). Because the {{ScoutJavadoc|AbstractSqlService|C}} also provides a setter for this property <code>setJdbcMappingName(String)</code>, it is possible to set the property with the <code>config.ini</code> file: | ||
+ | |||
+ | <qualified name of the class>#<setter name without set prefix>=<value> | ||
+ | |||
+ | This pattern works in Eclipse Scout for all classes extending the {{ScoutJavadoc|AbstractService|C}} | ||
+ | |||
+ | For this example: | ||
+ | |||
+ | myapp.server.services.common.sql.MySqlService#JdbcMappingName=jdbc:derby:C:/MyDB | ||
==SQL convenience class== | ==SQL convenience class== |
Revision as of 04:26, 12 November 2011
The Scout documentation has been moved to https://eclipsescout.github.io/.
The SqlService provides access to a database.
- implements The Scout documentation has been moved to https://eclipsescout.github.io/.
- extends The Scout documentation has been moved to https://eclipsescout.github.io/.
Contents
Description
Minimal configuration
To be able to connect to a database, these properties needs to be configured:
- The Scout documentation has been moved to https://eclipsescout.github.io/. the qualified name of the JDBC driver.
- The Scout documentation has been moved to https://eclipsescout.github.io/. the JDBC path
"jdbc:..."
. - The Scout documentation has been moved to https://eclipsescout.github.io/. the user name to connect to the database.
- The Scout documentation has been moved to https://eclipsescout.github.io/. the password to connect to the database.
- The Scout documentation has been moved to https://eclipsescout.github.io/. provides the class of the The Scout documentation has been moved to https://eclipsescout.github.io/. that should be used.
Delegation of the configuration to config.ini
If the Property The Scout documentation has been moved to https://eclipsescout.github.io/. is set (using the The Scout documentation has been moved to https://eclipsescout.github.io/.), the Java code looks like this:
package myapp.server.services.common.sql; import org.eclipse.scout.rt.services.common.jdbc.AbstractSqlService; import org.eclipse.scout.service.IService; public class MySqlService extends AbstractSqlService implements IService { @Override protected String getConfiguredJdbcMappingName() { return "jdbc:derby:C:/MyDB"; } // + other configurations... }
The path to the database is hard coded in the code. You might want to delegate this configuration to the config.ini
to have more flexibility (e.g one path for development and one path for production). Because the The Scout documentation has been moved to https://eclipsescout.github.io/. also provides a setter for this property setJdbcMappingName(String)
, it is possible to set the property with the config.ini
file:
<qualified name of the class>#<setter name without set prefix>=<value>
This pattern works in Eclipse Scout for all classes extending the The Scout documentation has been moved to https://eclipsescout.github.io/.
For this example:
myapp.server.services.common.sql.MySqlService#JdbcMappingName=jdbc:derby:C:/MyDB
SQL convenience class
Scout proposes a convenience singleton class to access the default SqlService: The Scout documentation has been moved to https://eclipsescout.github.io/.
Here a simple example:
SQL.update( " update actor " + " set first_name = :firstName," + " last_name = :lastName " + " where actor_id = :id ", formData );
See also
- The Scout documentation has been moved to https://eclipsescout.github.io/.
- The Scout documentation has been moved to https://eclipsescout.github.io/.
- The Scout documentation has been moved to https://eclipsescout.github.io/.