4D v16Configuring the Wakanda Application |
||||||||||||||||||||||||||||||||
|
4D v16
Configuring the Wakanda Application
Configuring the Wakanda Application
On the Wakanda Enterprise side, you can connect to a 4D database:
Once a connection is established between Wakanda and 4D, the Wakanda application can use all the exposed tables, attributes and project methods of the 4D application as local objects. It is also possible to execute additional JavaScript code. For example, you could locally modify properties of remote attributes, or extend classes, or add calculated attributes. In Wakanda Enterprise Studio, the Connect to Remote Datastore... command (found in the File menu as well as the project's contextual menu) opens a link with a remote datastore. This remote datastore can be a 4D database or another Wakanda application. In both cases, the HTTP server of the remote datastore must be started in order for the Wakanda Enterprise Studio to be able to access the remote model. When you select the Connect to Remote Datastore... command, the connection dialog box appears: It contains the following connection parameters:
When a connection is established between Wakanda and 4D Server by means of the "Connect to a Remote Datastore" dialog box, Wakanda Enterprise Studio automatically creates two files (icons with a red arrow) in the folder of the project:
Note: You can see a file's extension in a help tip that appears when files are selected in the Explorer of Wakanda Studio. Wakanda Enterprise Server lets you establish a link with a 4D database by executing a JavaScript method. The connection method must usually be placed in the code that runs when the application is opened (bootstrap.js), or when the model is opened (model.js) in order for the link to be available during each session. There are three methods you can use to establish a 4D Mobile link:
The main difference between these methods concerns the way objects coming from the remote datastore are integrated in the Wakanda application: model.mergeOutsideCatalog() merges the remote catalog with the active model, while addRemoteStore() and openRemoteStore() generate dedicated models. For more information about this point, refer to Integrating with the active model or using a dedicated model below. The mergeOutsideCatalog() JavaScript method designates a catalog of remote data and merges it within your current Wakanda model. You must call this method in the .js file associated with the current model and executed by the Wakanda server. There are two possible syntaxes:
The advantage of using the syntax with an object is that you can add a .js file that is executed after connection to the 4D database. This file can locally modify the catalog referenced from the remote database.
For a more detailed description, refer to the documentation of the mergeOutsideCatalog() method in the Wakanda Server-Side API manual. The model object indicates the current "model" of the Wakanda application, in other words, the set of its "datastore classes" (tables) and methods. In the context of a 4D Mobile architecture, the Wakanda model can be empty. If the Wakanda application already contains objects, the classes and methods referenced from the remote 4D application are merged with the local model when you use the mergeOutsideCatalog() method. When the connection is established successfully, the "exposed" 4D tables are added to the classes of the model on the Wakanda side. In Wakanda Enterprise Studio, you can see the remote tables among the list of classes for the local model. External elements are indicated by a red arrow. The external catalog is also represented in Wakanda Studio by a specific catalog (named localName.waRemoteCatalog) that is also indicated by a red arrow: Note: File extensions can be hidden in Wakanda Studio. You can double-click on this file to view the external catalog in the model editor of Wakanda Enterprise Studio:
The openRemoteStore() and addRemoteStore() methods are alternative ways of establishing dynamic links between a Wakanda application and a 4D application. Like mergeOutsideCatalog(), these methods provide dynamic access to the data of 4D databases but they work in a different way:
openRemoteStore() only returns a valid reference in the current JavaScript context, whereas addRemoteStore() maintains the reference throughout the session. For more information, refer to the description of the openRemoteStore() and addRemoteStore() methods in the Wakanda documentation. Whichever way you connect with the remote 4D datastore (using the "Connect to Remote Datastore" dialog box of Wakanda Studio or executing a JavaScript method), you have to choose whether the remote classes (tables) must be merged with the active model, or placed in a dedicated model. This choice is summarized in the following table:
When you merge remote 4D tables with the active model, they are integrated into the default model of the application (whose datastore is the ds object), as local classes. The data access principles are:
These principles facilitate the development of 4D Mobile applications but may lead to naming conflicts between tables, in particular when the Web application calls on several remote datastores. In this case, it may be useful to place the remote elements in a dedicated model. When remote 4D tables are not merged with the active model, they use a "dedicated" model. Remote classes then use a namespace that is specific to the datastore to which the application is connected and they cannot be accessed in the ds object. This way it is possible to use several tables with the same name in several different datastores:
However, this principle has certain limitations in the current version of Wakanda Enterprise:
So it is usually recommended to choose the merged mode for remote datastores when your client application must access the data of the 4D remote tables directly. Wakanda Enterprise lets you modify certain characteristics of the local version of the external model, for the purpose of customizing, security or optimization. To do this, you just need to add the appropriate JavaScript code in a .js file that has the same local name as the catalog plus the suffix ".js" and put this file in the same folder as the model. For example, if the name of the local catalog is Emp4D.waRemoteModel, you need to use a file named Emp4D.js placed in the folder of the model. Notes:
Wakanda executes this file when the external catalog is initialized. Using this file, you can:
For more information about JavaScript code for working with models, refer to the Model API section in the Wakanda documentation. You can set specific permissions to Wakanda Server overall for the remote model and/or individually for each class. For more information about this point, refer to the Assigning Group Permissions section of the Wakanda documentation.
See also
|
PROPERTIES
Product: 4D
HISTORY
ARTICLE USAGE
4D Mobile ( 4D v16) |
||||||||||||||||||||||||||||||