Nouvelle publication

検索

Article
· Déc 12, 2025 2m de lecture

Archivos temporales y Singletons: limpiad lo que generéis.

Hay un patrón con el que me he encontrado varias veces en el que necesito usar un archivo o carpeta temporal y que se limpie en algún momento más adelante.

Lo natural aquí es seguir los patrones de "Robust Error Handling and Cleanup in ObjectScript" usando un try/catch/pseudo-finally o un objeto registrado para gestionar la limpieza en el destructor. %Stream.File* también tiene una propiedad “RemoveOnClose” que podéis activar… pero usadla con cuidado, porque podríais eliminar accidentalmente un archivo importante, y este indicador se reinicia al llamar a %Save(), así que tendréis que volver a ponerlo a 1 después de hacerlo.

Pero hay un caso complicado: imaginad que necesitáis que el archivo temporal sobreviva en un nivel de pila superior. Por ejemplo:

ClassMethod MethodA()
{
    Do ..MethodB(.filename)
    // Do something else with the filename
}

ClassMethod MethodB(Output filename)
{
    // Create a temp file and set filename to the file's name
    Set filename = ##class(%Library.File).TempFilename()
    
    //... and probably do some other stuff
}

Siempre podríais pasar objetos %Stream.File* con RemoveOnClose puesto a 1, pero aquí realmente estamos hablando solo de archivos temporales.

Aquí es donde entra el concepto de “Singleton”. En IPM tenemos una implementación base en %IPM.General.Singleton que podéis extender para cubrir distintos casos de uso. El comportamiento general y el patrón de uso son:

  • En un nivel de pila superior, llamáis a %Get() en esa clase y obtenéis la única instancia, que también será accesible mediante llamadas a %Get() en niveles inferiores.
  • Cuando el objeto sale de ámbito en el nivel de pila más alto que lo usa, se ejecuta el código de limpieza.

Esto es un poco mejor que usar una variable %, porque no necesitáis comprobar si está definida, y además sobrevive a los NEW sin argumentos en los niveles de pila inferiores gracias a cierta magia profunda de objetos.

Pasando a los archivos temporales, IPM también tiene un singleton gestor de archivos temporales. Aplicándolo a este problema, la solución es:

ClassMethod MethodA()
{
    Set tempFileManager = ##class(%IPM.Utils.TempFileManager).%Get()
    Do ..MethodB(.filename)
    // Do something else with the filename
    // The temp file is cleaned up automatically when tempFileManager goes out of scope
}

ClassMethod MethodB(Output filename)
{
    Set tempFileManager = ##class(%IPM.Utils.TempFileManager).%Get()
    // Create a temp file and set filename to the file's name
    Set filename = tempFileManager.GetTempFileName(".md")
    
    //... and probably do some other stuff
}
Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Annonce
· Déc 12, 2025

[Video] SQL Tricks and Tips

Hey Community!

We're happy to share a new video from our InterSystems Developers YouTube:

⏯  SQL Tricks and Tips @ Ready 2025

This presentation introduces two helpful SQL features in InterSystems IRIS: Common Table Expressions (CTEs) and Limit/Offset. CTEs, available since version 24.1, let users simplify complex queries by breaking them into reusable, readable blocks that can be used with SELECT, INSERT, UPDATE, and DELETE statements.
The Limit/Offset feature, added in version 25.1, provides a flexible alternative to the TOP clause, allowing users to limit returned rows and skip specific records, ideal for pagination. Together, these features make queries easier to write, read, and optimize, while the SQL engine automatically handles efficient execution and plan optimization.

Presenters:
🗣 Ismail Ben Atitallah, Principal Systems Developer, InterSystems
🗣 Yiwen Huang, Systems Developer, InterSystems

Enjoy watching, and subscribe for more videos! 👍

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Annonce
· Déc 12, 2025

[Video] Enhancing Customer Engagement with Vector Search - Building a Customer Facing Chatbot

Hey Developers,

Enjoy the new video on InterSystems Developers YouTube

⏯ Enhancing Customer Engagement with Vector Search - Building a Customer Facing Chatbot @ READY 2025

Explore how InterSystems IRIS vector search anchors chatbot capabilities by delivering fast, relevant, and context-aware responses. In this session, we’ll walk through the key benefits and best practices for using vector search in conjunction with your LLM to power your chatbots. You’ll also meet our new chatbot AskMe, available on our documentation and learning sites; it’s designed to help you find answers quickly and navigate content with ease. Whether you’re building AI-driven support or optimizing existing solutions, you’ll leave with actionable insights to improve and enhance self-service experiences.

Presenters:
🗣 @Brenna Quirk, Sr. Technical Online Course Developer at InterSystems
🗣 @Jim Breen, Director of Global Learning at InterSystems
🗣 @Kim Koehler, Manager, Learning Technology at InterSystems 

Enjoy watching, and look forward to more videos!👍

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Annonce
· Déc 12, 2025

InterSystems sera présent au Health&Tech Summit 2025

Salut la communauté,

Rejoignez-nous pour notre présentation lors du Health&Tech Summit 2025 !

📅  Dates : 16 - 17 décembre, 2025

📌 Lieu : Palais du Pharo & AP-HM, Marseille, France

Nous prendrons la parole lors d’une intervention dédiée à l’innovation en santé, autour des enjeux de transformation numérique et des solutions qui accompagnent les professionnels au quotidien.

Réservez la date, préparez vos questions et rejoignez-nous pour des échanges, nous avons hâte de vous rencontrer !

Inscrivez-vous dès maintenant !

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Article
· Déc 12, 2025 3m de lecture

Create Foreign Tables Using SQL via JDBC

Hi everyone. Long time no see. Again, I would like to share what I am studying recently Create Foreign Tables Using SQL via JDBC.

Since I am learning about the IRIS BI at the same time, so I started with this Sample-BI docker environment

https://github.com/intersystems/Samples-BI

 

After starting the environment, login to the management portal http://localhost:52773/csp/sys/UtilHome.csp  with the user Superuser.

Switch the namespace to IRISAPP.

 

😀 We will find out that all the sample data are stored in this namespace IRISAPP. Let's find a simple table for testing the Foreign Table feature 🤣

System Explorer > SQL

 

Let's try the table HoleFoods.Outlet by Executing the following SQL query in the Execute Query tab

SELECT
ID, City, Country, Latitude, Longitude, Population, Type
FROM HoleFoods.Outlet

 

Great!!😉 there are 35 entries in this table. Let's use it.

 


Step1  -  Setup the JDBC connection

By studying the document below, InterSystems IRIS db can be connected by JDBC by the following way

Using the SQL Gateway as a JDBC Data Source

So, let's using the Namespace IRISAPP as the JDBC source database for testing, and set up a connection for it.

Add a new connection by System  > Configuration  > SQL Gateway Connections 

 

Input the following

Connection name  testjdbc
User superuser
Password {you own password}
Driver name com.intersystems.jdbc.IRISDriver
URL  jdbc:IRIS://127.0.0.1:1972/IRISAPP

Leave Class path blank in this case, because is connecting to InterSystems IRIS DB. If connecting to the 3rd party DB, remember to download the JDBC driver file (.jar) and specific the path of the drive in the Class path filed.

 

Save and Test the Connection. Connection successful should be expected. 😁

Yeah!!! we finished the 1st step.

 


Step 2 - Create Foreign Table

Now switch to another Namespace USER, which do no contain the table HoleFoods.Outlet. 😉

Here we would like to query this external table HoleFoods.Outlet by making use the feature of Foreign Table. (In InterSystems IRIS, different Namespace, can be config to point to different DB. In this example, Namespace IRISAPP and Namespace USER are pointing to different DB. As a result, we cannot query the table Namespace IRISAPP from Namespace USER directly. )

 

By studying the document below, we can directly create foreign table by SQL.😁👍

Foreign Tables

So let's go to the SQL execution page again. System Explorer > SQL

 

1. Define a Foreign Server

Now we are going to define a Foreign Server Sample.testDB by the following SQL. testjdbc is the name that we defined in the SQL Gateway JDBC connection in the pervious step.

CREATE FOREIGN SERVER Sample.testDB FOREIGN DATA WRAPPER JDBC CONNECTION 'testjdbc'

 

 

2. Define a Foreign Table

Now we are going to define a Foreign Table demo.outlet, which is pointing to the table HoleFoods.Outlet through the JDBC gateway

 

CREATE FOREIGN TABLE demo.outlet SERVER Sample.testDB TABLE 'HoleFoods.Outlet'

Let's check the result from the table list

Yeah!!!!  A Foreign Table demo.outlet is created. Oooo the schema is read and created automatically btw😂Happy happy.

 


Finally, test the Foreign Table by running the following SQL

SELECT * FROM demo.outlet

 

 

35 Outlets are returned!!! Yeah!! We made it.🤣

 


Only for your reference

Dropping the Foreign Table demo.outlet 

DROP FOREIGN TABLE demo.outlet

 

 

Dropping the  Foreign Server Sample.testDB 

DROP FOREIGN SERVER Sample.testDB CASCADE

 

That's all I want to share!!! Thanks for reading😘

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer