== defining different types of functions n libraries ==
== Functions - overview of different "types" ==
This sections covers how to define different "types" of functions in libraries.
=== by using static methods ===
This will be mostly utility functions and so on, where there is no need to instanciate an object. You'll need this probably the most time.
--> Static object with static functions.
This will be mostly utility functions where there is no need to instantiate an object. You'll need this probably the most time.
-> Static object with static functions.
Definition:
...
...
@@ -98,39 +101,103 @@ var additionals = CommValidationUtil.getExtensionsBlueprint();
You may want to hold data and create objects where methods share that data.
Definition:
Here is an example for an object that can be created:
[source,javascript]
----
/**
* object for easier handling of conditions; <1>
* With this object you do not have to check if the string is empty or not;
* you don't need to append a "1=1" condition or similar;
* this objects gains most benefit if you have a lot of conditions that are added (or not) depending on tons of JDito-conditions
* @class
* @param {String} [alias=the current alias] the database alias where the condition shall be executed later (important for column types of preparedStatements) <2>
* @example //TODO: add missing example <3>
* object that provides featrues for a single keyword attribute; initalizes itself on creation with a specific keyword-attribute
*
* @param {String} pContainerName specifies the type of the keyword and therefore the list elements;
* e.g. "COUNTRY"; use an entry of the $KeywordRegistry here
* @param {String} pAttributeName the name of the keyword attribute that shall be initalized
* @param {String} [pDefault=undefined] the default value -> Does not throw an error, if default value exists.
*
* @class
*/
function SqlCondition(pAlias) <4>
function KeywordAttribute(pContainerName, pAttributeName, pDefault)
{
//setting null is only needed to provide autocomplete for the ADITO-designer
this.preparedValues = null;
this._init();//the properties are initialized in an extra function because init is nearly the same as resetting (clearing) the SqlConditions
this.alias = alias;
this.container = pContainerName;
this.attribute = pAttributeName;
this.defaultValue = pDefault;
var keywordAttrData = newSelect("AB_KEYWORD_ATTRIBUTE.AB_KEYWORD_ATTRIBUTEID, AB_KEYWORD_ATTRIBUTE.KIND")
throw new Error(translate.withArguments("no keyword attribute \"%0\" found in keyword \"%1\" from container \"%2\"", [this.attribute, pKeyId, this.container]));
}
else if (this.defaultValue == undefined)
throw new Error(translate.withArguments("no keyword attribute \"%0\" found in keyword container \"%1\"", [this.attribute, this.container]));
else
return this.defaultValue;
}
/**
* get a SqlBuilder object for this keyword attribute. You can easily add additional conditions to it.
*
* @return {SqlBuilder} a SqlBuilder which contains a select for the entry-id's, joins to entry and attribute
* and conditions for the container and the attribute-name.