The dspFactory Object

You can access services, such as retrieving an array of strings representing columns or attributes that are part of the entity (table or view) or formatting the value for a column or attribute, using the dspFactory JavaScript object.
lac53
You can define the structure of the underlying data structure--the attributes and types for the defined entities, procedure parameters, and function parameters--using the methods that are included with the 
dspFactory
 JavaScript object. This object returns a unique 
typeName
 parameter.
Use the methods that are included with the 
dspFactory
 object in the JavaScript code (the 
Initialization > structure
 section's code editor) for data source providers.
You can use the following styles of 
dspFactory
 object methods:
  • createXXX(name)
    : With this method, you include the named attribute.
  • asXXX()
    : With this method, the method auto-assigns the name of the attribute.
For example, you can create a string attribute with a length of 10 using the following alternatives:
var myStringAttribute = dspFactory.createString(“varchar(10)”, 10);
Or
var myStringAttribute = dspFactory.asString(10);
For an example of how 
Layer7 Live API Creator
 defines entity attributes by calling the 
dspFactory
 methods, see the 
createAttrType
 function within the code in the 
Initialization > structure
 section of the 
JDBCExample
 data source provider example. This function takes the arguments, determines an appropriate underlying type model, assigns a unique 
typeName
 variable, and then returns the variable. Repeat calls to this function returns the same variable.
For more information about data source providers, see Manage Data Source Providers.
In this article:
2
createBinary() Method
The 
createBinary()
 method returns a string value (name). It uses the following syntax:
dspFactory.createBinary(typeName, maxLength)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • maxLength
    : The maximum allowed length of the string. Use -1 for variable maximum length.
Example:
var myStringAttribute =
dspFactory.createBinary
(“binary”, -1);
JDBC data type:
 blob, binary, varbinary
JSON type:
 string
createBitmask() Method
The 
createBitmask()
 method returns a string value (name). It uses the following syntax:
dspFactory.createBitmask(typeName, numBits)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • numBits
    : The number of bits to store for this bitmask setting.
Example:
var myStringAttribute =
dspFactory.createBitmask
(“bitmask”, 3);
JDBC data type:
 bit
JSON type:
 number
createBLOB() Method
The 
createBLOB()
 method returns a string value (name). It uses the following syntax:
dspFactory.createBLOB(typeName, maxLength)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • maxLength
    : The maximum allowed length of the string. Use -1 for variable maximum length.
Example:
var myStringAttribute =
dspFactory.createBLOB
(“blob”, -1);
JDBC data type:
 blob, binary, varbinary
JSON type:
 string
createBoolean() Method
The 
createBoolean()
 method returns a string value (name). It uses the following syntax:
dspFactory.createBoolean(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createBoolean
(“boolean”);
JDBC data type:
 boolean
JSON type:
 boolean
createCLOB() Method
The 
createCLOB()
 method returns a string value (name). It uses the following syntax:
dspFactory.createCLOB(typeName, maxLength)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • maxLength
    : The maximum allowed length of the string. Use -1 for variable maximum length.
Example:
var myStringAttribute =
dspFactory.createCLOB
(“clob”, -1);
JDBC data type:
 clob
JSON type:
 string
createCollection() Method
The 
createCollection()
 method returns a string value (name). It uses the following syntax:
dspFactory.createCollection(typeName, collectionTypeName, baseTypeName)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • collectionTypeName
    : The value for this parameter is a string that represents the collection type.
  • baseTypeName
    : The value for this parameter is a string of a 
    dspFactory
     object 
    create
     method.
Example:
var collectionTypeName = ‘string’;
var baseTypeName = dspFactory.createString(‘string’, -1);
var myStringAttribute =
dspFactory.createCollection
(“myCollection”, collectionTypeName, baseTypeName);
JDBC data type:
 collection
JSON type:
 array
createDate() Method
The 
createDate()
 method returns a string value (name). It uses the following syntax:
dspFactory.createDate(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createDate
(“date”);
JDBC data type:
 date
JSON type:
 string
createDecimal() Method
The 
createDecimal()
 method creates a field that can hold up to predetermined number of digits of precision of which a predetermined number are decimal. This method returns a string value (name). It uses the following syntax:
dspFactory.createDecimal(typeName, precision, scale)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • precision
    : The value for this parameter is the total number or digits for this decimal variable.
  • scale
    : The value for this parameter is the total number or digits to the right of the decimal point in this decimal variable.
Example:
var decAttrStr =
dspFactory.createDecimal
(“MyNumber(10,4)”, 10, 4);
In this example, you want to create a field that can hold ten digits with four decimals.
JDBC data type:
 decimal
JSON type:
 number
createDecimalWithInfinity() Method
The 
createDecimalWithInfinity()
 method creates a field that can hold a predetermined number of digits of precision of which a predetermined number are decimal. The field can hold negative infinity and position. This method returns a string value (name). It uses the following syntax:
dspFactory.createDecimalWithInfinity(typeName, precision, scale)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • precision
    : The value for this parameter is the total number or digits for this decimal variable.
  • scale
    : The value for this parameter is the total number or digits to the right of the decimal point in this decimal variable.
Example:
var decAttrStr =
dspFactory.createDecimalWithInfinity
(“decimal(10,2)”, 10,2);
JDBC data type:
 decimal
JSON type:
 number
createDouble() Method
The 
createDouble()
 method returns a string value (name). It uses the following syntax:
dspFactory.createDouble(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createDouble
(“double");
JDBC data type:
 decimal
JSON type:
 number
createFixedBinary() Method
The 
createFixedBinary()
 method returns a string value (name). It uses the following syntax:
dspFactory.createFixedBinary(typeName, size)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • size
    : The maximum allowed size of the string.
Example:
var myStringAttribute =
dspFactory.createFixedBinary
(“decimal(10,2)”, 10);
JDBC data type:
 blob, binary, varbinary
JSON type:
 string
createFixedString() Method
The 
createFixedString()
 method returns a string value (name). It uses the following syntax:
dspFactory.createFixedString(typeName, maxLength)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • maxLength
    : The maximum allowed size of the string.
Example:
var myStringAttribute =
dspFactory.createFixedString
(“decimal(10)”, 10);
JDBC data type:
 char, nchar
JSON type:
 string
createFloat() Method
The 
createFloat()
 method returns a string value (name). It uses the following syntax:
dspFactory.createFloat(typeName, bitCount)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • bitCount
    : The number of bits for this setting.
Example:
var myStringAttribute =
dspFactory.createFloat
(“float(10)”, 10);
JDBC data type:
 float, real
JSON type:
 number
createInteger() Method
The 
createInteger()
 method returns a string value (name). It uses the following syntax:
dspFactory.createInteger(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createInteger
(“integer”);
JDBC data type:
 integer
JSON type:
 number
createIntegralNumber() Method
The 
createIntegralNumber()
 method returns a string value (name). It uses the following syntax:
dspFactory.createIntegralNumber(typeName, numBytes)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • numBytes
    : The number of bytes for this integer setting. 
    Values:1, 2, 3, 4, or 8
Example:
var myStringAttribute =
dspFactory.createIntegralNumber
(“float(10)”, 10);
JDBC data type:
 bigint, mediumint, smallint, tinyint, long, integer
JSON type:
 number
createIntervalTime() Method
The 
createIntervalTime()
 method returns a string value (name). It uses the following syntax:
dspFactory.createIntervalTime(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createIntervalTime
(“intervalTime”);
JDBC data type:
 interval (time)
JSON type:
 object
createJSON() Method
The 
createJSON()
 method returns a string value (name). It uses the following syntax:
dspFactory.createJSON(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createJSON
(“asJson”);
JDBC data type:
 json
JSON type:
 object (any)
createLong() Method
The 
createLong()
 method returns a string value (name). It uses the following syntax:
dspFactory.createLong(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createLong
(“long”);
JDBC data type:
 long
JSON type:
 number
createMediumInt() Method
The 
createMediumInt()
 method returns a string value (name). It uses the following syntax:
dspFactory.createMediumInt(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createMediumInt
(“mediumint”);
JDBC data type:
 mediumint
JSON type:
 number
createObject() Method
The 
createObject()
 method returns a string value (name). It uses the following syntax:
dspFactory.createObject(typeName, attributeNames[], attributeTypes[], attributeNullable[])
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • attributeNames[]
    : Defines the array of attribute names.
  • attributeTypes[]
    : Defines the definition of each column attribute for the data structure as an array of attribute types.
  • attributeNullable[]
    : This is an array of boolean values to determine null handling.
Example:
var attributeNames = [];
var attributeTypes = [];
var attributeNullable = [];
attributeNames.push("name");
attributeNames.push("uuid");
attributeTypes.push(dspFactory.createString("string", -1));
attributeTypes.push(dspFactory.createString("string", -1));
attributeNullable.push(false);
attributeNullable.push(false);
var myStringAttribute =
dspFactory.createObject
(“myObject”, attributeNames, attibuteTypes, attributeNullable);
JDBC data type:
 object, struct
JSON type:
 object
createPeriodDate() Method
The 
createPeriodDate()
 method returns a string value (name). It uses the following syntax:
dspFactory.createPeriodDate(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createPeriodDate
(“periodDate”);
JDBC data type:
 periodDate
JSON type:
 object
createPeriodTime() Method
The 
createPeriodTime()
 method returns a string value (name). It uses the following syntax:
dspFactory.createPeriodTime(typeName, precision)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • precision
    : The total length of the picos for period time.
Example:
var myStringAttribute =
dspFactory.createPeriodTime
(“periodTime”,1);
JDBC data type:
 periodTime
JSON type:
 object
createPeriodTimestamp() Method
The 
createPeriodTimestamp()
 method returns a string value (name). It uses the following syntax:
dspFactory.createPeriodTimestamp(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createPeriodTimestamp
(“periodTimestamp”);
JDBC data type:
 periodTimestamp
JSON type:
 object
createSmallInt() Method
The 
createSmallInt()
 method returns a string value (name). It uses the following syntax:
dspFactory.createSmallInt(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createSmallInt
(“smallint”);
JDBC data type:
 smallint
JSON type:
 number
createTime() Method
The 
createTime()
 method returns a string value (name). It uses the following syntax:
dspFactory.createTime(typeName, precision)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • precision
    : The total number of picos for this time setting.
Example:
var myStringAttribute =
dspFactory.createTime
(“time”, 2);
JDBC data type:
 time
JSON type:
 object
createTimestamp() Method
The 
createTimestamp()
 method returns a string value (name). It uses the following syntax:
dspFactory.createTimestamp(typeName, precision)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • precision
    : The value for this parameter is the total number or digits for this string.
Example:
var myStringAttribute =
dspFactory.createTime
(“timestamp”, 3);
JDBC data type:
 timestamp
JSON type:
 string
createTimestampWithZone() Method
The 
createTimestampWithZone()
 method returns a string value (name). It uses the following syntax:
dspFactory.createTimestampWithZone(typeName, precision)
This method can have the following parameters:
  • typeName
    : The value for this parameter must be a string.
  • precision
    : The value for this parameter is the total number or digits for this string.
Example:
var myStringAttribute =
dspFactory.createTimestampWithZone
(“timestamp”, 1);
JDBC data type:
 timestamp
JSON type:
 string
createTinyInt() Method
The 
createTinyInt()
 method returns a string value (name). It uses the following syntax:
dspFactory.createTinyInt(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var myStringAttribute =
dspFactory.createTinyInt
(“tinyint”);
JDBC data type:
 tinyint
JSON type:
 number
Additional Services
The 
dspFactory
 object also includes the following other methods. Examples of their usage are included in the code for the data source provider examples.
createRow() Method
The 
createRow()
 method returns a data map. This data map returns values to the code in the code editors in the 
Data Retrieval > byKey
 and the 
Data Retrieval > query
 sections for data source providers. It uses the following syntax:
dspFactory.createRow()
Example:
var rows =
dspFactory.createRow
();
newRow[“id”] = 12345;
rows.add(newRow);
findTypeDefinition() Method
The 
findTypeDefinition()
 method returns the baseType for a defined attribute using the value of the 
typeName
 parameter. It uses the following syntax:
dspFactory.findTypeDefinition(typeName)
The value for the 
typeName
 parameter must be a string.
Example:
var baseType =
dspFactory.findTypeDefinition
(“double”);
isProcedureRelevant() Method
The 
isProcedureRelevant()
 method method returns true if the stored procedure is not excluded in the data source filter. It uses the following syntax:
dspFactory.isProcedureRelevant(procName)
The value for the 
procName
 parameter must be a string.
Example:
var shouldKeepProc =
dspFactory.isProcedureRelevant
(“myProcName”);
isTableRelevant() Method
The 
isTableRelevant()
 method method returns true if the table/view is not excluded in the data source filter. It uses the following syntax:
dspFactory.isTableRelevant(tableName)
The value for the 
tableName
 parameter must be a string.
Example:
var shouldKeepTable =
dspFactory.isTableRelevant
(“tableName”);