取得 NoSQL 處理
瞭解如何使用 Oracle NoSQL Database 驅動程式存取表格。建立 NoSQL 處理開始開發您的應用程式。使用 NoSQLHandle 來存取表格並執行所有作業。
若要建立以 NoSQLHandle 表示的連線,請使用 NoSQLHandleFactory.createNoSQLHandle
方法和 NoSQLHandleConfig
類別取得控制碼。NoSQLHandleConfig
類別可讓應用程式指定處理組態。如需詳細資訊,請參閱 Java API Reference Guide 。
/* Configure a handle for the desired Region and AuthorizationProvider.
* By default this SignatureProvider constructor reads authorization
* information from ~/.oci/config and uses the default user profile and
* private key for request signing. Additional SignatureProvider
* constructors are available if a config file is not available or
* desirable.
*/
AuthorizationProvider ap = new SignatureProvider();
/* Use the us-ashburn-1 region */
NoSQLHandleConfig config = new NoSQLHandleConfig(Region.US_ASHBURN_1, ap);
config.setAuthorizationProvider(ap);
/* Sets a default compartment for all requests from this handle. This
* may be overridden in individual requests or by using a
* compartment-name prefixed table name.
*/
config.setDefaultCompartment("mycompartment");
// Open the handle
NoSQLHandle handle = NoSQLHandleFactory.createNoSQLHandle(config);
// Use the handle to execute operations
控點具有與其關聯的記憶體和網路資源。當應用程式使用控點完成時,請使用 NoSQLHandle.close
方法釋出資源。
為了將網路活動和資源配置降到最低,並避免重複建立和關閉控點。例如,在每個作業周圍建立和關閉控點會導致應用程式效能不佳。控點允許並行作業,因此單一控點足以存取多重執行緒應用程式中的表格。建立多個控點會產生額外的資源經常費用,而不會提供任何效能優點。
建立控點的方式是先建立 borneo.NoSQLHandleConfig
執行處理來設定通訊端點、授權資訊以及控制代碼組態的預設值。borneo.NoSQLHandleConfig
代表服務的連線。建立之後,必須使用 borneo.NoSQLHandle.close()
方法來關閉,才能清除資源。處理作業具有執行緒安全特性,需要加以共用。
from borneo import NoSQLHandle, NoSQLHandleConfig, Regions
from borneo.iam import SignatureProvider
# create AuthorizationProvider
provider = SignatureProvider()
# create handle config using the correct desired region
# as endpoint, add a default compartment.
config = NoSQLHandleConfig(Regions.US_ASHBURN_1).
set_authorization_provider(provider).
set_default_compartment('mycompartment')
# create the handle
handle = NoSQLHandle(config)
附註:
若要減少建立控點的資源使用量和負荷,最好避免建立及關閉borneo.NoSQLHandle
執行處理。
go
應用程式的第一個步驟是建立用來傳送要求至服務的 nosqldb.Client
控點。用戶端控點的實例可以安全地由多個常式並行使用,並預定在多重常式應用程式中共用。使用您的證明資料和其他認證資訊來設定控制碼。provider, err := iam.NewSignatureProviderFromFile(cfgfile, profile, passphrase, compartment)
cfg := nosqldb.Config
{
Region: "us-phoenix-1", AuthorizationProvider: provider,
}
client, err := nosqldb.NewClient(cfg)
// use client for all NoSQL DB operations
NoSQLClient
類別代表服務的主要存取點。若要建立 NoSQLClient
的執行處理,您必須提供適當的組態資訊。此資訊由 Config
物件表示,可以提供給 NoSQLClient
類別的建構子。或者,您可以選擇將此資訊儲存在 JSON 組態檔和 NoSQLClient
的建構子中,並搭配該檔案的路徑 (絕對或相對於應用程式目前的目錄)。如需方法詳細資訊,請參閱 NoSQLClient 類別。
Config
物件建立 Cloud Service 的 NoSQLClient
執行處理。它也會新增預設區間,並覆寫組態物件中的預設逾時值。import { NoSQLClient, Region } from 'oracle-nosqldb';
let client = new NoSQLClient({
region: Region.US_ASHBURN_1,
timeout: 20000,
ddlTimeout: 40000,
compartment: 'mycompartment',
auth: {
iam: {
configFile: '~/myapp/.oci/config',
profileName: 'Jane'
}
}
});
第二個範例會將相同的組態儲存在 JSON 檔案 config.json
中,並用來建立 NoSQLClient
執行處理。
{
"region": "US_ASHBURN_1",
"timeout": 20000,
"ddlTimeout": 40000,
"compartment": "mycompartment",
"auth": {
"iam": {
"configFile": "~/myapp/.oci/config",
"profileName": "Jane"
}
}
}
import { NoSQLClient } from 'oracle-nosqldb';
let client = new NoSQLClient('config.json');
類別 NoSQLClient
代表服務的主要存取點。若要建立 NoSQLClient
的執行處理,您必須提供適當的組態資訊。此資訊由 NoSQLConfig
類別表示,執行處理可以提供給 NoSQLClient
的建構子。或者,您也可以選擇將組態資訊儲存在 JSON 組態檔中,然後使用 NoSQLClient
的建構子,將路徑 (絕對或相對於目前的目錄) 帶到該檔案。
NoSQLConfig
建立 Cloud Service 的 NoSQLClient
執行處理。它還會新增預設區間並覆寫 NoSQLConfig
中的某些預設逾時值。var client = new NoSQLClient(
new NoSQLConfig
{
Region = Region.US_ASHBURN_1,
Timeout = TimeSpan.FromSeconds(10),
TableDDLTimeout = TimeSpan.FromSeconds(20),
Compartment = "mycompartment",
AuthorizationProvider = new IAMAuthorizationProvider(
"~/myapp/.oci/config", "Jane")
});
第二個範例會將相同的組態儲存在 JSON 檔案 config.json
中,並用來建立 NoSQLClient
執行處理。
config.json
{
"Region": "us-ashburn-1",
"Timeout": 20000,
"TableDDLTimeout": 40000,
"compartment": "mycompartment",
"AuthorizationProvider":
{
"AuthorizationType": "IAM",
"ConfigFile": "~/myapp/.oci/config",
"ProfileName": "Jane"
}
}
var client = new NoSQLClient("config.json");
相關主題