<commit_before>/*
 * Copyright (C) 2012-2013 Vanderbilt University, All rights reserved.
 * 
 * Author: <NAME>
 */

define([ "util/assert" ], function (ASSERT) {
	"use strict";

	var Lock = function () {
		var waiters = [];

		return {
			lock: function (func) {
				waiters.push(func);
				if (waiters.length === 1) {
					func();
				}
			},

			unlock: function () {
                waiters.shift();
				if (waiters.length >= 1) {
					var func = waiters[0];
					func();
				}
			}
		};
	};

	var Database = function (database, options) {
		ASSERT(typeof database === "object" && typeof options === "object");

		options.cache = options.cache || 2000;

		var projects = {};
		var dlock = new Lock();

		function openProject (name, callback) {
			ASSERT(typeof name === "string" && typeof callback === "function");

			dlock.lock(function () {
				if (typeof projects[name] !== "undefined") {
					projects[name].reopenProject(callback);
					dlock.unlock();
				} else {
					database.openProject(name, function (err, project) {
						if (err) {
							callback(err);
						} else {
							project = wrapProject(name, project);
							projects[name] = project;
							project.reopenProject(callback);
						}
						dlock.unlock();
					});
				}
			});
		}

		function closeDatabase (callback) {
			dlock.lock(function () {
				var n;
				for (n in projects) {
					projects[n].abortProject();
				}
				projects = {};
				database.closeDatabase(callback);
				dlock.unlock();
			});
		}

		function deleteProject (name, callback) {
			if (typeof projects[name] !== "undefined") {
				projects[name].deleteProject();
			}

			database.deleteProject(name, callback);
		}

		function wrapProject (name, project) {
			var ID_NAME = project.ID_NAME;

			var refcount = 0;
			var branches = {};
			var missing = {};
			var backup = {};
			var cache = {};
			var cacheSize = 0;

			function deepFreeze (obj) {
				ASSERT(typeof obj === "object");


				Object.freeze(obj);

				var key;
				for (key in obj) {
					if (obj[key] !== null && typeof obj[key] === "object") {
						deepFreeze(obj[key]);
					}
				}
			}
<commit_msg>temporary workout for mysterious freeze error<commit_after>/*
 * Copyright (C) 2012-2013 Vanderbilt University, All rights reserved.
 * 
 * Author: <NAME>
 */

define([ "util/assert" ], function (ASSERT) {
	"use strict";

	var Lock = function () {
		var waiters = [];

		return {
			lock: function (func) {
				waiters.push(func);
				if (waiters.length === 1) {
					func();
				}
			},

			unlock: function () {
                waiters.shift();
				if (waiters.length >= 1) {
					var func = waiters[0];
					func();
				}
			}
		};
	};

	var Database = function (database, options) {
		ASSERT(typeof database === "object" && typeof options === "object");

		options.cache = options.cache || 2000;

		var projects = {};
		var dlock = new Lock();

		function openProject (name, callback) {
			ASSERT(typeof name === "string" && typeof callback === "function");

			dlock.lock(function () {
				if (typeof projects[name] !== "undefined") {
					projects[name].reopenProject(callback);
					dlock.unlock();
				} else {
					database.openProject(name, function (err, project) {
						if (err) {
							callback(err);
						} else {
							project = wrapProject(name, project);
							projects[name] = project;
							project.reopenProject(callback);
						}
						dlock.unlock();
					});
				}
			});
		}

		function closeDatabase (callback) {
			dlock.lock(function () {
				var n;
				for (n in projects) {
					projects[n].abortProject();
				}
				projects = {};
				database.closeDatabase(callback);
				dlock.unlock();
			});
		}

		function deleteProject (name, callback) {
			if (typeof projects[name] !== "undefined") {
				projects[name].deleteProject();
			}

			database.deleteProject(name, callback);
		}

		function wrapProject (name, project) {
			var ID_NAME = project.ID_NAME;

			var refcount = 0;
			var branches = {};
			var missing = {};
			var backup = {};
			var cache = {};
			var cacheSize = 0;

			function deepFreeze (obj) {
				ASSERT(typeof obj === "object");


                try{
				    Object.freeze(obj);
                }
                catch(e){
                    //TODO find the proper answer why this can occur
                    return;
                }

				var key;
				for (key in obj) {
					if (obj[key] !== null && typeof obj[key] === "object") {
						deepFreeze(obj[key]);
					}
				}
			}

{'fraction_non_alphanumeric': 0.15496422182468694, 'fraction_numerical': 0.007602862254025045, 'mean_word_length': 2.363157894736842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5348799', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1358, 'n_words': 337}