Saltar para o conteúdo principal
Versão: v20 R4 BETA

Using the Global Stamp

Visão Geral

4D automatically manages an internal global modification stamp, useful to handle data change tracking implementations, for example to monitor activity, backup, run incremental synchronization, etc.

The global modification stamp is a number, always maintained by 4D, even in case of database restoration, import, etc. Note however that the stamp can be modified using the .setGlobalStamp() function.

Once the data change tracking is configured and enabled, the following actions are automatically executed by 4D at each record modification (add, modify, delete):

  1. The current global modification stamp value is saved in the special "GlobalStamp" attribute of the involved entity. In case of a deletion, a new entity is also added to the `DeletedRecords` table with information about the deleted entity and the current global modification stamp value is saved in the "__Stamp" attribute.

  2. The global modification stamp value is incremented.

This mechanism allows you to identify entities that have been modified, added, or deleted since a point in time, and to implement any appropriate action (see example).

info

Do not confuse the global modification stamp with the internal entity stamp, used for the optimistic locking feature.

Configurando rastreamento de alterações de dados

By default, the global modification stamp is not created (the .getGlobalStamp() function returns 0. To enable data change tracking, you need to add special fields and a table to your structure. You can use the contextual menu of the Structure Editor to create automatically all necessary elements.

Requisitos de estrutura

To enable data change tracking, the application structure must contain at least one table with a __GlobalStamp field.

In addition, to ensure proper operation of the feature, the following conditions are required:

  • The __GlobalStamp field must must be of type Integer 64 bits, with automatic index, Expose as REST resource, and Invisible properties selected.
  • Uma tabela __DeletedRecords deve ser adicionada, com os seguintes campos:
CampoTipoDescrição
__PrimaryKeyTextChave primária da entidade excluída
__StampInteger 64 bitsGlobal stamp just before the deletion
__TableNameTextNome da tabela de entidades excluída
__TableNumberLong IntegerNúmero da tabela da entidade excluída

You can only track changes for data in tables having the __GlobalStamp field.

nota

In the 4D language, the __GlobalStamp field value should be handled through a Real type variable.

Usando o Editor de estruturas

The 4D Structure Editor allows you to enable or disable data change tracking using a single menu item.

Para ativar o rastreamento de alterações de dados:

  1. Selecione a(s) tabela(s) para as quais você deseja habilitar o rastreamento de alterações nos dados.
  2. Right-click on a selected table and select Enable data change tracking in the contextual menu.
  3. É exibida uma caixa de diálogo de confirmação. Date and Time: Date and time of backup.

Em seguida, 4D faz as seguintes alterações:

  • Um campo pré-configurado __GlobalStamp é adicionado à(s) tabela(s).
  • If not already existing, a __DeletedRecords table is added to the structure.

Para desativar o rastreamento de alterações de dados:

  1. Selecione a(s) tabela(s) para as quais você deseja remover o rastreamento de alterações nos dados.
  2. Right-click on a selected table and select Disable data change tracking in the contextual menu.
  3. É exibida uma caixa de diálogo de confirmação. Date and Time: Date and time of backup.

Em seguida, 4D remove o campo __GlobalStamp da(s) tabela(s). Note that if you want to remove the __DeletedRecords table, you need to do it manually.

Exemplo


$tableName:="Employee" $oldStamp:=... //load the previous stamp value
//from which you want to compare the current stamp

If ($oldStamp # ds.getGlobalStamp()) //get all new or modified entities $modifiedEmps:=ds[$tableName].query("__GlobalStamp > :1"; $oldStamp) //get all deleted entities $deletedEmpsInfo:=ds.__DeletedRecords.query("__Stamp > :1 and __TableName = :2";\
$oldStamp; $tableName) End if