Question
· Mar 25, 2019

Subclasses and/or Inheritence

First time post, also a new Cache developer, hence the <Beginner> tag.

If our data has Predefined terms in a dictionary, and a user can add terms on their own, can the terms exist in different tables?

Lets call the tables "Terms" and the user data in "UserTerms".

If a third class definition has a property of "Term" can it not be either Terms or UserTerms?

I'm leaning towards using a Subclass strategy where the pseudo "Parent" (forgive me) is  Dictionary.Term and the child is along the lines of Dictionary.Term.User

Dictionary.Term.User can inherit from Dictionary.Term and this is stated in the Docs "If class B inherits from class A, you can use an instance of class B in any location where you can use an instance of class A."

This applies to properties of a class correct? Not just methods?

Is there an alternative data model for this that would support the access to the predefined terms to be in a read-only database so as to protect them from changes, yet the users can add terms all they want?

Discussion (5)0
Log in or sign up to continue

This applies to properties of a class correct? Not just methods?

Correct.

You have several solutions:

  1. Application level control. You have one table Term { Name, Type} and on the application level you decide for edits to go or not based on type. It is the fastest solution, but you need to write a application code and remember to check for type.
  2. Class-level control as described by you.
  3. Row-level security. Control access row by row.

Interestingly, I am researching this for a customer. Another way to do this that I have seen is to seed the ID counter at the site to a really high number (e.g. set ^Vendor.CountryD=10000000) after the initial Country code table is deployed. Then, new entries that are distributed by the vendor will never have conflicting IDs (assuming no more than 10000000 entries are ever shipped of course). But this also means that you can't ship the whole vendor copy of the global as you will overwrite the onsite ID counter node.

And, in a multi-tenant/namespace deployment you can't generate SQL or Object Insert scripts - if you have indices on the table then they need to be built locally for each namespace and global mapped and so you would need to run the insert script on each namespace to maintain the indices. However, rebuilding the indices on code tables should be pretty quick as they tend not to be huge, and hopefully won't balloon the journals too much....

I like the idea of a read-only distributed database - oddly I hadn't thought of that as an extra layer of protection beyond what the application code may provide

The biggest issue with this approach though is  likely to be the risk of a unique property collision - customer adds MYNewCountry , and then at some point so does the Vendor. And so an upgrade script would have to check for that - possibly renaming the customer object to say MyNewCountryX.

But this also means that you can't ship the whole vendor copy of the global as you will overwrite the onsite ID counter node.

You can! When you load globals specify /mergeglobal flag to merge the global with existing data instead of overwriting it:

set sc = $system.OBJ.Load("global.xml", "/mergeglobal=1")

seed the ID counter at the site to a really high number

Bitmap indices would really slow down from that.

Bitmap indices maintain one node per each chunk of 64 000 id's, if at least one id from that range exists. So random integer ids can slow bitmaps down. On the other hand if there are two consecutive but spread (i.e 1..1000 and 100000...110000) id sequences it would generate just 2 global nodes so everything should be ok in that scenario.

Check index global in various scenarios:

 
Example.Bitmap