public DataTable generateDataTable(Query query, HttpServletRequest request){
Object myObject = request.getAttribute("my_object_name");
// Add your code to manipulate myObject here
}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-07-10 (世界標準時間)。"],[[["\u003cp\u003eDevelop intricate data source implementations by inheriting from \u003ccode\u003eDataSourceServlet\u003c/code\u003e or creating a custom servlet using \u003ccode\u003eDataTableGenerator\u003c/code\u003e and \u003ccode\u003eDataSourceHelper\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEnhance efficiency by defining capabilities like \u003ccode\u003eSQL\u003c/code\u003e, \u003ccode\u003eSORT_AND_PAGINATION\u003c/code\u003e, and \u003ccode\u003eSELECT\u003c/code\u003e using the \u003ccode\u003eCapabilities\u003c/code\u003e enum to leverage your data store's querying features.\u003c/p\u003e\n"],["\u003cp\u003eCustomize the data source flow by utilizing helper functions within \u003ccode\u003eDataSourceHelper\u003c/code\u003e to tailor the sequence of events beyond the default flow.\u003c/p\u003e\n"],["\u003cp\u003ePass additional parameters to your \u003ccode\u003eDataTableGenerator\u003c/code\u003e using \u003ccode\u003eHttpServletRequest.setAttribute\u003c/code\u003e and retrieve them within the \u003ccode\u003egenerateDataTable\u003c/code\u003e method using \u003ccode\u003eHttpServletRequest.getAttribute\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eImplement the library without servlets by using classes like \u003ccode\u003eQuery\u003c/code\u003e, \u003ccode\u003eDataTable\u003c/code\u003e, and specific \u003ccode\u003eDataSourceHelper\u003c/code\u003e functions to parse, split, and apply queries to generate data tables in desired formats.\u003c/p\u003e\n"]]],[],null,["# Implementation Tips\n\nThis section covers some tips that\nwill help you write more complex implementations of the library:\n\n- [Using Your Own Servlet](#servlet)\n- [Defining Capabilities](#capabilities)\n- [Customizing the Flow of Events](#events)\n- [Passing Parameters to `DataTableGenerator.generateDataTable`](#params)\n- [Implementing a Non-servlet Data Source](#nonservlet)\n\nUsing Your Own Servlet\n----------------------\n\nThe simplest data source implementations inherit from the library's `DataSourceServlet` class.\nTo inherit from a class other than `DataSourceServlet`, implement\na data source as follows:\n\n1. Implement the `DataTableGenerator` interface and override `getCapabilities()` and `generateDataTable()`.\n2. Call `DataSourceHelper.executeDataSourceServletFlow()` from within your servlet's code to run the data source flow. This method takes the following parameters :\n - An `HttpServletRequest` object.\n - An `HttpServletResponse` object.\n - Your implementation of the `DataTableGenerator` interface from step 1 above.\n - A boolean to specify restricted or unrestricted access mode.\n\nFor example, if you want to inherit your servlet from another servlet\nclass, called `AuthServlet` that provides built-in authentication,\nyou can rewrite the `SimpleServletExample` to inherit `AuthServlet` rather\nthan `DataSourceServlet` as follows:\n\n1. Implement the `DataTableGenerator` interface.\n2. Move `generateDataTable()` from your `DataSourceServlet` implementation to your `DataTableGenerator` implementation.\n3. Override `getCapabilities()` in your `DataTableGenerator` implementation to return `Capabilities.None`.\n4. Call `DataSourceHelper.executeDataSourceServletFlow()` from within your servlet code (`doGet()` or `doPost()`), and pass your `DataTableGenerator` implementation. This method runs the entire flow of the datasource, including rendering the data source results into the servlet response.\n\nYou can use the same technique if you are using a servlet framework\nin which you normally inherit an abstract class provided by the framework.\nFor example, if you are using WebWork you might want to inherit the `ActionSupport` class.\n\nDefining Capabilities\n---------------------\n\nIf your data store contains a large amount of data, and you want\nto increase the efficiency of your data source, you can use the querying\ncapabilities of your data store. For example, suppose that your data store\nis a database, and the database has a large number of columns. If a visualization\nrequests only a few of those columns, then running a `SELECT` operation\nwithin the database is more efficient than retrieving all the columns and\nusing the library's querying capabilities to perform the `SELECT`.\nTo implement `SELECT` capabilities, you write code\nto run a `SELECT` operation within the database and to return\na data table.\n\nUse the `Capabilities` enum\nto define the querying capabilities that your code\nprovides. Available options are:\n\n- `NONE`: the default, your code provides no query operations.\n- `SQL`: your code provides SQL query operations.\n- `SORT_AND_PAGINATION`: your code provides both sort and pagination query operations.\n- `SELECT`: your code provides a select operation.\n- `ALL`: your code provides `SQL`, `SORT_AND_PAGINATION`, and `SELECT` operations.\n\n**Note**: In all cases the library handles\nany query operations that are not provided by your code.\n\nTo implement a capability other than `NONE`, override `Capabilities.getCapabilities()`and\nimplement `DataTable.generateDataTable()` to query the data\nstore and return a data table.\n\nThree of the examples illustrate how to implement capabilities: `AdvancedExampleServlet`,\n`AdvancedExampleServlet2`, and `SqlDataSourceServlet`.\nAll are in the `example` package. `AdvancedExampleServlet2` is\ndiscussed in [Defining Capabilities and the Flow of Events](/chart/interactive/docs/dev/dsl_httpservlet).\n\nCustomizing the Flow of Events\n------------------------------\n\nThe default flow of events is defined in `DataSourceHelper.executeDataSourceServletFlow`.\nThe default flow is as follows:\n\n1. Extract and parse query parameters.\n2. For restricted access mode only, verify that the request originates from the same domain as the servlet.\n3. Parse the request to create two query objects: the data source query and the completion query. Pass the data source query to your implementation of `generateDataTable()`.\n4. Your implementation of `generateDataTable()` generates a data table.\n5. Run the completion query on the data table generated in step 5.\n6. Render the data table into the format specified by the visualization and set the servlet response.\n\nTo specify your own flow of events, call the\nhelper functions in `datasource.DataSourceHelper`. See\n[Defining Capabilities and the Flow of Events](/chart/interactive/docs/dev/dsl_httpservlet) for an example\nimplementation.\n\nPassing Parameters to `DataTableGenerator.generateDataTable`\n------------------------------------------------------------\n\nYou can use the `HttpServletRequest.setAttribute` to pass\ndata that is not part of a query or `HttpServletRequest` object\nto `DataTableGenerator.generateDataTable`. Example code is provided\nbelow.\n\nIn your servlet's code, put the object you want to pass into the `HttpServletRequest` as\nfollows: \n\n```scdoc\nrequest.setAttribute(\"my_object_name\", myObject);\nDataSourceHelper.executeDataSourceServletFlow(request, response, dataTableGenerator);\n```\n\nIn your `dataTableGenerator` interface implementation, get the object from the `HttpServletRequest` as follows: \n\n```scdoc\npublic DataTable generateDataTable(Query query, HttpServletRequest request){\n Object myObject = request.getAttribute(\"my_object_name\"); \n // Add your code to manipulate myObject here \n} \n```\n\nImplementing a Non-servlet\nData Source\n--------------------------------------\n\nIf you implement the library without using a servlet, you can\nuse only those classes and helper functions that do not require\na servlet environment. These include the `Query` and `DataTable`\nclasses and some of the `DataSourceHelper` functions\nsuch as `parseQuery`, `applyQuery`, `validateQuery` and `splitQuery`.\nYou can use these classes and functions to do the following:\n\n- Parse a visualization query.\n- Split the query into a data source query and a completion query.\n- Run the completion query to generate a data table.\n- Return the data table to the visualization in `HTML`, `CSV`, or `JSON` format."]]