Search in sources :

Example 1 with AbstractSqlService

use of org.eclipse.scout.rt.server.jdbc.AbstractSqlService in project scout.rt by eclipse.

the class StatementProcessorTest method testLookupCall.

@Test
public void testLookupCall() throws Exception {
    LookupCall call = new LookupCall() {

        private static final long serialVersionUID = 1L;
    };
    // 
    AbstractSqlService sqlService = new AbstractSqlService() {
    };
    BeanInstanceUtil.initializeBeanInstance(sqlService);
    StatementProcessor sp = new StatementProcessor(sqlService, "SELECT P.PERSON_NR,P.NAME" + " FROM PERSON P " + " WHERE P.PERSON_NR=:key " + " AND P.NAME like '%'||:text||'%'", new Object[] { call });
    sp.simulate();
    String sqlPlainTextDump = sp.createSqlDump(false, true);
    assertFalse(sqlPlainTextDump.contains("UNPARSED"));
}
Also used : LookupCall(org.eclipse.scout.rt.shared.services.lookup.LookupCall) AbstractSqlService(org.eclipse.scout.rt.server.jdbc.AbstractSqlService) Test(org.junit.Test)

Example 2 with AbstractSqlService

use of org.eclipse.scout.rt.server.jdbc.AbstractSqlService in project scout.rt by eclipse.

the class StatementProcessorTest method testIgnoreInvalidDuplicateBinds.

@Test
public void testIgnoreInvalidDuplicateBinds() {
    AbstractSqlService sqlService = new AbstractSqlService() {
    };
    BeanInstanceUtil.initializeBeanInstance(sqlService);
    // The abstract server session contains active but without a setter and is thus not a valid bind
    // In this test, the NVPair active should be used and there should be no exception throw
    StatementProcessor sp = new StatementProcessor(sqlService, "SELECT 1 FROM DUAL INTO :active ", new Object[] { new Session(), new NVPair("active", new IntegerHolder()) });
    sp.simulate();
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder) AbstractSqlService(org.eclipse.scout.rt.server.jdbc.AbstractSqlService) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) RunWithServerSession(org.eclipse.scout.rt.testing.server.runner.RunWithServerSession) TestJdbcServerSession(org.eclipse.scout.rt.server.TestJdbcServerSession) AbstractServerSession(org.eclipse.scout.rt.server.AbstractServerSession) Test(org.junit.Test)

Example 3 with AbstractSqlService

use of org.eclipse.scout.rt.server.jdbc.AbstractSqlService in project scout.rt by eclipse.

the class FunctionInput method produceSqlBindAndSetReplaceToken.

@Override
public SqlBind produceSqlBindAndSetReplaceToken(ISqlStyle sqlStyle) {
    if (isBatch() || !m_valueSet) {
        if (m_callerService instanceof AbstractSqlService) {
            m_value = ((AbstractSqlService) m_callerService).callbackCustomBindFunction(m_target.getName(), m_target.getArgs(), m_bindBases);
        } else {
            throw new ProcessingException("don't know how to resolve custom bind function '" + m_target.getName() + "' on service " + m_callerService.getClass().getName());
        }
        m_valueSet = true;
    }
    Object value = null;
    if (isBatch() && m_batchIndex >= 1) {
        value = null;
    } else {
        value = m_value;
    }
    Class<?> nullType = null;
    if (value instanceof IHolder<?>) {
        IHolder h = (IHolder<?>) value;
        value = h.getValue();
        nullType = h.getHolderType();
    }
    // 
    if (m_target.isPlainToken()) {
        m_target.setReplaceToken(m_target.getParsedToken());
        return null;
    } else if (m_target.isPlainValue()) {
        m_target.setReplaceToken(sqlStyle.toPlainText(value));
        return null;
    } else if (m_target.isPlainSql()) {
        m_target.setReplaceToken("" + value);
        return null;
    } else {
        m_target.setReplaceToken("?");
        return sqlStyle.buildBindFor(value, nullType);
    }
}
Also used : IHolder(org.eclipse.scout.rt.platform.holders.IHolder) AbstractSqlService(org.eclipse.scout.rt.server.jdbc.AbstractSqlService) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 4 with AbstractSqlService

use of org.eclipse.scout.rt.server.jdbc.AbstractSqlService in project scout.rt by eclipse.

the class StatementProcessorTest method exec.

private String[] exec(final boolean checkForDuplicateBinds, final String statement, final Object... binds) {
    final Collection<String> duplicates = new ArrayList<>();
    final AbstractSqlService sqlService = new AbstractSqlService() {
    };
    new StatementProcessor(sqlService, statement, binds) {

        @Override
        protected boolean isBindDuplicateCheckEnabled() {
            return checkForDuplicateBinds;
        }

        @Override
        protected void onDuplicateBind(IToken token) {
            if (token instanceof ValueInputToken) {
                duplicates.add(((ValueInputToken) token).getName());
            } else if (token instanceof ValueOutputToken) {
                duplicates.add(((ValueOutputToken) token).getName());
            } else {
                throw new ProcessingException("Unexpected token: {}", token);
            }
        }
    }.simulate();
    return duplicates.toArray(new String[duplicates.size()]);
}
Also used : ValueOutputToken(org.eclipse.scout.rt.server.jdbc.parsers.token.ValueOutputToken) IToken(org.eclipse.scout.rt.server.jdbc.parsers.token.IToken) ArrayList(java.util.ArrayList) AbstractSqlService(org.eclipse.scout.rt.server.jdbc.AbstractSqlService) ValueInputToken(org.eclipse.scout.rt.server.jdbc.parsers.token.ValueInputToken) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 5 with AbstractSqlService

use of org.eclipse.scout.rt.server.jdbc.AbstractSqlService in project scout.rt by eclipse.

the class StatementProcessorTest method testSelectLike.

@Test
public void testSelectLike() throws Exception {
    AbstractSqlService sqlService = new AbstractSqlService() {
    };
    BeanInstanceUtil.initializeBeanInstance(sqlService);
    StatementProcessor sp = new StatementProcessor(sqlService, "SELECT BP_NR FROM FLM_BP WHERE BP_NO LIKE :bpNo INTO :bpNr", new Object[] { new NVPair("bpNo", "12"), new NVPair("bpNr", new LongHolder()) });
    sp.simulate();
    String sqlPlainTextDump = sp.createSqlDump(false, true);
    assertFalse(sqlPlainTextDump.contains("UNPARSED"));
}
Also used : LongHolder(org.eclipse.scout.rt.platform.holders.LongHolder) AbstractSqlService(org.eclipse.scout.rt.server.jdbc.AbstractSqlService) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) Test(org.junit.Test)

Aggregations

AbstractSqlService (org.eclipse.scout.rt.server.jdbc.AbstractSqlService)6 Test (org.junit.Test)4 NVPair (org.eclipse.scout.rt.platform.holders.NVPair)3 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)2 IntegerHolder (org.eclipse.scout.rt.platform.holders.IntegerHolder)2 ArrayList (java.util.ArrayList)1 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)1 LongHolder (org.eclipse.scout.rt.platform.holders.LongHolder)1 AbstractServerSession (org.eclipse.scout.rt.server.AbstractServerSession)1 TestJdbcServerSession (org.eclipse.scout.rt.server.TestJdbcServerSession)1 IToken (org.eclipse.scout.rt.server.jdbc.parsers.token.IToken)1 ValueInputToken (org.eclipse.scout.rt.server.jdbc.parsers.token.ValueInputToken)1 ValueOutputToken (org.eclipse.scout.rt.server.jdbc.parsers.token.ValueOutputToken)1 LookupCall (org.eclipse.scout.rt.shared.services.lookup.LookupCall)1 RunWithServerSession (org.eclipse.scout.rt.testing.server.runner.RunWithServerSession)1