カスタム検索関数の呼び出し
以下の Java™ および C# の例では、日付値をカレンダー値に変換するカスタム検索関数を開始する方法を示します。
関数 DateConversionFunctionHandler は、SearchSQL オブジェクトの選択リストで指定されます。 SearchScope オブジェクトが作成され、その fetchRows メソッドが呼び出されます。検索によって行が返されるたびに、サーバーはカスタム検索関数を呼び出します。この関数は、変換された値を返します。それは、返された値は他のプロパティーとともに検索選択リストに表示されます。
Java の例
// Create a SearchSQL instance and build the SQL statement.
SearchSQL sqlObject = new SearchSQL();
// In the in the select list, specify the custom search function to evaluate the DateCreated property.
// Because "Month" is passed as a parameter to the function, the function will return the current month and year.
// For more information, see Implementing a Search Function Handler.
sqlObject.setSelectList("d.DocumentTitle, d.Id, SCF::DateConversionFunctionHandler(DateCreated, 'Month') as MonthYear");
sqlObject.setFromClauseInitialValue("Document", "d", false);
// Print the SQL statement to be invoked.
System.out.println("SQL: " + sqlObject.toString());
// SearchScope インスタンスを作成// (オブジェクト・ストア・オブジェクトが存在すると仮定)
SearchScope search = new SearchScope(os);
// To execute searches calling custom functions, the fetchRows method must be used.
RepositoryRowSet myRows = search.fetchRows(sqlObject, null, null, null);
// Iterate the collection of rows and print selected properties.
// The MonthYear property reflects the value returned by the DateConversionFunctionHandler function.
int rowCount = 0;
Iterator iter = myRows.iterator();
while (iter.hasNext())
{
RepositoryRow row = (RepositoryRow) iter.next();
String docTitle = row.getProperties().get("DocumentTitle").getStringValue();
Id docId = row.getProperties().get("Id").getIdValue();
String MonthYear = row.getProperties().get("MonthYear").getStringValue();
rowCount++;
System.out.print("row " + rowCount + ":");
System.out.print(" Id=" + docId.toString());
if (docTitle != null) System.out.print(" DocumentTitle=" + docTitle);
System.out.print(" Date last modified=" + MonthYear + "¥n");
}
C# の例
// Create a SearchSQL instance and build the SQL statement.
SearchSQL sqlObject = new SearchSQL();
// In the in the select list, specify the custom search function to evaluate the DateCreated property.
// Because "Month" is passed as a parameter to the function, the function will return the current month and year.
// For more information, see Implementing a Search Function Handler.
sqlObject.SetSelectList("d.DocumentTitle, d.Id, SCF::DateConversionFunctionHandler(DateCreated, 'Year') as MonthYear");
sqlObject.SetFromClauseInitialValue("Document", "d", false);
// Print the SQL statement to be invoked.
System.Console.WriteLine("SQL: " + sqlObject.ToString());
// SearchScope インスタンスを作成// (オブジェクト・ストア・オブジェクトが存在すると仮定)
SearchScope search = new SearchScope(os);
// To execute searches calling custom functions, the FetchRows method must be used.
IRepositoryRowSet myRows = search.FetchRows(sqlObject, null, null, null);
// Iterate the collection of rows and print selected properties.
// The MonthYear property reflects the value returned by the DateConversionFunctionHandler function.
int rowCount = 0;
foreach (IRepositoryRow row in myRows)
{
string docTitle = row.Properties.GetProperty("DocumentTitle").GetStringValue();
Id docId = row.Properties.GetProperty("Id").GetIdValue();
String MonthYear = row.Properties.GetProperty("MonthYear").GetStringValue();
rowCount++;
System.Console.Write("row " + rowCount + ":");
System.Console.Write(" Id=" + docId.ToString());
if (docTitle != null) System.Console.Write(" DocumentTitle=" + docTitle);
System.Console.Write(" Date last modified=" + MonthYear + "¥n");
}