Skip to content

Commit

Permalink
[442] Add support for GenQuery2 API.
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn committed May 14, 2024
1 parent ae2c8e9 commit 6a042b5
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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())
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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();
}

}

0 comments on commit 6a042b5

Please sign in to comment.