Package com.baasbox.dao

Examples of com.baasbox.dao.ScriptsDao


     *       v
     *  | Uninstall |
     */

    public static ODocument resetStore(String name,JsonNode data) throws ScriptException {
        ScriptsDao dao = ScriptsDao.getInstance();
        ODocument script = dao.getByName(name);
        if (script == null) throw new ScriptException("Script not found");
        ODocument emdedded = new ODocument().fromJSON(data.toString());
        script.field(ScriptsDao.LOCAL_STORAGE,emdedded);
        dao.save(script);
        return emdedded;
    }
View Full Code Here


        dao.save(script);
        return emdedded;
    }

    public static ODocument getStore(String name) throws ScriptException {
        ScriptsDao dao = ScriptsDao.getInstance();
        ODocument script = dao.getByName(name);
        if (script == null) throw new ScriptException("Script not found");
        return script.<ODocument>field(ScriptsDao.LOCAL_STORAGE);
    }
View Full Code Here

        if (script == null) throw new ScriptException("Script not found");
        return script.<ODocument>field(ScriptsDao.LOCAL_STORAGE);
    }

    private static ODocument updateStorageLocked(String name,boolean before,JsonCallback updaterFn) throws ScriptException {
        final ScriptsDao dao = ScriptsDao.getInstance();
        ODocument script = null;
        try {
            script = dao.getByNameLocked(name);
            if (script == null) throw new ScriptException("Script not found");
            ODocument retScript = before ? script.copy() : script;

            ODocument storage = script.<ODocument>field(ScriptsDao.LOCAL_STORAGE);

            Optional<ODocument> storage1 = Optional.ofNullable(storage);

            JsonNode current = storage1.map(ODocument::toJSON)
                    .map(Json.mapper()::readTreeOrMissing)
                    .orElse(NullNode.getInstance());
            if (current.isMissingNode()) throw new ScriptEvalException("Error reading local storage as json");

            JsonNode updated = updaterFn.call(current);

            ODocument result = new ODocument().fromJSON(updated.toString());
            script.field(ScriptsDao.LOCAL_STORAGE, result);
            dao.save(script);
            ODocument field = retScript.field(ScriptsDao.LOCAL_STORAGE);
            return field;
        } finally {
            if (script != null) {
                script.unlock();
View Full Code Here

        return updateStorageLocked(name,true,updater);
    }


    public static List<ODocument> list(QueryParams paramsFromQueryString) throws SqlInjectionException {
        ScriptsDao dao = ScriptsDao.getInstance();
        List<ODocument> scripts = dao.getAll(paramsFromQueryString);
        return scripts;
    }
View Full Code Here

        String source = codeNode.asText();
        return update(name,source);
    }

    public static ScriptStatus update(String name,String code) throws ScriptException {
        ScriptsDao dao = ScriptsDao.getInstance();
        updateCacheVersion();
        ODocument updated = dao.update(name,code);
        compile(updated);

        ScriptStatus status;
        ScriptCall install = ScriptCall.install(updated);
        try {
            ScriptResult result = invoke(install);
            status = result.toScriptStatus();
            if (!status.ok){
                updateCacheVersion();
                dao.revertToLastVersion(updated);

            }
        } catch (ScriptEvalException e){
            if (Logger.isDebugEnabled()) Logger.debug("Script installation failed: deleting");
            updateCacheVersion();
            dao.invalidate(updated);
            dao.revertToLastVersion(updated);
            throw e;
        }
        return status;
    }
View Full Code Here

     */
    public static ScriptStatus create(JsonNode script) throws ScriptException {
        if (Logger.isTraceEnabled()) Logger.trace("Method start");

        if (Logger.isDebugEnabled()) Logger.debug("Creating script");
        ScriptsDao dao = ScriptsDao.getInstance();

        ODocument doc = createScript(dao,script);
        compile(doc);
        if (Logger.isDebugEnabled())Logger.debug("Script created");

View Full Code Here

     * Returns a script object corresponding to name
     * @param name
     * @return
     */
    public static ODocument get(String name) {
        ScriptsDao dao = ScriptsDao.getInstance();
        ODocument script = dao.getByName(name);
        return script;
    }
View Full Code Here

        ODocument script = dao.getByName(name);
        return script;
    }

    public static ODocument get(String name,boolean onlyvalid,boolean active) throws ScriptException {
        ScriptsDao dao = ScriptsDao.getInstance();
        ODocument script = dao.getByName(name);
        if (script != null){
            if (onlyvalid && script.<Boolean>field(ScriptsDao.INVALID)){
                throw new ScriptException("Script is in invalid state");
            }
            if (active && !(script.<Boolean>field(ScriptsDao.ACTIVE))){
View Full Code Here

     * @param name
     * @return
     */
    public static boolean delete(String name) throws ScriptException{
        updateCacheVersion();
        ScriptsDao dao = ScriptsDao.getInstance();
        ODocument script = dao.getByName(name);
        //script not found
        if (script == null){
            return false;
        }

        ScriptCall uninstall = ScriptCall.uninstall(script);
        try {
            invoke(uninstall);
            return dao.delete(name);
        } catch (ScriptException e){
            dao.invalidate(script);
            throw  e;
        }
    }
View Full Code Here

        }
    }

    public static boolean forceDelete(String name) throws ScriptException {
        updateCacheVersion();
        ScriptsDao dao = ScriptsDao.getInstance();
        return dao.delete(name);
    }
View Full Code Here

TOP

Related Classes of com.baasbox.dao.ScriptsDao

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.