All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nustaq.kontraktor.frontend.UpdateMixin Maven / Gradle / Ivy

There is a newer version: 5.2.0
Show newest version
package org.nustaq.kontraktor.frontend;

import org.nustaq.kontraktor.Actors;
import org.nustaq.kontraktor.IPromise;
import org.nustaq.reallive.api.RealLiveTable;

public interface UpdateMixin {

    RealLiveTable getTable(String name);

    /**
     * update or add
     * @param table
     * @param key
     * @param keyVals
     */
    default IPromise updateRec(String table, String key, Object[] keyVals) {
        if ( keyVals.getClass() != Object[].class ) {
            Object tmp[] = new Object[keyVals.length];
            for (int i = 0; i < tmp.length; i++) {
                tmp[i] = keyVals[i];
            }
            keyVals = tmp;
        }
        RealLiveTable tab = getTable(table);
        if ( tab == null )
            return Actors.reject("table not found "+table);
        tab.update( key,keyVals);
        return Actors.resolve();
    }

    default IPromise removeRec(String table, String key) {
        RealLiveTable tab = getTable(table);
        if ( tab == null )
            return Actors.reject("table not found "+table);
        tab.remove( key);
        return Actors.resolve();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy