Getting Started Use Any Data Model Multi-Model QuickStart

Multi-Model QuickStart

15 minutes

InterSystems IRIS® data platform provides a multi-model architecture that allows you to use the data model that best fits each task in your application — relational, object, or even direct/native access — all accessible through the language of your choice.

Multi-model features available in InterSystems IRIS include:

  • Industry-standard APIs for SQL and object access
  • An API to store data in a custom optimized data structure
  • A reusable database connection that supports using the best data model for each task
  • APIs for your language of choice (including Java, .NET, Python, and ObjectScript)
  • An underlying consistent structure avoiding data duplication

Watch the short video above, then launch the online sandbox below. You can try the exercise below using one of the languages listed.

Sandbox Set up



Make sure you have an instance of InterSystems IRIS and a multi-language IDE ready to go. Sandbox settings will appear below after you log in and launch a sandbox.

If you don’t have InterSystems IRIS yet, get a free, online development sandbox here. Log in with your InterSystems universal account, or register for one below.

Choose your language

This exercise is available in four languages:


Try it: Java

With Java, you can interact with InterSystems IRIS relationally (with JDBC), using objects (with XEP or Hibernate), or natively (with the Native API). For this exercise, use the lab launcher to run the code. In the steps below, you will create a set of airport data as objects, retrieve that data via SQL, and then natively access custom data structures to store route information.

Set up

  1. First, make sure you created your free online sandbox at the beginning of this exercise.
  2. Clone the quickstarts-multimodel-java repo into the /home/project directory in the cloud IDE whose settings are above. Open the IDE . Then in the IDE’s terminal window:
    cd /home/project
    git clone -b try-iris http://github.com/intersystems/quickstarts-multimodel-java
    
  3. You should now have three new classes inside quickstart-multimodel-java/src: Demo.Airport.java, Demo.Location.java, and multimodelQS.java.
  4. Correct the credentials. Using the Explorer pane (the file browser encompassing the left side of the IDE), open the quickstarts-multimodel-java folder, and then the src folder. Then open the multimodelQS.java file and on line 31 change the value of IP to (provision a sandbox to get this setting) and on line 32, change the value of port to (provision a sandbox to get this setting).

Use objects and SQL side by side

  1. Run multimodelQS.java to execute the populateAirports() and getAirports() methods.
    cd /home/project/quickstarts-multimodel-java/src
    javac -cp ".:../lib/intersystems-jdbc-3.2.0.jar:../lib/intersystems-xep-3.2.0.jar" multimodelQS.java
    java -cp ".:../lib/intersystems-xep-3.2.0.jar:../lib/intersystems-jdbc-3.2.0.jar" multimodelQS
    
  2. Inspect the output and code. The first method — populateAirports() — populates five objects and saves them to the database, while the second method — getAirports() — runs an SQL query and returns all airports, printing them to the screen. Using InterSystems IRIS, you can interact with data using either objects or SQL based on the task, optimizing both developer time and application performance.
  3. If all works correctly, you will see a list of airports output. Data is stored using XEP (objects) and retrieved using JDBC (relationally).

Create a custom data structure, optimizing development time and performance

In the case where you need to answer a question you did not expect when you built the database, refactoring a relational-only database could be expensive and complicated. With InterSystems IRIS, you may choose to natively store data in a custom data structure, allowing you to modify the structure to fit your specific data and easily handle new data that was not part of your initial schema or class design.

  1. Two other methods — storeAirfare() and checkAirfare() — have been created to store route information to InterSystems IRIS and print if a particular route exists.
  2. Find and uncomment the following lines, then save the file:
    // storeAirfare(irisNative); 
    // checkAirfare(irisNative);
    
  3. Compile and run multimodelQS.java again.
  4. Enter departure airport: BOS
  5. Enter destination airport: AUS
    The output should say:

    Printed to ^airport global. The distance in miles between BOS and AUS is: 1698.
    The following routes exist for this path:
    -AA150: 450 USD
    -AA290: 550 USD

    Other routes may be null.


Try it: .NET

With .NET, you can interact with InterSystems IRIS relationally (with ADO.NET or ODBC), using objects (with XEP or Entity Framework), or natively (with the Native API). In the steps below, you will create a set of airport data as objects, retrieve that data via SQL, and then natively access custom data structures to store route information.

Set up

  1. First, make sure you created your free online sandbox at the beginning of this exercise.
  2. Clone the quickstarts-multimodel-dotnet repo into the /home/project directory in the cloud IDE whose settings are above. Open the IDE . Then in the IDE’s terminal window:
    cd /home/project
    git clone -b try-iris http://github.com/intersystems/quickstarts-multimodel-dotnet
    
  3. You should now have three new classes inside quickstart-multimodel-dotnet: Demo.Airport.cs, Demo.Location.cs, and MultiModelQS.cs.
  4. Correct the credentials. Using the Explorer pane (the file browser encompassing the left side of the IDE), open the quickstarts-multimodel-dotnet folder. Then open the MultiModelQS.cs file and on line 20 change the value of ip to (provision a sandbox to get this setting) and on line 21, change the value of port to (provision a sandbox to get this setting).

Use objects and SQL side by side

  1. Run MultiModelQS.cs to execute the populateAirports() and getAirports() methods.
    cd /home/project/quickstarts-multimodel-dotnet
    dotnet run
    
  2. Inspect the output and code. The first method — populateAirports() — populates five objects and saves them to the database, while the second method — getAirports() — runs an SQL query and returns all airports, printing them to the screen. Using InterSystems IRIS, you can interact with data using either objects or SQL based on the task, optimizing both developer time and application performance.
  3. If all works correctly, you will see a list of airports output. Data is stored using XEP (objects) and retrieved using ADO.NET (relationally).

Create a custom data structure, optimizing development time and performance

In the case where you need to answer a question you did not expect when you built the database, refactoring a relational-only database could be expensive and complicated. With InterSystems IRIS, you may choose to natively store data in a custom data structure, allowing you to modify the structure to fit your specific data and easily handle new data that was not part of your initial schema or class design.

  1. Two other methods — storeAirfare() and checkAirfare() — have been created to store route information to InterSystems IRIS and print if a particular route exists.
  2. Find and uncomment the following lines, then save the file:
    // storeAirfare(irisNative); 
    // checkAirfare(irisNative);
    
  3. Run MultimodelQS.cs again.
  4. Enter departure airport: BOS
  5. Enter destination airport: AUS
    The output should say:

    Printed to ^airport global. The distance in miles between BOS and AUS is: 1698.
    The following routes exist for this path:
    -AA150: 450 USD
    -AA290: 550 USD

    Other routes may be null.


Try it: Python

With Python, you can interact with InterSystems IRIS relationally (with PyODBC) or natively (with the Native API). In the steps below, you will create a set of airport data and retrieve that data via SQL, and then natively access custom data structures to store route information.

Set up

  1. First, make sure you created your free online sandbox at the beginning of this exercise.
  2. Clone the quickstarts-multimodel-python repo into the /home/project directory in the cloud IDE whose settings are above. Open the IDE . Then in the IDE’s terminal window:
    cd /home/project
    git clone -b try-iris http://github.com/intersystems/quickstarts-multimodel-python
    
  3. You should now have a Python file inside quickstarts-multimodel-python: multimodelQS.py.
  4. Correct the credentials. Using the Explorer pane (the file browser encompassing the left side of the IDE), open the quickstarts-multimodel-python folder. Then open the multimodelQS.py file and on line 37 change the value of IP to (provision a sandbox to get this setting) and on line 38, change the value of port to (provision a sandbox to get this setting).

Use SQL for CRUD operations: Create, Read, Update, Delete

  1. Install the InterSystems IRIS driver for the Native API and PyODBC.
    cd /home/project/quickstarts-multimodel-python
    pip install nativeAPI_wheel/irisnative-1.0.0-cp34-abi3-linux_x86_64.whl
    sudo odbcinst -i -d -f pyodbc_wheel/odbcinst.ini
    
  2. Run python multimodelQS.py, which executes the populate_airports()and get_airports() methods.
  3. Inspect the output and code. The first method — populate_airports() — populates five objects and saves them to the database, while the second method — get_airports() — runs an SQL query and returns all airports, printing them to the screen.
  4. If all works correctly, you will see a list of airports output. Data is stored and retrieved using PyODBC (relationally).

Create a custom data structure, optimizing development time and performance

In the case where you need to answer a question you did not expect when you built the database, refactoring a relational-only database could be expensive and complicated. With InterSystems IRIS, you may choose to natively store data in a custom data structure, allowing you to modify the structure to fit your specific data and easily handle new data that was not part of your initial schema or class design.

  1. Two functions — store_airfare() and check_airfare() — have been created to store route information to InterSystems IRIS and print if a particular route exists.
  2. Find and uncomment the following lines, then save the file:
    # store_airfare(irisNative, "^airport"); 
    # check_airfare(irisNative, "^airport");
    
  3. Run multimodelQS.py again.
  4. Enter departure airport: BOS
  5. Enter destination airport: AUS
    The output should say:

    Printed to ^airport global. The distance in miles between BOS and AUS is: 1698.
    The following routes exist for this path:
    -AA150: 450 USD
    -AA290: 550 USD

    Other routes may be null.


Try it: InterSystems ObjectScript

With InterSystems ObjectScript, you can interact with InterSystems IRIS relationally, using objects, or natively. In the steps below, you will create a set of airport data as objects, retrieve that data via SQL, and then natively access custom data structures to store route information. 

Set up

  1. First, make sure you created your free online sandbox at the beginning of this exercise.
  2. Clone the quickstarts-multimodel-objectscript repo into the /home/project/shared directory in the cloud IDE whose settings are above. Open the IDE . Then in the IDE’s terminal window:
    cd /home/project/shared
    git clone -b try-iris http://github.com/intersystems/quickstarts-multimodel-objectscript
    
  3. Import the production using the Management Portal. There are two ways to do this. From the Cloud IDE you can use the menu bar. Navigate to InterSystems > Management Portal.
  4. From the Management Portal homepage, switch to the USER namespace, and navigate to System ExplorerClasses.
    Management Portal home page with Switch Namespace functionality highlighted
  5. Click Import and choose /home/project/shared/quickstarts-multimodel-objectscript/Airport.xml as the file to import.
    Import button highlighted on page, with path and file name filled in as described in the step.

Use objects and SQL side-by-side

  1. Open the Cloud IDE and use the menubar to navigate to InterSystems > Web Terminal and run:
    do ##class(Demo.Airport).PopulateAirports()
    do ##class(Demo.Airport).DisplayAirports()
  2. Inspect the output and code. The first method — PopulateAirports() — populates five objects and saves them to the database, while the second method — DisplayAirports() — runs an SQL query and returns all airports, printing them to the screen.
  3. If all works correctly, you will see a list of airports output. Data is stored using objects and retrieved relationally.
  4. If you inspect the code, you will notice that the query uses a special shorthand notation (–>, known as an implicit join) to retrieve data from a related table without requiring you to think about how to join tables. Using InterSystems IRIS, you can interact with data using either objects or SQL based on the task, optimizing both developer time and application performance.

Create a custom data structure, optimizing development time and performance

In the case where you need to answer a question you did not expect when you built the database, refactoring a relational-only database could be expensive and complicated. With InterSystems IRIS, you may choose to natively store data in a custom data structure, allowing you to modify the structure to fit your specific data and easily handle new data that was not part of your initial schema or class design.

  1. Two methods — StoreAirfare() and CheckAirfare() — have been created to store route information to InterSystems IRIS and print if a particular route exists. Run these methods to see this work:
    do ##class(Demo.Airport).StoreAirfare()
    do ##class(Demo.Airport).CheckAirfare("BOS", "AUS")


    The output should say:

    Printed to ^airport global. The distance in miles between BOS and AUS is: 1698.
    The following routes exist for this path:
    -AA150: 450 USD
    -AA290: 550 USD

    Other routes may be null.

Up Next
Using Multi-Model with Python and Node.js
45 minutes