JavaScript Application Development API for Oracle Visual Builder Cloud Service - Classic Applications

Source: entity.dt/js/DataModelTransactions.js

define([
    'core.dt/js/spi/TransactionSupport'
], function (TransactionSupport) {

    'use strict';

    /**
     * TBD consider keeping the transactions logic within the implementations themselves.
     */
    var DataModelTransactions = function () {
        AbcsLib.throwStaticClassError();
    };

    /**
     * Creates a constructor which produces transactionalized DataModel implementation from the given DataModel implementation constructor
     *
     * @param {type} implementationConstructor
     * @returns {function}
     */
    DataModelTransactions.wrapDataModel = function (implementationConstructor) {
        return TransactionSupport.transactionalize(implementationConstructor, [
            {
                create: 'createEntity',
                remove: {
                    name: 'removeEntity',
                    createArgs: function (entity) {
                        return [entity.getName()];
                    }
                },
                pattern: TransactionSupport.PATTERN_CREATE_REMOVE
            }
        ]);
    };

    /**
     * Creates a constructor which produces transactionalized Entity implementation from the given Entity implementation constructor
     *
     * @param {type} implementationConstructor
     * @returns {function}
     */
    DataModelTransactions.wrapEntity = function (implementationConstructor) {
        return TransactionSupport.transactionalize(implementationConstructor, [
            {
                property: 'name',
                pattern: TransactionSupport.PATTERN_SETTER
            },
            {
                create: 'createProperty',
                remove: {
                    name: 'removeProperty',
                    createArgs: function (property) {
                        return [property.getName(), property.getId(), property.getType(), property.getClassification()];
                    }
                },
                pattern: TransactionSupport.PATTERN_CREATE_REMOVE
            },
            {
                create: 'createRelation',
                remove: {
                    name: 'removeRelation',
                    createArgs: function (relation) {
                        return [relation.getTargetEntity(), relation.getCardinality()];
                    }
                },
                pattern: TransactionSupport.PATTERN_CREATE_REMOVE
            }
        ]);
    };

    /**
     * Creates a constructor which produces transactionalized Property implementation from the given Property implementation constructor
     *
     * @param {type} implementationConstructor
     * @returns {function}
     */
    DataModelTransactions.wrapProperty = function (implementationConstructor) {
        return TransactionSupport.transactionalize(implementationConstructor, [
            {
                property: 'name',
                pattern: TransactionSupport.PATTERN_SETTER
            },
            {
                property: 'type',
                pattern: TransactionSupport.PATTERN_SETTER
            },
            {
                property: 'classification',
                pattern: TransactionSupport.PATTERN_SETTER
            }
        ]);
    };

    return DataModelTransactions;

});