⬆️ ⬇️

Backstreet Access To Intersystems Cache '





Backstreet Access To Intersystems Cache







“Some works may differ in greater depth of thought

and the best knowledge of human nature; other books maybe

not inferior to mine in terms of originality and volume,

but with its hopeless, incurable authenticity, it surpasses

all still discovered works. "



JK Jerome. "Three in the same boat, not counting the dogs"


')

In order not to trample in the front door, while smoking manuals, trying to read into advertising brochures or listen to the passionate assurances of another wavy parrot from Aichi, I invite you to enter the world of Cache 'from the outskirts - to do some kind of illegal diving. As a person working with this technology is not the first (and the second!) A decade and little-little-familiar with it, I hope that I can master the role of a guide on this simple journey.



I briefly report to those interested in the subject: the discussion will be about the DBMS on the one hand rather obscure, on the other - claiming to be the silver bullet for the developer of all kinds of integrated circuits, CIS, IArI and so on. and so on If you have any relation to the software market, the time spent will pay off - I tried to fit my best experience of recent years. Not at all academic. And even if you have already failed to comprehend Cache 'unsuccessfully - believe me, sometimes even entering the most respectable institution from the gateway (with the right escort) turns out to be more effective. And what’s too bad to conceal and be modest - it is often the case in the satellite.










So, the first five minutes to deploy.





"And if you suddenly get bored with your gentle light,

You will have a place with us, there will be enough rain for everyone. ”



V. Tsoi




You will laugh, but the most difficult thing in this process is to install and configure a web server. Including and because colleagues from Intersystems did not work very well.



I have been relying on Apache for many years as such. With thousands of users is quite an acceptable option. Social networks and other load entertainment with their nginx's are beyond the scope of the discussion. Cache 'is first of all a DBMS, and then everything else. But! Want to scale - easily. If you call 8-800-2600- right now ... then I will make for you not only scaling, but also an individual amulet-ward from bugs and deadlocks, tuned exclusively to your aura.



But to the point. On http://www.apache.org/dist/httpd/binaries/win32/ we take away the file httpd- 2.2 .22-win32-x86-no_ssl.msi . Here is version 22, but if you get a later one, no big deal, the main thing is 2.2. If you already have an Apache web server, omit this step - Cache 'minimally affects the settings - about this after the next image. IIS fans can only offer myself to have fun with the settings - I offer a simple way on these pages, and IIS always walks in the front doors.







Nine clicks, twice entered "localhost", a little feathers and ... the most difficult thing behind.



The next step is two times simpler. But we will need to register: http://download.intersystems.com/download/ . We'll have to fill as many as 11 fields and click six checkboxes (there are no worse marketers than the best DBMS vendors), but art requires sacrifice:









Managed in 5 minutes? I, too!



I would like to say "voila" here and poke in exclamation marks, but no - the guys from Intersystems (hereinafter I will gently say "IS") condescendingly allowed us to demonstrate how well we own the file.



Find the file C: \ Program Files (x86) \ Apache Software Foundation \ Apache2.2 \ conf \ httpd.conf



At the very bottom of it (remember, we came from the gate) we find a terrible construction of the form



#### BEGIN-CSP-SECTION () ####

LoadModule csp_module_sa "C: / Program Files (x86) / Apache Software Foundation / Apache2.2 / CSPGateway / CSPa22.dll"

Alias ​​/ csp / "C: / InterSystems / TryCache / CSP /"



<Directory "C: / InterSystems / TryCache / CSP">

AddType application / x-csp .csp .cls .zen .cxw

AllowOverride None

Order allow, deny

Allow from all

</ Directory>

#### END-CSP-SECTION () ####

#### BEGIN-CSP-SECTION (TRYCACHE) ####

Alias ​​/ trycache / csp / "C: / InterSystems / TryCache / CSP /"

#### END-CSP-SECTION (TRYCACHE) ####



We leave only her

#### BEGIN-CSP-SECTION () ####

LoadModule csp_module_sa "C: / Program Files (x86) / Apache Software Foundation / Apache2.2 / CSPGateway / CSPa22.dll"

#### END-CSP-SECTION () ####



Having embellished it a bit, we get:

#### BEGIN-CSP-SECTION () ####

LoadModule csp_module_sa "C: / Program Files (x86) / Apache Software Foundation / Apache2.2 / CSPGateway / CSPa22.dll"

<Location / csp>

CSP On

SetHandler csp-handler-sa

</ Location>

#### END-CSP-SECTION () ####



Happiness is in simplicity. I, strictly speaking, do not even remember what the difference is. But what you see in the end - it works. And how it works. And what is written by default is buggy anyway.



How to stop and restart Apache, I hope you will understand. Hint: we are looking for a red feather with a green arrow in the tray - it reacts to the mouse, believe me.








Well, here we are in Cache '!





“There was a terrible crash.

Alice fell on a pile of dead trees and dried leaves.

She did not hurt herself at all and quickly jumped to her feet. ”



L. Carroll "Alice in Wonderland"




You have no idea how nice it is to welcome you to Cache 'after five minutes of communication. Well, if a little later, then I don’t answer for the bad “these are your internet”.



Checking that everything works: http: //localhost/csp/samples/ZENDemo.Home.cls - are we seeing a hypno-triangle? So everything is ok. The browser may ask to display SVG-content - I allowed and advise you.



Already saw the cube in the tray? If not, I show (we are looking at the bottom right of the screen):















It is from this very cube that all further will occur. But only if it is blue. But if the cube is gray, it means that Cache 'did not start up for you - for the Valkam that kaments.



It's time to forgive the developers for the bad Apache configuration and tune in a positive way. Moreover, in the near future, they are developed IP, we are more than not let you down.



For example, on the Cache cube, no matter how hard you press - with the right button, with the left - the menu is always the same:







First, take a look at the system management portal. I know a couple of companies in which no one knows how to use it at all and at the same time the institutions are flourishing. We are now required from the portal to create an area for work.



We distinguish the database and area:

The Cache database (Database) is a file on disk, the records in which belong to our database on the simple basis that they are in this file.

The domain (Namespace) is the definition in the Cache 'configuration, which contains information about which databases we use and for what purposes. A region can take programs from one database, and data from another. This is one of the basics of scaling in Cache '- simple and very convenient. By changing the definition of the area, I can instantly switch all users of the system to work with updated programs, but with current data - which I do about two weeks later - I am replacing the versions of all programs, but users almost do not notice.




Create an area:











Here, by the way, it is just noticeable that for the field globals (learn this word - this is how Cache 'stores data) and programs can be taken from various databases.



Since we want to create a new database for the new domain, we first do this:











Then "Next", again "Next" and "Finish" - the database was created, and we returned to the creation of the area:







And so:







Completed the next five minutes of communication with Cache '. We now have our own privatized field for experiments. There are still no results, but after a couple of minutes we will erect something with you - I guarantee.








Studio in the studio!





“But somewhere I nudged it with a silt,

I spotted something in the dust

Inside somewhere blew, spat, -

What do you think - let's go! ”



A.Tvardovsky "Vasily Torkin"




You, too, itching to give something to the top? Solidarity. We press on the blue cube at the bottom right:











The studio will ask us about what area we will work with - choose BS and click OK, we don’t need a password yet:







Initially, Studio Cache 'appears before us in the form of a rather complex construction:







But a little work with the crosses and dragging, you can achieve an adequate presentation. "Inspector", "View" and so on. We will need them, but later, and in the next picture I highlight how to turn them on (four buttons above), in which case. I feel comfortable like this:







At this point, the struggle between the desire to demonstrate the next "Hello world!" and match the reality of programming was won last - play in an adult.








Where do programs come from?





"The pyramid turned out to be a simple, but very entertaining mechanism -

a kind of fixer that turned illusion into reality.

You just need to come up with something, and then turn on the pyramid, and the created

imagination becomes as real as the world around .. "





K. Saymak "Transfer Station"




Imagination, it seems to me, perfectly helps to design software. But when setting the task there is no worst adviser - and it is very important not to forget about it. Therefore, we proceed simply. We use one of the models of the Library of Free Data Models from DatabaseAnswers.org. Thus, we omit both the stage of problem statement and design. In any case, Cache 'is not an assistant here.



Take a model, for example.







I propose to implement from left to right and from top to bottom. Well, or something like this.

Classes are our everything. On the sections of the Studio "Programs", "CSP-files" and "Other" forget. This is for guys interested in a facade. And for the respected pensioners Cache veterans.




So, create a class with a flick of the right button:





It should be noted that the classes in Cache 'are located in packages. For example:





With the invention of the names of the packages and their nesting recommend to be very careful. Occam's razor , as it was once presented to me, says that it is not necessary to multiply the number of entities beyond what is necessary. However, few cope with it. After all, it is most difficult to understand the banal idea - you can know it, be able to reproduce it with various organs, teach it to others, be able to use it. But do not understand at the same time. The principles of Le Chatelier , Heisenberg , Occam and Sandwich many people can never understand. After all, they are sure that they ALREADY understand them.



So, after the request to create a class, we will be shown the corresponding dialog:







How to name packages and classes?

Then fit to remember about the design patterns . When an applicant for an interview to the question "Which templates do you use more often?" replies: "Different - well, the conveyor goes well ...", - you immediately understand that the person in front of you is responsible and ready for the routine. And not ready to give names to packages in Cache '.



A Cache'-designer should always think of domain objects (Domain Model, DM). Night. The outside. Lamp. Pharmacy. Who wants to use abstraction - please enter from the front door. We have everything here in a simple way - we traditionally bring all kinds of "accounting registers" to a liquid state and merge it into. As compensation for the torment of the type "well, how is it to call it that it was in the DM?" sooner or later, perfect synergy sets in - the system begins to respond adequately to the impacts for which the designer did not prepare it.



A sign that you know this template is simple: You do not need to do anything for half of the new customer requests. The system behaves in the same way as a real business is flourishing.



DM is the main template. And he is useful to us first.



Another small remark:

Cache 'offers not just a good implementation of the domain model. It is very concise and convenient means provided encapsulation not only data, but also the behavior of domain objects in the appropriate classes.





So we call:







And immediately we press "Finish". The fact is that after clicking "Next" you will be shown a completely useless additional form, so I don’t want to waste our time.



That's exactly what the class blank in Cache 'looks like:







I do not know about you, but my heart stops when I see such constructions. Nothing extra. No these stupid "public static void main" and others include stdio.h - freedom!



For all the apparent simplicity - thousands of lines of system code, courtesy of the IC, now (after compilation, of course) will allow to work with this class. We have not done anything yet, but the system already knows how to create instances of it, delete them, execute queries and much, much more. Just because it is inherited from the% Persistent system class, which implements object storage and access.



But without data it is not very reasonable to do this. Let's fill our class with properties (right inside the window use the right mouse button):











I also propose to immediately press "Finish". We use the "Next" button, but a little later.



Check with the scheme. There are still two properties of the entity "Place of presentation" - they are added in the same way by the right button. Or using "Ctrl-C + Ctrl-V". Then I propose to compile the class right away:







Now check that this class works.



First we feel it as an object. For simplicity, we will do this through the Cache terminal. Click on the tray cube, select "Terminal":











We get a terminal window with the command line Cache '. "USER" is the default domain. You can rummage in the settings to change it to "BS".







But there is a simpler way - the command to change the " zn " area. After moving to our area, we create an instance of the class, fill its properties and save:



Host: papahost, Instance: TRYCACHE



USER> zn "BS"



BS> set obj = ## class (place.One).% New () // Do not care about the constructor



BS> set obj.Name = "Chapito" // Do not care about getter setters



BS> set obj.Description = "On the site near the station"



BS> do obj.% Save () // Do not care about how data is saved




Do not be scared. This is for verification only. In actual development, objects appear and remain more civilized. About this a little lower.

All our objects are also presented as SQL tables. In fact, there are several data accesses - you can work with them as with objects (we tried it above), as with tables (more on this below), and get so-called to them. "direct access". I will keep silence about the latter here - if you don’t know about it, you will lose little, but you want to figure it out, I think, master it.



For SQL data access on our cube, select the "System Management Portal", and go to the SQL queries:







Further:

1. Choose our area "BS"

2. Enter the query "select * from place.One"

3. Execute the request

4. We see a line of the table where the object we have saved is displayed.







SQL Access allows you to fully utilize regular SQL syntax. You can experiment, but there is one piece of advice: I do not use the INSERT, UPDATE and DELETE commands on domain classes. The handling of triggers and events (for example, when saved) may differ. And all the work invested in the implementation of the subject area will be ashes when using these commands. Instead of SQL commands, we will use the% New (),% Save (),% DeleteId () methods.



So, I hope that you, too, everything turned out. That is, we created a class with simple properties and made sure that it works.








First application





"Playboy figure, Coco Chanel's lingerie,

And that girl is just a new model ...

Allou pops, I say without hiding.

Allou pops, I get in touch. "





I.Lagutenko




I don’t remember exactly which version of Cache 'ZEN appeared in, but I know for sure that for me from that moment the superfine client was finally the only and non-alternative client for Cache'. I will say more - if at the time of CSP (Cache Server Pages is a technology from the asp, jsp series, etc.), the transition from the CSP + Cache task to the PHP + MySQL task and back was quiet and smooth, then with ZEN no longer so - labor costs when using ZEN (and the database implementing the subject area) are so ridiculous that any other way of designing, developing and maintaining is perceived as hard labor. In general, as in that bearded joke - not using ZEN in Cache 'on new tasks you act either stupidly or meanly towards the customer.



And I wrote it longer than I’m going to spend on a demonstration now. Click "Create":







Go to the tab "Zen" and select "New Zen-page":







Further, we are offered a form for input. Frankly, working with ZEN for more than 5 years, I probably see her for the third time. Basically, to create pages, I copy the code for the most appropriate ZEN page that I once created and make the necessary changes. But for the first page we will use it:







You already understood that zen-pages are the same classes. And they are also packed in bags. We will think up the name:







And immediately click "Finish". "Next" please do not touch - you will get to the place where you feel some awkwardness for the supplier of the product. It should turn out like this:







Wow piled on! When I talked about not using the template, I meant exactly these effects. Put in order and compile (Ctrl-F7):







Basically, we created the application. Do not see "Hello, world!"? So do I. But the app is ready to go. You can go to it by pressing the globe in the menu (to the right of the compilation button) or "F5". But there are two nuances:



1. The address for viewing will look like http: // localhost: 57772 / csp / bs / zui.Places.cls - the fact is that when installing Cache, it deploys a web server on port 57772 for its own needs and for some reason tries through him, to demonstrate our success in the Studio. This web server has a number of limitations and we don’t want to use it. Therefore, let's set up the display of pages from the Studio in our Apache - for this, in the Studio menu, select "Project" - "Settings", and in the "Advanced" tab of the window that appears, clear the port (remove everything starting with a colon so that localhost is released):







After that, in the Studio menu, save the project - "File" - "Save Project".





2. The fact is that when we created a region, the system created a csp-application for it (ZEN runs on top of csp). Access to the newly created application is limited - we will be prompted to enter a name and password. And this is good! But he will have to spend some time on creating a user and assigning rights to it. We are waiting for the cube and open the "System Management Portal"







(and when finally the IP will remove the DeepSee section ... or it will dismiss this marketer, I won’t buy it!)







The button "Create New User" is quite noticeable - and especially hurts the eyes of a person who is somewhat familiar with the Russian language. Interestingly, this translator, too, passed on his exam?It does not look like we are in the old fashioned way. About security, if Cache happens, I recommend to take care of - at least delve into the "Intersystems Cache Database Security Settings Standard" - sometimes the month of one technical writer is more useful than the year of the ordeal of the development team - the text is critically useful. If you find where in the Portal there is a security audit - also be sure to explore - broadens the mind.



For the purposes of acquaintance, we will simply do - create a user with the rights of% All - that is, "All Inclusive" - ​​everything is allowed - the IC can make you feel like a god (sometimes):







Enter the name and the password twice - do not touch anything else. Until.Click "Save" and go to the "Roles" tab. Choose the role of% All, and assign it to the user:







It should turn out like this:









Actually, Cache '(and ZEN) perfectly implements the user-role-resource approach. But I'm afraid my time for this may not be enough - experiment yourself. Get a lot of positive emotions. I hope. But back to the Studio and press "F5" (or the globe). Enter the name and password on the zen-page, our first application opens:







Again, nothing superfluous. Beauty!It’s hard to imagine that this delightfully blank page could be spoiled by the presence of some “Hello, world!” (foreign agent).



An experienced developer will understand what I really enjoy - of course, the absence of errors. She spins! 90% of the work done.








(!)





« — ,

.

, .









This part should be a little shorter than the previous one. What is natural - to create a masterpiece in the form of a blank page is much more difficult than to prepare a form for entering and displaying places of circus performances.



Remember that we have already saved one object of the "Place View" class in the database? Let's take it to display. To do this, we need a ZEN component with the name "tablePane":







Hereinafter, I will place the source code, which can be downloaded to the Studio from the "Tools" menu - "Import Locally".



Source: places1.xml Let's compile



and see what happened:







With the problem layout, but this is a fixable matter. The main thing is that we have learned to display data. Now let's record them from the user interface.About the implementation of the MVC pattern(model - view - controller) a lot has been written in the ZEN documentation, but I have not read it and I don’t advise you - I’d better show how it works.



First, you need to inherit our stored class from% ZEN.DataModel.Adaptor:







Source code: one1.xml



And in the interface class, add:

1. Controller

2. A form indicating that our controller deals with its data

3. Event-handling methods (here the method saves data and updates the table)







Source code: places2.xml



In the browser:







Add an entry:







I hope you did it too?



In order for the data of the object to be loaded to the controller when the row of the table is selected, we also need some code. At the same time, add deletion, padding and other amenities.







Source: places3.xml



Looking at my text from the last title, I feel a clear lack of pathos and indiscretion - and in fact we did it - we learned how to work with DBMS data in a super-thin client using AJAX and a lot more. Virtually unaware of this.








Connections





“The secret action of the systems

Hidden under the consciousness of

Ass is connected with the entire

universe of God.”





I.Guberman




Intersystems offers several variants of connections between objects, two of which are alive - the property of the object type and the one-to-many relationship. I implore you with all your experience with Cache '- in no case use the properties-collection of objects, the parent-child relationship and other "one-to-one" implementation. I am personally inclined to refer situations when such a perverse need arises to design flaws. I also feel sorry for the work of those programmers who wrote the implementation of the "parent-descendant", but this work was a waste of calories and budget. Garbage.



The use of one-to-many relationships and properties of objects allows you to easily and universally solve all binding problems in the system. All - take for example our circus.



In the "Places" object of the diagram, we see the type property "Foreign foreign key "(forget about these, if you are going to work with Cache '), named" place_type_code ", referring to the class" Ref_Place_Types ".



" Ref "seems to indicate that we are dealing with a directory, but I am opposed to using the concept “reference book" - if only we are not dealing with a reference book of measures and weights or Bradis tables. Any object that we foolishly called a reference book (reference value table) may at some moment find behavior and the reference book will cease to be new properties and new logic - and limitations Imposed on the so-called "reference" can greatly harm the work.

So just create a class "Place Type Type". I clicked on our place.One in the class hierarchy of the Studio with the right mouse button and selected "Copy", after which I adjusted the class code a little. Likewise, I created an interface for working with types of sites.



Sources: type1.xml , placeTypes1.xml



In the browser, it looks like this:







Now we need to define the Type property in the Presentation Venue class. With a little thought one can come to the conclusion that it is undesirable for us to delete types without hindrance - I would like it to be done when deleting a type whether or not there are places of the type being deleted. Since the logic for this is too lazy to write, and restrictions on the use of relationships are not noticeable, we will describe the relationship as "one-to-many" In the Studio, in the place.One class, right-click on "Add" - "New Property".















* Properties "Places" is not yet in the class place.Type - so I typed it in shape with my hands - Studio will take care of its creation:







After that, in two class descriptions there appeared blocks responsible for the one-to-many relationship:



In place. One:

/// Platform

Type Relationship Type As place.Type [Cardinality = one, Inverse = Places];



Index TypeIndex On Type;




and in place.Type:

Relationship Places As place. One [Cardinality = many, Inverse = Type];




Compile.



In order to organize the input of the "Site Type" field on the interface, use the new zen control (look for the dataCombo after the input fields):



<text label = "Name" dataBinding = "Name" />

<text label = "Description" dataBinding = "Description" />

<text label = "Details" dataBinding = "Details" />

<dataCombo dataBinding = "Type"

sql = "select ID, Description from place.Type"

sqlLookup = "select Description from place.Type where ID =?"

/>




In the sql parameter, we told the control how to offer choices to the user, and in sqlLookup, how to load data from the controller (for example, when selecting a new row in the table).



To display in the table, we will use my favorite feature of the implicit JOIN by means of arrows:



<tablePane id = "placesTable"

tableName = "place.One"

onselectrow = "zenPage.onSelectPlace ()"

valueColumn = "ID"

>

<column colName = "ID" hidden = "true" />

<column header = "Name" colName = "Name" width = "20%" />

<column header = "Description" colName = "Description" width = "30 % "/>

<column header =" Details "colName =" Details "width =" 30% "/>

<column header =" Type "colName =" Type "colExpression =" Type-> Description "/>

</ tablePane>









In the same way, you can quickly create event classes and their types:







Project sources: circus1.xml



The resulting interface looks like this:







The moment came when or you need to honestly stop and think about the next part or postpone - the volume turned out unexpectedly large.



What I wanted to say about Cache ':



We obtained a powerful tool for designing domain objects, their connections and behavior. Do not use the pattern "domain model" when working with Cache 'is at least irrational.



ZEN allows you to quickly move from the design of the database to the implementation of the GUI, which makes it possible to perform hundreds of sketches and prototypes before the appearance of a product that satisfies the customer.



Yesterday's student takes technology in a few days. In two weeks, the code written by him can easily be in production.



Making changes can often not wait for the next release - user requirements can be met within a telephone conversation. Often, the user does not even have to use "F5" to work with the modified code.





What I do not have time to tell:



Storage-level inheritance is a great tool offering various interfaces for accessing the same data.



Implicit JOIN. There is an example in the text (and source code), but of course the power of the tool is not disclosed.





And from the author:



I am not just a convinced lazy, I am a laziness preacher. Lazily made code can be seen immediately - it is brief, understandable, and very effectively does exactly and only what it is intended for. The last factor is important - often the programmer ponders and writes a universal code, the fate of which is to get absolutely nothing in the projected mass of parameters until the end of the system life cycle and return only two values ​​instead of the programmer’s hundreds (worse if the analyst) hundreds. A lazy programmer is also easy to distinguish - he is vivacious and effective. He is aware of social gossip and NoSQL-holivar. He attends theaters and has children. If he is programming, it is only when one cannot do without it.



Some argue that the merit of the Intersystems is small - the main thing is the M-language, global and other pleasures of the wooden architecture (in the first variant I was sealed here by Freud, gaining work). Many of our programmers have been working with Cache for more than a year and don’t know the global team, oh, horror!



The merit of the Intersystems for me is that they made it possible to forget about the "everyday M" - they offered to use it only as a spice adorning the taste of a completely different dish, with which I tried to begin to acquaint you with the recipes.





An important footnote: all of the above is not applicable to the Russian Accounting Standards - the notorious RAS, a disgusting example of how not to organize accounting. I will never write accounting software. I told myself 20 years ago. Sticking to. No in the stall object "wiring"! There is a showcase, the seller, the box office. Up to 22 hours there is an object "alcohol". But the object "wiring" is not there. Is that wiring.





Thanks for attention.



Source: https://habr.com/ru/post/183340/



All Articles