How do include a global's extended reference when creating a class using cache sql storage? - intersystems-cache

I am creating a class that is mapped to an existing global so it uses cache sql storage not default storage. This class has extended references (UCKE, SYKE) whose values are set at run-time. How do I include the extended reference in the sql storage map? I can't seem to find any Intersystmes documentation about this.

Well, it's not entirely clear what specific problem you are running into. I just tested a class where I opened Cache Studio, went to the Object Inspector, selected Storage, went down to the row that shows SQL Storage Map, clicked the ellipsis that appear when that row is selected, selected the master map, and for the global name set it to ^[UCKE]MyGlobal. This generated correct .INT code for SQL statements.
Are you having problems making sure the local variables are set when the SQL runs? Did I just not understand what you were doing?

Related

Do classes necessarily have to exist prior to record insertion?

I'm coming from Neo4j and evaluating OrientDB, and I had a quick question about classes - do they have to exist prior to inserting a record? That is, in Neo4j there's the 'MERGE' command, which will update or create a node if it doesn't exist. Classes seem roughly equivalent to Neo4j's labels, and if a label doesn't exist when performing a MERGE, it will be created. Is there similar functionality in OrientDB? Currently when I try to insert a record whose class doesn't exist, OrientDB throws an exception, "Class SOME_CLASS not found in database".
I've been reading through the docs trying to get a handle on the various data models available, but I can't find anything explicit on this issue. One thing I tried was to add a cluster, and then insert a record with a class that does not exist. This worked, and in OrientDB Studio, under 'DB', I see the cluster with number of records equal to '1'; however, the class of that new record does not appear under 'Schema'.
If dynamic class creation of this sort isn't possible, is it acceptable to check if a class exists in the schema, and if not, create it, and then proceed with creating the record? A different question is, if it's acceptable, is it good to do this, or should I always define the schema manually?
If you use one of the CREATE commands, then the object is placed in a default class; for example:
CREATE VERTEX
Created vertex 'V#9:0 v1' in 0.047000 sec(s).
(In this case, the class is V.)
And of course if you use the INSERT INTO ... form, then you have to specify a class.
So perhaps your first question boils down to whether it is possible to change the class of an OrientDB vertex or edge.
It is possible to change the parent class of a vertex -- see
http://orientdb.com/docs/2.1/SQL-Move-Vertex.html -- but there are important caveats.
To test whether a class exists programmatically, see e.g. this SO entry:
Check if class exists or not in orientdb
This gives a Java example, but a similar approach is possible using other supported languages.
As to the wisdom of changing the class of an entity dynamically -- perhaps the safe answer is that if you can achieve whatever you want using a property label, then use labels.

Why does Titan have this limitation?

It says here:
The definition of an edge label, property key, or vertex label cannot
be changed once its committed into the graph.
In contrast SQL Server, which is what I'd normally use, doesn't have a problem with, say, changing the type of a field or the cardinality of a relationship.
This isn't even in the Temporary Limitations section of that web page.
Why is this limitation here and what am I supposed to do when I make a mistake when defining a type? Delete the whole database and import all the data into a new one?

Does SQL Table name === Class name? and vice-versa?

So I'm just learning Cache, and have a question about tables, classes and globals, what's the difference?
I'm doing the tutorial and it seems like, since this is an object-orientated DB that a class is a table and vice versa. So if I create a class and make it persistent with properties, I can use SQL to query it. Is this true? What's a global then?
Reason I ask is because I'm using Management portal for one of our Cache applications and although I can see a table in WinSQL and Documatic, that same table doesn't seem to exist in the class explorer (Under management portal)... can't figure it out, is it hidden? Is there a command to see class def'ns in terminal??
thanks!
In Caché, classes are tables and tables are classes. You can choose when you want to use SQL access and when you want to use Object Oriented access.
Globals are the sparse multidimensional arrays which sit as storage beneath the class/table. Look at the storage definition at the end of your class to see the actual globals that your persistent class is stored in (e.g. ^Sample.PersonD)
By default, class names are projected as table names, but there are some rules which apply in order to ensure that the table names comply with SQL standards:
if you have a class that is a couple of packages deep (e.g. MyApp.Data.Person) then all but the last "." will be replaced by "_" in the table name (e.g. MyApp_Data.Person would be the table name)
You can't use reserved SQL keywords in table names, so if you make something in the User package for example (class: User.Person) then Caché will change the Package name (e.g. SQLUser.Person would be the name of the table)
I suggest you refer to http://docs.intersystems.com/cache20141/csp/docbook/DocBook.UI.Page.cls?KEY=GORIENT_ch_persistence for more detail

query enterprise architect database

I need to query the EA database in order to discover the visibility status of a class attribute.
I've been snooping around but could not find the table where this information is stored.
Any help will be appreciated.
This is a case of inconsistent naming in EA. The property that's displayed as the attribute's Scope in the GUI is referred to as Attribute.Visibility in the API, and stored in t_attribute.Scope in the database.
Similarly, the same property of an element is displayed as Scope in the GUI, referred to as Element.Visibility in the API and stored in t_object.Scope in the database. There is a column t_object.Visibility, but it appears to be unused.

How to manage Constants in Application

what is the best way to use Application Constants ?
What i usually do is create a separate table in database of constants and reference them as foreign key in other table.
In Java i use enum.
But how to keep a single place of authority for constants in application and what are the different ways i can do that(like table or enum).
What you described is a usual approach. You keep "constants" in the database layer and you mirror them in the application using enumerations. The only trouble is keeping them in sync. Following a strict process can help here. For example, you always update values on both levels immediately one after another, not interrupting the process for any purspose and checking in the changes immediately after it's done.
Another idea would to oly keep constants in the database. You also assign names to them. Whenever you use a constant in your application (by name) it is transparently loaded from the database. This way any change you introduce will immediately be seen by any user connecting to the database. The only error may be caused by an update happening in the middle of a transaction.