Search in sources :

Example 6 with KvPair

use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.

the class QueueOps method onReceiveTask.

public void onReceiveTask(String task) {
    LOGGER.debug("Received Task: " + task);
    String[] parts = task.split("::");
    if (parts.length < 3) {
        LOGGER.error("invalid task format");
        return;
    }
    String action = parts[0];
    String hashKey = parts[1];
    int index = hashKey.indexOf(":");
    if (index < 0) {
        LOGGER.error("invalid event format, failed to figure out type and key");
        return;
    }
    String type = hashKey.substring(0, index);
    String key = hashKey.substring(index + 1);
    String traceId = parts[2];
    Context context = new Context(traceId);
    if (enableMonitor)
        context.enableMonitor(task, "queue", action);
    KvPair pair = new KvPair(key, type);
    KvPairs pairs = new KvPairs(pair);
    AnyKey anyKey = new AnyKey();
    if (!AppCtx.getKeyInfoRepo().find(context, pairs, anyKey)) {
        String msg = "keyInfo not found";
        LOGGER.error(msg);
        context.logTraceMessage(msg);
        return;
    }
    KeyInfo keyInfo = anyKey.getKeyInfo();
    // ...
    String msg = "unknown task action:" + action;
    LOGGER.error(msg);
    context.logTraceMessage(msg);
    context.closeMonitor();
}
Also used : Context(doitincloud.rdbcache.supports.Context) AnyKey(doitincloud.rdbcache.supports.AnyKey) KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo) KvPairs(doitincloud.rdbcache.supports.KvPairs)

Example 7 with KvPair

use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.

the class AbsDbaseRepo method insert.

@Override
public boolean insert(final Context context, final KvPairs pairs, final AnyKey anyKey) {
    boolean allOk = true;
    for (int i = 0; i < pairs.size(); i++) {
        KvPair pair = pairs.get(i);
        KeyInfo keyInfo = anyKey.getAny(i);
        if (!insert(context, pair, keyInfo)) {
            allOk = false;
        }
    }
    return allOk;
}
Also used : KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo)

Example 8 with KvPair

use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.

the class AbsDbaseRepo method save.

@Override
public boolean save(final Context context, final KvPairs pairs, final AnyKey anyKey) {
    boolean allOk = true;
    for (int i = 0; i < pairs.size(); i++) {
        KvPair pair = pairs.get(i);
        KeyInfo keyInfo = anyKey.getAny(i);
        if (!save(context, pair, keyInfo)) {
            allOk = false;
        }
    }
    return allOk;
}
Also used : KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo)

Example 9 with KvPair

use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.

the class AbsDbaseRepo method find.

@Override
public boolean find(final Context context, final KvPairs pairs, final AnyKey anyKey) {
    boolean allOk = true;
    for (int i = 0; i < pairs.size(); i++) {
        KvPair pair = pairs.get(i);
        KeyInfo keyInfo = anyKey.getAny(i);
        if (!find(context, pair, keyInfo)) {
            allOk = false;
        }
    }
    return allOk;
}
Also used : KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo)

Example 10 with KvPair

use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.

the class SimpleKeyInfoRepo method find.

@Override
public boolean find(Context context, KvPairs pairs, AnyKey anyKey) {
    LOGGER.trace("find pairs(" + pairs.size() + ") anyKey(" + anyKey.size() + ")");
    boolean foundAll = true;
    for (int i = 0; i < pairs.size(); i++) {
        KvPair pair = pairs.get(i);
        KeyInfo keyInfo = anyKey.getAny(i);
        String key = pair.getId();
        Map<String, Object> map = (Map<String, Object>) data.get(key);
        if (map == null) {
            foundAll = false;
            LOGGER.trace("find: Not Found " + key);
            continue;
        } else {
            keyInfo = Utils.toPojo(map, KeyInfo.class);
            anyKey.set(i, keyInfo);
            LOGGER.trace("find: Found " + key);
        }
    }
    return foundAll;
}
Also used : KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

KvPair (doitincloud.rdbcache.models.KvPair)51 KeyInfo (doitincloud.rdbcache.models.KeyInfo)29 KvPairs (doitincloud.rdbcache.supports.KvPairs)22 Context (doitincloud.rdbcache.supports.Context)15 Test (org.junit.Test)15 AnyKey (doitincloud.rdbcache.supports.AnyKey)14 StopWatch (doitincloud.rdbcache.models.StopWatch)13 ServerErrorException (doitincloud.commons.exceptions.ServerErrorException)9 BadRequestException (doitincloud.commons.exceptions.BadRequestException)7 KvIdType (doitincloud.rdbcache.models.KvIdType)6 SQLException (java.sql.SQLException)4 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)2 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)2 NotFoundException (doitincloud.commons.exceptions.NotFoundException)1