TubEntity

TubEntity

In-memory representation of Entity metadata definition (meta file). Meta file must be created in accordance with the entity definition JSON scheme This server-side class contain more properties when client-side UBEntity class or TubApp#getDomainInfo method result, since server pass to client only part of Entity definition information.

The most useful method is addMethod witch allow to add public (accessible from client) JavaScript methods to entity.

Constructor

new TubEntity()

Members

name: String

The name of the entity

modelName: String

Model entity assigned to. To get model configuration use following code:

 var modelConfig = App.domain.config.models.byName('UBA'); // UBA is a modelName
 var publicPath = modelConfig.publicPath;

caption: String

Caption

description: String

Description

connectionName: String

Name of the database connection entity assotiated wiith. Connections defined in application config.

connectionConfig: TubConnectionConfig

Database connection configuration

connection

Database connection
Deprecated:
  • `undefined` since 1.11. Use a connectionConfig

cacheType: TubCacheType

Caching type

dsType: TubEntityDataSourceType

type of data entity mapped to

sqlAlias: String

Short string using as SQL alias while building SQL query and DDL statements If empty - entity name used

descriptionAttribute: String

Name of attribute what describe element This attribute is used for example in comboBox as display field

documentation

entity documentation

idGenerator: String

Name of idGenerator used for generating ID's for this entity. Default generator ('main') is created automatically.

attributes: TubEntityAttributeList

Entity attributes

existSequence: Boolean

refSequenceName: String

allowGenSequence: Boolean

allowUseSequence: Boolean

Methods

addMethod(methodName)

Add entity level method.

Method itself must be a function type property of entity with single parameter of type {ubMethodParams} Client able to call such methods remotely. Also such methods is a subject of ELS security.

You do not need to add methods what do not called from client using {TubEntity#addMethod}

Warning: do not call entity.addMethod from inside function or conditions. This code evaluated during thread initialization and each thread must add method in the same manner.

Arguments:
  1. methodName (String)
Example
//consider we have entity my_entity. Code below is inside my_entity.js file):
       "use strict";
        var me = my_entity;
        me.entity.addMethod('externalMethod');
        // @param {ubMethodParams} ctx <- here must be JSDoc comment format
        me.externalMethod = function(ctx){
            var
                params = ctx.mParams, a = params.a || 1, b = params.b || 1;
            params.multiplyResult = a*b;
        }

        // now from client side you can call
        $App.connection.run({entity: 'my_entity', method: 'externalMethod', a: 10, b:20}).done(function(result){
            console.log(' 10 * 20 = ', result.multiplyResult); // will put to log "10 * 20 = 200"
        });