Logo

dev-resources.site

for different kinds of informations.

Tutorial - Develop IRIS using SSH

Published at
4/16/2023
Categories
java
beginners
tutorial
jdbc
Author
intersystemsdev
Categories
4 categories in total
java
open
beginners
open
tutorial
open
jdbc
open
Author
15 person written this
intersystemsdev
open
Tutorial - Develop IRIS using SSH

SSH framework is a relatively representative framework of Java, which was popular many years ago. There are Struts+Spring+hibernate and Spring MVC+Spring+hibernate. Of course, I used the second one in college. If I can connect IRIS to Hibernate as a library, does it also mean that IRIS can be developed using SSH framework in theory?

Tools and environment

JDK 1.8

Maven

Hibernate 5.X.X

IRISHealth-2022.1.3

intellij idea

Windows 10 64

Create database

Create several tables in code mode

Class BKIP.SOA.MonitorScreen.CacheTable.logError Extends %Persistent
{
/// Service Overview Cache Table
Property SucNum As %String(MAXLEN = "");
Property failNum As %String(MAXLEN = "");
Property fdateTime As %String(MAXLEN = "");
}
Enter fullscreen mode Exit fullscreen mode

As shown in the figure:

Image description

Create a Spring project

The next step is to use IDEA to create the mapping of the library and create the entity class

File—New—Project....

Image description

Image description

Name the project and select the jdk version,Click "Next"

Image description

Image description

Image description

Wait for maven to finish creating the project,As shown in the figure

Image description

Add required packages

Image description

<!--Introduce hibernate package-->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.9.Final</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.1.2</version>
        </dependency>
Enter fullscreen mode Exit fullscreen mode

File—Project Structure...

Image description

Select Facets - add Hibernate

Image description

Image description

Add the configuration file as shown in the figure

Image description

Image description

Image description

Image description

Jdbc package introducing iris

Image description

Image description

Image description

Image description

Image description

Image description

Enter connection information in Hibernate configuration

Image description

IDEA's database management tool connects to IRIS

Image description

Introduction of drive package

Image description

Image description

Image description

Connect to IRIS database

Image description

Image description

Select the required database

Image description

Open Hibernate tool, View -- Persistence

Image description

Open the mapping, as shown:

Image description

Select Connect and enter the registration. Because the computer display is incomplete, select all.

Image description

Next, click OK until you succeed:

Image description

You get a bunch of entity classes:

Image description

Now that the entity class has been created, the rest of the logic of creating a session factory to add, delete, and check is not shown here. Share a tool class I used for reference only

package com.example.hibernate.utils;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

/**
 * <p>
 * Hibernate Tools
 * </p>
 *
 * @author wangzhe
 * @since 2017/3/9 14:42
 */
public class HibernateUtil {

   private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
   private static SessionFactory sessionFactory = null;

   static {
      try {
         Configuration cfg = new Configuration().configure();
         ServiceRegistry serviceRegistry = cfg.getStandardServiceRegistryBuilder().build();
         sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
      } catch (Exception e) {
         System.err.println("Failed to create session factory");
         e.printStackTrace();
      }
   }

   /**
    * Get Session
    *
    * @return Session
    * @throws HibernateException
    */
   public static Session getSession() throws HibernateException {
      Session session = (Session) threadLocal.get();
      if (session == null || !session.isOpen()) {
         if (sessionFactory == null) {
            rebuildSessionFactory();
         }
         session = (sessionFactory != null) ? sessionFactory.openSession() : null;
         threadLocal.set(session);
      }

      return session;
   }

   /**
    * Rebuild session factory
    */
   public static void rebuildSessionFactory() {
      try {
         Configuration cfg = new Configuration().configure();
         ServiceRegistry serviceRegistry = cfg.getStandardServiceRegistryBuilder().build();
         sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
      } catch (Exception e) {
         System.err.println("Failed to create session factory");
         e.printStackTrace();
      }
   }

   /**
    * Get SessionFactory object
    *
    * @return SessionFactory object
    */
   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }

   /**
    * Close Session
    *
    * @throws HibernateException
    */
   public static void closeSession() throws HibernateException {
      Session session = (Session) threadLocal.get();
      threadLocal.set(null);
      if (session != null) {
         session.close();
      }
   }
}
Enter fullscreen mode Exit fullscreen mode

Conclusion:

The above is a step that I showed how to build an environment and continue to develop IRIS as a data source in combination with the SSH framework. Although the content shown is relatively simple, if I follow this way, in theory, I can use Java to develop and use IRIS, and I can use a series of native Java methods to make it more convenient for Java developers to use the powerful performance of IRIS and complete more businesses, At the same time, if you want to use SpringBoot or even SpringCloud to develop IRIS, it is not impossible. The key is the role of IRIS in this architecture.

jdbc Article's
30 articles in total
Favicon
Simplify Python-Informix Connections with wbjdbc
Favicon
🚀 Mastering JDBC: Bridging Java and Databases Seamlessly 📊
Favicon
LIBRARY MANAGEMENT SYSTEM USING JAVA AND SQL
Favicon
Java JDBC + IntelliJ + SQLite - A Beginner's Walkthrough
Favicon
Java Backend Management Project
Favicon
JDBC and Streams have never been simpler
Favicon
Quick tip: Using SingleStore for Iceberg Catalog Storage
Favicon
Introducing Kuery Client for those who love writing SQL in Kotlin/JVM
Favicon
Performance tests IRIS - PostgreSQL - MySQL
Favicon
Mastering Conversations: A Guide to Building and Using a Java-Based Chat (StarChat) with IRIS Cloud SQL.
Favicon
Understanding JDBC Three-Tier Architecture: A Detailed Overview
Favicon
Spring Boot Security with JDBC Authentication
Favicon
Wednesday Links - Edition 2024-01-10
Favicon
Constant Lag in CDC Pipeline (JDBC Sink Connector)
Favicon
How to Connect Java Applications to Databases with JDBC
Favicon
Wednesday Links - Edition 2023-08-30
Favicon
How JDBC Paved the Way for Java Frameworks! 🛤️
Favicon
Connect to JDBC in java using MySQL
Favicon
JDBC program for Delete operation
Favicon
Spring JDBC 6 CRUD Operations
Favicon
Java JDBC CRUD Operations in Eclipse using MySql
Favicon
Tutorial - Develop IRIS using SSH
Favicon
Spark Update Optimizations
Favicon
Tips and tricks of the brand new LOAD DATA command
Favicon
Configure the SQuirreL SQL Client to use the SingleStore JDBC Driver
Favicon
Mapping with SCHEMA
Favicon
Built in multi model integration using InterSystems iris data platform
Favicon
Use JDBC to connect TiDB Cloud through TLS
Favicon
Connect your Java application with any SQL databases
Favicon
Java and MySQL

Featured ones: