Manage Non-Persistent Attributes
Manage Non-Persistent Attributes
You can extend your data model to include non-persistent attributes (NPAs). NPAs are pseudo-columns, or attributes, that are not in the schema. You can add and use them in your API without altering the database schema. Add NPAs when you cannot change the database schemas. For example, another application that does not change the value uses the NPA.
You can minimize data-maintenance tasks and speed development using NPAs.
NPAs are analogous to SQL optimizer hints. You can use them to tune API Server.
CA Live API Creatorcan compute rules as SQL expressions when the rules follow certain restrictions. It computes rules that compute values, such as formula rules, for NPAs faster than other rules. NPAs eliminate the SQL that
CA Live API Creatorrequires to synchronize your data with your rules.
CA Live API Creatorreflects NPAs in the OpenAPI (Swagger) documentation for your API.
NPAs can incur substantial performance overhead as compared to columns that are stored in your database. If you have tested your logic and then you discover performance issues, delete the NPAs and alter the schema to define the persisted columns.
CA Live API Creatorre-optimizes your logic.
For more information about performance, see the "NPA Best Practices" section.
In this article:
NPA Best Practices
The decision about whether you want
CA Live API Creatorto persist derived data can result in a trade-off:
- Performance.Non-persistent data can perform orders-of-magnitude slower than persistent data. This most often occurs with aggregate rules, when there are many children per parent, or when aggregate rules chain. For example, it can be expensive to compute a balance by adding up the items for the orders of a customer, or to compute a department budget by recursively summing the sub departments.
- Data consistency.Applications must update the derivation logic properly to avoid consistency errors.
It is not always clear how data distributions will turn out. Switching strategies by recoding the accessing logic can be expensive. You often discover these challenges near the end of development when you load full test data volumes. These challenge can result in rework and delays.
While the dilemma remains,
CA Live API Creatorcan eliminate the cost of rework. As you manage your NPAs,
CA Live API Creatoradjusts your logic accordingly. It maintains aggregate rules using adjustment logic.
For more information about how
CA Live API Creatormaintains aggregates using adjustment logic, see Performance.
Consider the following when establishing NPA best practices for your API:
- If you are using an existing system and you cannot change the database schema, add the NPA to your data source, and then reference it from table-based resources and from rules.
- If you cannot change the database schema by defining persistent attributes, do one of the following:
- For update (PUT/POST) logic, add NPAs to your data source, and then haveCA Live API Creatorcompute values or roll up sum/count aggregates by referencing the NPA in your rules, such as formula rules.
- For retrieval (GET) logic. For example, you store first and last names in your database but you want to create APIs that return the full name. You can set virtual resource attributes with lookup values using "fuzzy" foreign key in GET events.For more information about how to set virtual resource attributes with lookup values, see Define Table-Based Resource Types.
Verify the Prerequisites
Before add an NPA, ensure that you have:
- Defined entities (tables or views).
- Verified your data source.
Add a Non-Persistent Attribute to your Data Source
- With your API open, in the Create section, clickData Sources.A list of the data sources for your API display.
- From the list of data sources, select the data source to which you want to add the NPA.
- Click theNon-persistent attributestab.A list of your NPAs for the selected data source display.
- Above the NPA list, clickAdd.An NPA is added to your data source.
- Define the following fields, and then save your changes:NameThe name for the NPA. Use a simple name, without spaces and special characters.EntityThe entity (table or view) for which the NPA is defined.TypeDefine the type of data (data type) the attribute can contain.Values:
- Boolean:true or false
- Character:A single character
- Date:A SimpleDate (Year-Month-Day)
- Decimal:An arbitrary precision signed decimal number (such as money or percent)
- Integer:An integer number between -2,147,483,648 to 2,147,483,647
- Real:An IEEE 754 floating point number
- String:An arbitrary list of characters
- Timestamp:A SimpleTimestamp (Year-Month-Day-Hour-Minute-Second)
The NPA is added to your data source.
Use Non-Persistent Attributes
You can reference NPAs in entity resource attributes added to table-based resources and in rules, such as derivation and validation rules. The NPAs that you reference in entity resource attributes can return values. You can reference NPAs in entity resource attributes and then inject the computed values by using the attributes in rules.
B2B NorthwindAPI sample includes the
EmployeeWithRaisesresource with the
FullNameNPANPA added as a
FullNameNPAentity resource attribute.
For more information about this API sample, see B2B API Sample.
For more information about how to reference NPAs in resources, see Manage Resource Attributes.
View Non-Persistent Attributes
You can view the NPAs that you have added to your data source in the following locations:
- On the Schema page in API Creator.For more information about how to view your schema, see Database Connectivity.
- In the Swagger documentation for your API.For more information, see Access OpenAPI (Swagger) Documentation for your API.
- In Data Explorer.For more information, see Data Explorer.
Non-Persistent Attribute Limitations
The following are limitations to adding and using NPAs:
- You cannot add parent resource attributes that are NPAs to a resource.
- You cannot add NPAs to APIs that are connected to data sources that have been created using a data source provider. For example, you cannot create NPAs if your API is connected to the MongoDB data source. This data source uses the extensible data source framework.