TableUtils - Global
A API TableUtils é uma classe de atalhos para acessar informações relacionadas à tabela.
Esta classe está disponível para scripts do lado do servidor.
TableUtils – tableExists()
Verifica se existe uma tabela.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Booliano | Verdadeiro se a tabela existir. |
var table = new TableUtils("my_table");
gs.print("Does 'my_table' exist? " + table.tableExists());
Saída: "my_table" existe? falso
TableUtils - drop(cadeia de caracteres "tableName")
Descarta uma tabela de banco de dados.
| Nome | Tipo | Descrição |
|---|---|---|
| tableName | Cadeia de caracteres | Nome da tabela a ser descartada |
| Tipo | Descrição |
|---|---|
| vazio |
var tu = new TableUtils();
tu.drop("table_that_will_be_lost_forever");
dropping table table_that_will_be_lost_forever
Starting cache flush
Cache flush complete
TABLE DROP: admin dropped table table_that_will_be_lost_foreverTableUtils - dropAndClean(cadeia de caracteres "tableName")
Descarta uma tabela de banco de dados e limpa as referências à tabela.
| Nome | Tipo | Descrição |
|---|---|---|
| tableName | Cadeia de caracteres | Nome da tabela a ser descartada |
| Tipo | Descrição |
|---|---|
| vazio |
var tu = new TableUtils();
tu.dropAndClean("table_that_will_be_lost_forever");
dropping table table_that_will_be_lost_forever
Starting cache flush
Cache flush complete
TABLE DROP: admin dropped table table_that_will_be_lost_forever
*** Script: removing gauges for table_that_will_be_lost_forever
*** Script: removing forms for table_that_will_be_lost_forever
*** Script: removing styles for table_that_will_be_lost_forever
*** Script: removing forms sections for table_that_will_be_lost_forever
*** Script: removing lists for table_that_will_be_lost_forever
*** Script: removing related lists for table_that_will_be_lost_forever
*** Script: removing references to table_that_will_be_lost_forever
*** Script: removing dictionary entries for table_that_will_be_lost_forever
Background message, type:info, message: Table deletedTableUtils - dropTableAndExtensions(cadeia de caracteres "tableName")
Descarta uma tabela de banco de dados, todas as suas tabelas estendidas e limpa as referências às tabelas.
| Nome | Tipo | Descrição |
|---|---|---|
| tableName | Cadeia de caracteres | A tabela a ser descartada |
| Tipo | Descrição |
|---|---|
| vazio |
var tu = new TableUtils();
tu.dropTableAndExtensions("table_that_will_be_lost_forever");
dropping table parent_table_that_will_be_lost_forever
Starting cache flush
Cache flush complete
TABLE DROP: admin dropped table ext_table_that_will_be_lost_forever
removing gauges for ext_table_that_will_be_lost_forever
removing forms for ext_table_that_will_be_lost_forever
removing styles for ext_table_that_will_be_lost_forever
removing forms sections for ext_table_that_will_be_lost_forever
removing lists for ext_table_that_will_be_lost_forever
removing related lists for ext_table_that_will_be_lost_forever
removing references to ext_table_that_will_be_lost_forever
removing dictionary entries for ext_table_that_will_be_lost_forever
Background message, type:info, message: Table deleted
dropping table parent_table_that_will_be_lost_forever
Starting cache flush
Cache flush complete
TABLE DROP: admin dropped table parent_table_that_will_be_lost_forever
removing gauges for parent_table_that_will_be_lost_forever
removing forms for parent_table_that_will_be_lost_forever
removing styles for parent_table_that_will_be_lost_forever
removing forms sections for parent_table_that_will_be_lost_forever
removing lists for parent_table_that_will_be_lost_forever
removing related lists for parent_table_that_will_be_lost_forever
removing references to parent_table_that_will_be_lost_forever
removing dictionary entries for parent_table_that_will_be_lost_forever
Background message, type:info, message: Table deletedTableUtils – getAbsoluteBase()
Retorna o nome da tabela base da qual a tabela foi estendida.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Cadeia de caracteres | Nome da tabela base |
var table = new TableUtils("cmdb_ci_server");
gs.print(table.getAbsoluteBase());
Saída: cmdb_ci
TableUtils – getAllExtensions()
Retorna a lista de tabelas que estendem uma tabela, incluindo a tabela base.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Lista de matrizes | Uma lista de tabelas que estende a tabela inclui a tabela base. |
var table = new TableUtils("task");
gs.print(table.getAllExtensions());
[task, incident, issue, kb_submission, sysapproval_group, change_request, change_request_imac, sc_task,
problem, sc_req_item, ticket, ast_transfer_order, planned_task, change_task, change_phase, sc_request]TableUtils – getHierarchy()
Retorna uma lista de todas as classes que participam da hierarquia da tabela especificada.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Lista de matrizes | Uma lista de todas as classes na hierarquia da tabela especificada. |
var table = new TableUtils("cmdb_ci_server");
gs.print(table.getHierarchy());
Output: [cmdb_ci_server, cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci, cmdb_ci_mainframe, cmdb_ci_linux_server, cmdb_ci_mainframe_lpar, cmdb_ci_esx_server, cmdb_ci_unix_server, cmdb_ci_solaris_server, cmdb_ci_hpux_server, cmdb_ci_aix_server, cmdb_ci_osx_server, cmdb_ci_netware_server, cmdb_ci_win_server]
TableUtils – getTables()
Retorna a hierarquia da tabela.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Lista de matrizes | Uma lista de nomes de tabela na hierarquia primária. |
// Get the hierarchy of tables
var table = new TableUtils("cmdb_ci_computer");
var tableArrayList = table.getTables();
// Use the j2js method to convert the Java ArrayList to JavaScript
gs.include("j2js");
var tableArray = j2js(tableArrayList);
// Write the value of each element in the JavaScript array
var i = 0;
while ( i < tableArray.length ) {
gs.print("Table with index " + i + ": " + tableArray[i]);
i++;
}
Table with index 0: cmdb_ci_computer
Table with index 1: cmdb_ci_hardware
Table with index 2: cmdb_ci
Table with index 3: cmdbTableUtils – getTableExtensions()
Retorna uma lista de tabelas que estendem uma tabela.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Lista de matrizes | Uma lista de nomes de tabela que estendem a tabela. |
Este exemplo mostra que 58 tabelas nesta instância estendem a tabela Computador [cmdb_ci_computer]. (Saída resumida abaixo.)
// Get the tables that extend the table
var table = new TableUtils("cmdb_ci_computer");
var tableArrayList = table.getTableExtensions();
// Use the j2js method to convert the Java ArrayList to JavaScript
gs.include("j2js");
var tableArray = j2js(tableArrayList);
// Write the value of each element in the JavaScript array
var i = 0;
while ( i < tableArray.length ) {
gs.print("Table with index " + i + ": " + tableArray[i]);
i++;
}
Table with index 0: cmdb_ci_mainframe_hardware
Table with index 1: cmdb_ci_handheld_computing
Table with index 2: cmdb_ci_ucs_blade
Table with index 3: cmdb_ci_storage_switch
Table with index 4: cmdb_ci_server
Table with index 5: cmdb_ci_hmc_server
…
Table with index 56: cmdb_ci_pc_hardware
Table with index 57: cmdb_ci_ucs_rack_unitTableUtils – hasExtensions()
Determina se uma tabela foi estendida.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Booliano | Verdadeiro se a tabela tiver extensões. |
var table = new TableUtils("cmdb_ci_server");
gs.print(table.hasExtensions());
trueTableUtils – isBaseClass()
Determina se uma tabela é uma classe base, o que significa que ela não tem primárias e tem extensões.
Por exemplo, Task é uma classe base, pois não é estendida de outra tabela e tem tabelas estendidas dela. Sys_user não é uma classe base porque não tem primários, mas não tem extensões.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Booliano | Sinalizador que indica se uma tabela é uma tabela de classe base, o que significa que ela não tem primárias, mas tem extensões. Valores válidos:
|
Exemplo
var table = new TableUtils("task");
gs.print("Task is base class: " + table.isBaseClass());
var table = new TableUtils("sys_user");
gs.print("User is base class: " + table.isBaseClass());
Task is base class: true
User is base class: falseTableUtils – isSoloClass()
Determina se a tabela não tem primários nem extensões.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Booliano | Verdadeiro se a tabela não tiver primário e nenhuma tabela for estendida a partir dele. |
var table = new TableUtils("task");
gs.print("task is solo class: " + table.isSoloClass());
var table = new TableUtils("cmdb_ci_win_server");
gs.print("cmdb_ci_win_server is solo class: " + table.isSoloClass());
var table = new TableUtils("sys_user");
gs.print("sys_user is solo class: " + table.isSoloClass());
task is solo class: false
cmdb_ci_win_server is solo class: false
sys_user is solo class: trueTableUtils - TableUtils(cadeia de caracteres "tableName")
Cria uma instância de uma classe TableUtils.
| Nome | Tipo | Descrição |
|---|---|---|
| tableName | Cadeia de caracteres | O nome da tabela |
var tu = new TableUtils("incident");