Skip to main content
Version: Next

DataStore

A Datastore is the interface object provided by ORDA to reference and access a database. A Datastore object is returned by the ds command (a shortcut to the main datastore) or the openDatastore command.

Functions and properties

.cancelTransaction()    cancels the transaction
.dataclassName : 4D.DataClass    all attributes of the dataclass as objects
.isAdminProtected() : boolean    returns true if Data Explorer access has been disabled for the working session
.setAdminProtection( status : boolean )    allows disabling any data access on the web admin port, including for the Data Explorer in WebAdmin sessions
.startTransaction()    starts a transaction in the current process on the database matching the datastore to which it applies
.validateTransaction()     accepts the transaction

.cancelTransaction()

.cancelTransaction()

ParameterTypeDescription
Does not require any parameters

Description

The .cancelTransaction() function cancels the transaction opened by the .startTransaction() function at the corresponding level in the current process for the specified datastore.

The .cancelTransaction() function cancels any changes made to the data during the transaction.

You can nest several transactions (sub-transactions). If the main transaction is cancelled, all of its sub-transactions are also cancelled, even if they were validated individually using the .validateTransaction() function.

Example

See example for the .startTransaction() function.

.dataclassName

.dataclassName : 4D.DataClass

Description

Each dataclass in a datastore is available as a property of the DataStore object. The returned cs.object contains all attributes of the dataclass as objects.

Example

 var emp : cs.Employee
var sel : cs.EmployeeSelection
emp = ds.Employee //emp contains the Employee dataclass
sel = emp.all() //gets an entity selection of all employees

//you could also write directly:
sel = ds.Employee.all()

.isAdminProtected()

.isAdminProtected() : boolean

ParameterTypeDescription
Resultbooleantrue if the Data Explorer access is disabled, false if it is enabled (default)

Description

The .isAdminProtected() function returns true if Data Explorer access has been disabled for the working session.

By default, the Data Explorer access is granted for webAdmin sessions, but it can be disabled to prevent any data access from administrators (see the .setAdminProtection() function).

See also

.setAdminProtection()

.setAdminProtection()

.setAdminProtection( status : boolean )

ParameterTypeDescription
statusbooleantrue to disable Data Explorer access to data on the webAdmin port, false (default) to grant access

Description

The .setAdminProtection() function allows disabling any data access on the web admin port, including for the Data Explorer in WebAdmin sessions.

By default when the function is not called, access to data is always granted on the web administration port for a session with WebAdmin privilege using the Data Explorer. In some configurations, for example when the application server is hosted on a third-party machine, you might not want the administrator to be able to view your data, although they can edit the server configuration, including the access key settings.

In this case, you can call this function to disable the data access from Data Explorer on the web admin port of the machine, even if the user session has the WebAdmin privilege. When this function is executed, the data file is immediately protected and the status is stored on disk: the data file will be protected even if the application is restarted.

Example

You create a protectDataFile project method to call before deployments for example:

 ds.setAdminProtection(true) //Disables the Data Explorer data access

See also

.isAdminProtected()

.startTransaction()

.startTransaction()

ParameterTypeDescription
Does not require any parameters

Description

The .startTransaction() function starts a transaction in the current process on the database matching the datastore to which it applies. Any changes made to the datastore's entities in the transaction's process are temporarily stored until the transaction is either validated or cancelled.

If this method is called on the main datastore (i.e. the datastore returned by the ds command), the transaction is applied to all operations performed on the main datastore and on the underlying database.

You can nest several transactions (sub-transactions). Each transaction or sub-transaction must eventually be cancelled or validated. Note that if the main transaction is cancelled, all of its sub-transactions are also cancelled even if they were validated individually using the .validateTransaction() function.

info

A transaction represents a series of changes made within a context on interconnected data. A transaction is only permanently saved in the datastore when the transaction is validated as a whole by calling .validateTransaction(). If a transaction has not been validated, whether it was cancelled or because of some external event, the changes are not saved.

Example

 var connect,status : object
var person : cs.PersonsEntity
var ds : cs.DataStore
var choice : string
var error : boolean

ds.startTransaction()
person = ds.Persons.query("lastname == :1","Peters").first()

if(person != null)
person.lastname = "Smith"
status = person.save()
end
...
...
if(lastErrors[0].errCode != 0)
ds.cancelTransaction()
else
ds.validateTransaction()
end

.validateTransaction()

.validateTransaction()

ParameterTypeDescription
Does not require any parameters

Description

The .validateTransaction() function accepts the transaction that was started with .startTransaction() at the corresponding level.

The function saves the changes to the data that occurred during the transaction.

You can nest several transactions (sub-transactions). If the main transaction is cancelled, all of its sub-transactions are also cancelled, even if they were validated individually using this function.

Example

See example for .startTransaction().