# HG changeset patch
# User Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
# Date 1619796196 -7200
# Node ID 0e21097f438b5f8510e3a5544e99803eb6ce5d26
# Parent  e14e81b8044eab80a7d02b4135de5078b86a5825
Reduce the number of MonetDatabaseMetaData objects created via getMetaData() to maximum 1 per connection as it can be reused.

diff --git a/src/main/java/org/monetdb/jdbc/MonetConnection.java b/src/main/java/org/monetdb/jdbc/MonetConnection.java
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java
@@ -147,6 +147,9 @@ public class MonetConnection
 	/** The last set query timeout on the server as used by Statement, PreparedStatement and CallableStatement */
 	protected int lastSetQueryTimeout;	// 0 means no timeout, which is the default on the server
 
+	/** A cache to reduce the number of DatabaseMetaData objects created by getMetaData() to maximum 1 per connection */
+	private DatabaseMetaData dbmd;
+
 
 	/**
 	 * Constructor of a Connection for MonetDB. At this moment the
@@ -586,10 +589,14 @@ public class MonetConnection
 	 */
 	@Override
 	public DatabaseMetaData getMetaData() throws SQLException {
+		// for debug: System.out.println("calling getMetaData()");
 		if (lang != LANG_SQL)
 			throw new SQLException("This method is only supported in SQL mode", "M0M04");
-
-		return new MonetDatabaseMetaData(this);
+		if (dbmd == null) {
+			// first use, construct it once and reuse it for all next calls
+			dbmd = new MonetDatabaseMetaData(this);
+		}
+		return dbmd;
 	}
 
 	/**