// Path: src/com/govu/Govu.java
// public class Govu {
// 
//     public static String VERSION = "0.0.4";
//     public static String root;
//     public static String dbRoot;
//     public static String webRoot;
//     public static Logger logger;
//     public static int PORT;
//     public static Set<WebApplication> apps = new HashSet<>();
//     public static Config config;
//     private DB db;
// 
//     /**
//      * @param args the command line arguments
//      */
//     public static void main(String[] args) {
//         if (args.length > 0) {
//             String command = args[0].toLowerCase();
//             if (command.equals("deploy")) {
//                 new DeployCommand().process(args);
//             } else if (command.equals("delete")) {
//                 new DeleteCommand().process(args);
//             } else {
//                 System.out.println("Unknown govu command: " + args[0]);
//             }
//         } else {
//             //Start govu web server
//             Govu govu = new Govu();
//         }
//     }
// 
//     public Govu() {
//         logger = Logger.getLogger("govu");
//         root = System.getProperty("user.dir");
//         dbRoot = root + "/db";
//         webRoot = root + "/web";
//         logger.debug("Staring Govu Server " + VERSION + "...");
// 
//         try {
//             config = new Config();
//             config.readProperties();
//         } catch (IOException | InterruptedException ex) {
//             logger.error("Error reading config file", ex);
//         }
// 
// 
//         File webDir = new File(webRoot);
//         if (!webDir.exists()) {
//             logger.debug("Creating web base directory");
//             webDir.mkdir();
//         }
// 
//         File dbDir = new File(dbRoot);
//         if (!dbDir.exists()) {
//             logger.debug("Creating database base directory");
//             dbDir.mkdir();
//         }
// 
//         //Init Database Provider
//         db = new DB(new DB4OProvider());
// 
//         //Init http server
//         ServerBootstrap httpBootStrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
//         httpBootStrap.setOption("child.tcpNoDelay", true);
//         httpBootStrap.setPipelineFactory(new HttpServerPipelineFactory());
//         httpBootStrap.bind(new InetSocketAddress(PORT));
// 
//         logger.debug("Govu started successfully. Happy coding!");
//     }
// 
//     public static WebApplication getWebApp(String host, String path) {
//         for (Iterator<WebApplication> it = apps.iterator(); it.hasNext();) {
//             WebApplication app = it.next();
//             if ((app.getDomain() != null && app.getDomain().equals(host))
//                     || (app.getDomain() == null && path.startsWith(app.getRootPath()))) {
//                 return app;
//             }
//         }
//         return null;
//     }
//     
//     public static WebApplication getWebApp(String name) {
//         for (Iterator<WebApplication> it = apps.iterator(); it.hasNext();) {
//             WebApplication app = it.next();
//             if (app.getName().equals(name)){
//                 return app;
//             }
//         }
//         return null;
//     }
// }
// 
// Path: src/com/govu/engine/db/DatabaseProvider.java
// public interface DatabaseProvider {
// 
//     public void deleteObj(ScriptableObject obj, String type);
// 
//     public void saveObj(ScriptableObject obj, String type);
// 
//     public void delete(ScriptableObject obj, String type);
//     
//     public Scriptable[] getAll(Function function, String type);
// 
//     public Scriptable[] search(ScriptableObject obj, Function function, String type);
// 
//     public Scriptable get(ScriptableObject obj, String type);
//     
// }


import com.govu.Govu;
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.query.Predicate;
import com.govu.engine.db.DatabaseProvider;
import java.util.HashMap;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
        ObjectSet<HashMap<Object, Object>> maps = con.query(new Predicate<HashMap<Object, Object>>() {
            @Override
            public boolean match(HashMap<Object, Object> et) {
                for (Object key : map.keySet()) {
                    if (!(et.containsKey(key) && et.get(key).equals(map.get(key)))) {
                        return false;
                    }
                }
                return true;
            }
        });

        if (maps.hasNext()) {
            HashMap<Object, Object> map2 = maps.next();
            for (Object obj2 : map2.keySet()) {
                String key = obj2.toString();
                Object value = map2.get(obj2);
                obj.put(key, obj, value);
                obj.put("_id_", obj, con.ext().getID(map2));
            }
            return obj;
        } else {
            return null;
        }
    }

    private ObjectContainer getDB(String type) {
        if (dbs.containsKey(type)) {
            return dbs.get(type);
        } else {
// Path: src/com/govu/Govu.java
// public class Govu {
// 
//     public static String VERSION = "0.0.4";
//     public static String root;
//     public static String dbRoot;
//     public static String webRoot;
//     public static Logger logger;
//     public static int PORT;
//     public static Set<WebApplication> apps = new HashSet<>();
//     public static Config config;
//     private DB db;
// 
//     /**
//      * @param args the command line arguments
//      */
//     public static void main(String[] args) {
//         if (args.length > 0) {
//             String command = args[0].toLowerCase();
//             if (command.equals("deploy")) {
//                 new DeployCommand().process(args);
//             } else if (command.equals("delete")) {
//                 new DeleteCommand().process(args);
//             } else {
//                 System.out.println("Unknown govu command: " + args[0]);
//             }
//         } else {
//             //Start govu web server
//             Govu govu = new Govu();
//         }
//     }
// 
//     public Govu() {
//         logger = Logger.getLogger("govu");
//         root = System.getProperty("user.dir");
//         dbRoot = root + "/db";
//         webRoot = root + "/web";
//         logger.debug("Staring Govu Server " + VERSION + "...");
// 
//         try {
//             config = new Config();
//             config.readProperties();
//         } catch (IOException | InterruptedException ex) {
//             logger.error("Error reading config file", ex);
//         }
// 
// 
//         File webDir = new File(webRoot);
//         if (!webDir.exists()) {
//             logger.debug("Creating web base directory");
//             webDir.mkdir();
//         }
// 
//         File dbDir = new File(dbRoot);
//         if (!dbDir.exists()) {
//             logger.debug("Creating database base directory");
//             dbDir.mkdir();
//         }
// 
//         //Init Database Provider
//         db = new DB(new DB4OProvider());
// 
//         //Init http server
//         ServerBootstrap httpBootStrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
//         httpBootStrap.setOption("child.tcpNoDelay", true);
//         httpBootStrap.setPipelineFactory(new HttpServerPipelineFactory());
//         httpBootStrap.bind(new InetSocketAddress(PORT));
// 
//         logger.debug("Govu started successfully. Happy coding!");
//     }
// 
//     public static WebApplication getWebApp(String host, String path) {
//         for (Iterator<WebApplication> it = apps.iterator(); it.hasNext();) {
//             WebApplication app = it.next();
//             if ((app.getDomain() != null && app.getDomain().equals(host))
//                     || (app.getDomain() == null && path.startsWith(app.getRootPath()))) {
//                 return app;
//             }
//         }
//         return null;
//     }
//     
//     public static WebApplication getWebApp(String name) {
//         for (Iterator<WebApplication> it = apps.iterator(); it.hasNext();) {
//             WebApplication app = it.next();
//             if (app.getName().equals(name)){
//                 return app;
//             }
//         }
//         return null;
//     }
// }
// 
// Path: src/com/govu/engine/db/DatabaseProvider.java
// public interface DatabaseProvider {
// 
//     public void deleteObj(ScriptableObject obj, String type);
// 
//     public void saveObj(ScriptableObject obj, String type);
// 
//     public void delete(ScriptableObject obj, String type);
//     
//     public Scriptable[] getAll(Function function, String type);
// 
//     public Scriptable[] search(ScriptableObject obj, Function function, String type);
// 
//     public Scriptable get(ScriptableObject obj, String type);
//     
// }


// Path: src/com/govu/engine/db/db4o/DB4OProvider.java
import com.govu.Govu;
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.query.Predicate;
import com.govu.engine.db.DatabaseProvider;
import java.util.HashMap;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

        ObjectSet<HashMap<Object, Object>> maps = con.query(new Predicate<HashMap<Object, Object>>() {
            @Override
            public boolean match(HashMap<Object, Object> et) {
                for (Object key : map.keySet()) {
                    if (!(et.containsKey(key) && et.get(key).equals(map.get(key)))) {
                        return false;
                    }
                }
                return true;
            }
        });

        if (maps.hasNext()) {
            HashMap<Object, Object> map2 = maps.next();
            for (Object obj2 : map2.keySet()) {
                String key = obj2.toString();
                Object value = map2.get(obj2);
                obj.put(key, obj, value);
                obj.put("_id_", obj, con.ext().getID(map2));
            }
            return obj;
        } else {
            return null;
        }
    }

    private ObjectContainer getDB(String type) {
        if (dbs.containsKey(type)) {
            return dbs.get(type);
        } else {
            ObjectContainer obj = Db4o.openFile(Govu.dbRoot + "/" + type + ".data");