If there is a bind variable, it is specified as the parameter to the Execute(object[]). Since there isn't any bind variable in this example, parameter is set to null.
S2Container will construct the components so it is only necessary to invoke the Execute() method.
If there is an underscore (_) included in the column name, it is mapped to a property whose name is the column name without the underscore character.
To just query 1 object, BasicSelectHandler is used in a similar manner as in the Query(BeanList) except BeanDataReaderHandler is used and an object is returned instead of a list.
Seasar.Examples.Reference.ADO.SelectBean.dicon
<components><includepath="Seasar.Examples/Ado.dicon"/><componentname="SelectBeanClient"class="Seasar.Examples.Reference.ADO.SelectBeanClient"/><componentname="SelectBeanHandler"class="Seasar.Extension.ADO.Impl.BasicSelectHandler"><propertyname="Sql"> "SELECT empno, ename, job, mgr, hiredate, sal, comm, deptno FROM emp WHERE empno = @empno"</property><propertyname="DataReaderHandler"><componentclass="Seasar.Extension.ADO.Impl.BeanDataReaderHandler"><arg>Seasar.Examples.Reference.ADO.Employee</arg></component></property></component></components>
Seasar.Examples.Reference.ADO.SelectBeanClient
C#
using System;
using Seasar.Extension.ADO;
using Seasar.Framework.Container;
using Seasar.Framework.Container.Factory;
namespace Seasar.Examples.Reference.ADO
{
publicclass SelectBeanClient
{
privateconststring PATH = "Seasar.Examples/Reference/ADO/SelectBean.dicon";
publicvoid Main()
{
IS2Container container = S2ContainerFactory.Create(PATH);
container.Init();
try
{
ISelectHandler handler = (ISelectHandler) container.GetComponent("SelectBeanHandler");
Employee result = (Employee) handler.Execute(newobject[] { 7788 });
Console.Out.WriteLine(result);
}
finally
{
container.Destroy();
}
}
}
}
BasicUpdateHandler is used in an update. It has the following properties:
Seasar.Extension.ADO.Impl.BasicUpdateHandler
Property
Description
S2Container Example
DataSource
DataSource
Set normally by default
Sq‚Œ
SQL command to execute
"UPDATE emp SET ename = @ename WHERE empno = @empno "
Seasar.Examples.Reference.ADO.Update.dicon
<components><includepath="Seasar.Examples/Ado.dicon"/><componentname="UpdateClient"class="Seasar.Examples.Reference.ADO.UpdateClient"/><componentname="UpdateHandler"class="Seasar.Extension.ADO.Impl.BasicUpdateHandler"><propertyname="Sql">"UPDATE emp SET ename = @ename WHERE empno = @empno"</property></component></components>
Seasar.Examples.Reference.ADO.UpdateClient
C#
using System;
using Seasar.Extension.ADO;
using Seasar.Framework.Container;
using Seasar.Framework.Container.Factory;
namespace Seasar.Examples.Reference.ADO
{
publicclass UpdateClient
{
privateconststring PATH = "Seasar.Examples/Reference/ADO/Update.dicon";
publicvoid Main()
{
IS2Container container = S2ContainerFactory.Create(PATH);
container.Init();
try
{
IUpdateHandler handler = (IUpdateHandler) container.GetComponent("UpdateHandler");
int result = (int) handler.Execute(newobject[] { "SCOTT", 7788 });
Console.Out.WriteLine(result);
}
finally
{
container.Destroy();
}
}
}
}
When mapping NET Framework type to a database column, if there is a column with a value NULL, exception will be thrown because when .NET Framework type is of a System.Int32 construct, NULL is not possible.
To use NULL in a column, refer to the following sections:
Parameter markers that may be used in a SQL command depends on the ADO.NET data provider. As an example, SqlClient uses "@parmname", OracleClient uses ":parmname", OleDb uses "?", and Odbc uses "?".
S2ADO allows SQL commands to be independent of data provider by changing parameter markers depending on a data provider used.
Following is an example:
Data Provider
SQL command
(User's SQL command)
SELECT * FROM emp WHERE empno = @empno OR empno = :empno OR empno = ?
SqlClient
SELECT * FROM emp WHERE empno = @0 OR empno = @1 OR empno = @2
OracleClient
SELECT * FROM emp WHERE empno = :0 OR empno = :1 OR empno = :2
OleDb
SELECT * FROM emp WHERE empno = ? OR empno = ? OR empno = ?
Odbc
SELECT * FROM emp WHERE empno = ? OR empno = ? OR empno = ?
Note: Several types of parameter markers may be used in a SQL command but for readability, it is recommended to use one type.