External Type Path Resolving
External Type Path Resolving
In many cases, it is necessary to use an external storage (e.g., a database file) that resides outside the application installation directory. However, it is often undesirable to hardcode absolute paths into the application configuration files or code, as this can lead to portability issues and maintenance challenges, as actual paths may be different from controller to controller.
To overcome this, a path resolving using environment variables and OS-specific slices can be used in external type path configurations.
Environment Variables Value Substitution
Environment variable references in the external type paths are replaced with the variable value, similarly to how standard OS environment variables are denoted in the respective OS scripts.
On Linux, these environment variable reference syntaxes can be used:
$ENV_VAR_NAME
or
${ENV_VAR_NAME}
And on Windows, this syntax:
%ENV_VAR_NAME%
Using these references in the paths will cause them to be resolved to the actual values of the respective environment variables at runtime.
Application-specific Environment Variables
Additionally, two application-specific environment variables are always defined by CDP that can also be used in the path resolving:
CDP_SYSTEM_NAME- The name of the system the application belongs to.CDP_APPLICATION_NAME- The name of the application.
OS-Specific Path Slices
To accommodate different operating systems with a single configuration, the resolving mechanism also supports OS-specific slices. These slices allow defining different path segments for Linux and Windows within the same path string.
The syntax for OS-specific slices is as follows:
[LINUX:linux_specific_path_segment][WINDOWS:windows_specific_path_segment]
Example Usage
Here are some examples of how to use environment variables and OS-specific slices in external type paths:
ExternalType="SQLiteValue; DBLocation=[LINUX:$HOME/.local/$CDP_APPLICATION_NAME:][WINDOWS:%LOCALAPPDATA%\\%CDP_APPLICATION_NAME%:]; DBName=[LINUX:${CDP_APPLICATION_NAME}:][WINDOWS:%CDP_APPLICATION_NAME%:].db"
In this example, the database location and name is defined differently for Linux and Windows, using the appropriate environment variables for each OS:
- On Linux, the database will be located in the user's home directory under
.localand the application name. - On Windows, the database will be located in the
LOCALAPPDATAdirectory under the application name. - The database name will be the application name with a
.dbextension, on both OSes.
Note: Note that the backslash in the Windows path segment has to be escaped (\) to ensure it is interpreted correctly.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.