From 6a042b5e881a7f17fd00654183f9a481b2f83c22 Mon Sep 17 00:00:00 2001 From: Kory Draughn Date: Mon, 13 May 2024 21:00:53 -0400 Subject: [PATCH] [442] Add support for GenQuery2 API. --- .../jargon/core/packinstr/Genquery2Input.java | 66 +++++++++++++++++++ .../core/pub/IRODSAccessObjectFactory.java | 8 +++ .../pub/IRODSAccessObjectFactoryImpl.java | 4 ++ .../core/pub/IRODSGenquery2Executor.java | 17 +++++ .../core/pub/IRODSGenquery2ExecutorImpl.java | 61 +++++++++++++++++ 5 files changed, 156 insertions(+) create mode 100644 jargon-core/src/main/java/org/irods/jargon/core/packinstr/Genquery2Input.java create mode 100644 jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSGenquery2Executor.java create mode 100644 jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSGenquery2ExecutorImpl.java diff --git a/jargon-core/src/main/java/org/irods/jargon/core/packinstr/Genquery2Input.java b/jargon-core/src/main/java/org/irods/jargon/core/packinstr/Genquery2Input.java new file mode 100644 index 000000000..6d0ad8168 --- /dev/null +++ b/jargon-core/src/main/java/org/irods/jargon/core/packinstr/Genquery2Input.java @@ -0,0 +1,66 @@ +package org.irods.jargon.core.packinstr; + +import org.irods.jargon.core.exception.JargonException; + +public class Genquery2Input extends AbstractIRODSPackingInstruction { + + public static final String PI_TAG = "Genquery2Input_PI"; + + public static final int GENQUERY2_API_NBR = 10221; + + private String queryString = ""; + private String zone = ""; + private int sqlOnly = 0; + private int columnMappings = 0; + + public static Genquery2Input instance(final String queryString, final String zone) { + Genquery2Input input = new Genquery2Input(); + input.setApiNumber(GENQUERY2_API_NBR); + input.queryString = queryString; + input.zone = zone; + return input; + } + + public static Genquery2Input instanceForSqlOnly(final String queryString, final String zone) { + Genquery2Input input = new Genquery2Input(); + input.setApiNumber(GENQUERY2_API_NBR); + input.queryString = queryString; + input.zone = zone; + input.sqlOnly = 1; + return input; + } + + public static Genquery2Input instanceForColumnMappings() { + Genquery2Input input = new Genquery2Input(); + input.setApiNumber(GENQUERY2_API_NBR); + input.columnMappings = 1; + return input; + } + + public String getQueryString() { + return queryString; + } + + public String getZone() { + return zone; + } + + public int getSqlOnlyValue() { + return sqlOnly; + } + + public int getColumnMappingsValue() { + return columnMappings; + } + + @Override + public Tag getTagValue() throws JargonException { + return new Tag(PI_TAG, new Tag[] { + new Tag("query_string", getQueryString()), + new Tag("zone", getZone()), + new Tag("sql_only", getSqlOnlyValue()), + new Tag("column_mappings", getColumnMappingsValue()) + }); + } + +} diff --git a/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSAccessObjectFactory.java b/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSAccessObjectFactory.java index ded3901aa..79398e1fb 100644 --- a/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSAccessObjectFactory.java +++ b/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSAccessObjectFactory.java @@ -544,5 +544,13 @@ AuthResponse authenticateIRODSAccountUtilizingCachedConnectionIfPresent(IRODSAcc * @throws JargonException {@link JargonExecutor} */ ApiPluginExecutor getApiPluginExecutor(final IRODSAccount irodsAccount) throws JargonException; + + /** + * + * @param irodsAccount + * @return + * @throws JargonException + */ + IRODSGenquery2Executor getIRODSGenquery2Executor(final IRODSAccount irodsAccount) throws JargonException; } diff --git a/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSAccessObjectFactoryImpl.java b/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSAccessObjectFactoryImpl.java index a79e9db19..8550c1344 100644 --- a/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSAccessObjectFactoryImpl.java +++ b/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSAccessObjectFactoryImpl.java @@ -675,5 +675,9 @@ public DiscoveredServerPropertiesCache getDiscoveredServerPropertiesCache() { public boolean isUsingDynamicServerPropertiesCache() { return getIrodsSession().isUsingDynamicServerPropertiesCache(); } + + public IRODSGenquery2Executor getIRODSGenquery2Executor(final IRODSAccount irodsAccount) throws JargonException { + return new IRODSGenquery2ExecutorImpl(irodsSession, irodsAccount); + } } diff --git a/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSGenquery2Executor.java b/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSGenquery2Executor.java new file mode 100644 index 000000000..e7f3a09b6 --- /dev/null +++ b/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSGenquery2Executor.java @@ -0,0 +1,17 @@ +package org.irods.jargon.core.pub; + +import org.irods.jargon.core.exception.JargonException; + +public interface IRODSGenquery2Executor extends IRODSAccessObject { + + String execute(final String queryString) throws JargonException; + + String execute(final String queryString, final String zone) throws JargonException; + + String getGeneratedSQL(final String queryString) throws JargonException; + + String getGeneratedSQL(final String queryString, final String zone) throws JargonException; + + String getColumnMappings() throws JargonException; + +} diff --git a/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSGenquery2ExecutorImpl.java b/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSGenquery2ExecutorImpl.java new file mode 100644 index 000000000..fc3e71588 --- /dev/null +++ b/jargon-core/src/main/java/org/irods/jargon/core/pub/IRODSGenquery2ExecutorImpl.java @@ -0,0 +1,61 @@ +package org.irods.jargon.core.pub; + +import org.irods.jargon.core.connection.IRODSAccount; +import org.irods.jargon.core.connection.IRODSSession; +import org.irods.jargon.core.exception.JargonException; +import org.irods.jargon.core.packinstr.Genquery2Input; +import org.irods.jargon.core.packinstr.Tag; + +public class IRODSGenquery2ExecutorImpl extends IRODSGenericAO implements IRODSGenquery2Executor { + + public IRODSGenquery2ExecutorImpl(IRODSSession irodsSession, IRODSAccount irodsAccount) throws JargonException { + super(irodsSession, irodsAccount); + } + + @Override + public String execute(String queryString) throws JargonException { + return execute(queryString, getIRODSAccount().getZone()); + } + + @Override + public String execute(String queryString, String zone) throws JargonException { + final Genquery2Input input = Genquery2Input.instance(queryString, zone); + final Tag tag = getIRODSProtocol().irodsFunction(input); + + if (null == tag) { + return null; + } + + return tag.getTag("myStr").getStringValue(); + } + + @Override + public String getGeneratedSQL(String queryString) throws JargonException { + return getGeneratedSQL(queryString, getIRODSAccount().getZone()); + } + + @Override + public String getGeneratedSQL(String queryString, String zone) throws JargonException { + final Genquery2Input input = Genquery2Input.instanceForSqlOnly(queryString, zone); + final Tag tag = getIRODSProtocol().irodsFunction(input); + + if (null == tag) { + return null; + } + + return tag.getTag("myStr").getStringValue(); + } + + @Override + public String getColumnMappings() throws JargonException { + final Genquery2Input input = Genquery2Input.instanceForColumnMappings(); + final Tag tag = getIRODSProtocol().irodsFunction(input); + + if (null == tag) { + return null; + } + + return tag.getTag("myStr").getStringValue(); + } + +}