0

I am working on a java application with Spring and JDBC connection. I did not code the application myself and I am kind of new to some of the frameworks and implications of this.

I traced the path of how sql statements are passed, however I am stuck at some point where I do not find any details on the method that is called and the class it belongs to. The method is imported via import de.dit.icr.frontend.ProxyBean;

Basically all queries are contained in a single "query.xml" file, that is passed into a "ProxyBean" object, which is then fed with the parameters map and then a "getStatement()" method is called that returns the prepared query string.

What I would like to do is to split the query.xml file into single sql files (one for each query) and implement a new method instead of the proxyBean.getStatement(), that would still take the parameters map, the name of the query, and prepare the statement.

In order to do that, I require your light on something: - where does this ProxyBean class come from? From an external library, and if so, which one? - Which method, which library could I use to create a string of an sql prepared statement from a sql file and a parameters map?

Thanks a lot for your help!

Here is a simplified view of the code:

import de.dit.icr.frontend.ProxyBean;
import de.dit.icr.util.Url;
import de.dit.itsales.dbi.util.DBUtil;
import de.dit.itsales.dbi.util.Log;

public class IASAdapterImpl implements IASAdapter {
    private static final String[] QUERY_FILES = {"query.xml"};
    private static final String RELATIVE_PATH_TO_QUERY_FILE = "queries";

    public IASAdapterImpl() {
        init();
    }

private void init() {
    String key = "queries";
    String pathToQueryFile = DBUtil.getInstance().getConfigDir() + RELATIVE_PATH_TO_QUERY_FILE;
    Url.register(key, pathToQueryFile);
    createProxyBean();
}

public synchronized String getQuery(String queryName, Map<String,String> queryVariables, boolean resolveNames) {
    ProxyBean proxyBean = createProxyBean();
    setParameter(queryVariables, proxyBean);
    String temp = proxyBean.getStatement(queryName, resolveNames);
    return temp;
}

private ProxyBean createProxyBean() {
    ProxyBean bean = new ProxyBean();
    for (int i = 0; i < QUERY_FILES.length; i++) {
        bean.setQuerySet(QUERY_FILES[i]);
    }
    return bean;
}

private void setParameter(Map<String,String> map, ProxyBean bean) {
    if(map == null || map.isEmpty()) {
        return;
    }
    for (Map.Entry<String,String> entry : map.entrySet()) {
        String key = entry.getKey();
        bean.set(key, entry.getValue());
    }
    }

Sample of query.xml:

<query name = "alle-fonds"><![CDATA[
select fondsnummer,
    spokid,
    mfnummer,
    fondsname,
    bewertungsdatum,
    letztebewertung,
    hauptfonds,
    performancegraphrelevant
from rep.v_alle_fonds where anwender_login = '${loginname}'
    and sprache = lower('${sprache}')
order by mfnummer
]]></query>
zelig
  • 43
  • 7
  • I edited the post and deleted what seemed irrelevant to me. I am prepared to provide the earlier code if required. – zelig Oct 23 '18 at 14:00
  • You dumped a lot of code, but forgot to ask an actual question. If you want someone to rewrite this for you, hire a contractor. Note that this looks like a poor man's Mybatis; you may want to consider rewriting from scratch using Mybatis (or spring-data). – Mark Rotteveel Oct 23 '18 at 14:00
  • look up named parameters, see https://stackoverflow.com/q/16359316/217324. i don't see where splitting these into 1 query per file actually helps you in any way. – Nathan Hughes Oct 23 '18 at 14:11
  • Thank you for your answer Mark, I updated my post with the specific points that would help me. Nathan, splitting the queries is required for further manipulation. Thanks for the link! – zelig Oct 23 '18 at 14:14

0 Answers0