Generating Object Queries from Primary Key Attributes

An object query is automatically generated for each mobile business object (MBO) attribute identified as a Primary key, as well as an additional "composite" object query if there are multiple primary keys.

If an MBO uses an Online cache group policy, these options are disabled. See Online Cache Group Policy. Object queries generated from primary key attributes return a single instance (row) of data, which is useful in many applications. For example, you could create a new record and use the object query to return that record to the device application. Depending on the data source to which the MBO is bound, it may require multiple primary keys to uniquely identify an instance of the data. Unwired WorkSpace:
  • Generates an object query named findByPrimaryKey. This query could be generated from a single primary key attribute, or a composite, if multiple attributes are identified as primary keys:
    • Generates an object query named findByPrimaryKey if there is only one primary key attribute.
    • If there are multiple primary keys, generates an object query for every attribute identified as a primary key . For example, primary keys attA, attB, and attC generates queries findByattA, findByattB, findByattC, and findByPrimaryKey (which is a composite of the three primary keys).
    • For auto-generated queries, the return type for 'findByPrimaryKey is a single object, with a setting of isMany = false, for other auto-generated queries, the return type is a multiple object, with a setting of isMany = true.
  • Allows you to delete any of the auto-generated object queries. A warning message appears, if you delete the findByPrimaryKey object query. Deleting other queries does not generate a warning message. For example, if you:
    • Remove query findByA, uncheck Primary key for attribute A, then check Primary key for attribute A again, the query findByA is generated again.
    • Remove query findByPrimaryKey, then check or uncheck Primary key for any attribute, findByPrimaryKey is generated again.

The steps for manually generating the findByPrimaryKey object query are:

  1. Create the MBO from an existing data source. For example, drag-and-drop a table on to the Mobile Application Diagram.
  2. From the Properties View Attributes tab, select the Primary key attribute(s) that uniquely identify a row.
  3. An informational prompt informs you that the name query will be generated. Click Ok.
    Corresponding object queries are generated.
  4. Select the Object Queries tab to view the query definition.
    The Primary key query follows these guidelines:
    • The name of the query is findByname, where name is the name of the attribute. If the primary consists of only one attribute, there is only a findByPrimaryKey method and it returns a single object.

      If a primary key consists of multiple attributes:

      • findByPrimaryKey is still generated, and
      • findByAttribute1, findByAttribute2 are generated, but can be deleted. In this case, Attribute1 and attribute2 are also primary keys.
    • If you change the primary key attribute name, the name of the query automatically changes as well.
    • If you change the MBO name, the query definition is automatically updated to reference the newly named MBO.