<commit_before>// databankobject.js
//
// abstraction for CRUD'ing an object as JSON to a Databank
//
// Copyright 2011, StatusNet Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var Databank = require('./databank').Databank;

var DatabankObject = function(properties) {
    DatabankObject.init(this, properties);
};

DatabankObject.init = function(obj, properties) {
    DatabankObject.copy(obj, properties);
};

DatabankObject.copy = function(obj, properties) {
    var property;
    for (property in properties) {
        obj[property] = properties[property];
    }
};

DatabankObject.driver = null;
DatabankObject.params = {};
DatabankObject.bank = null;

DatabankObject.subClass = function(type, Parent) {

    var Cls;

    if (!Parent) {
        Parent = DatabankObject;
    }

    Cls = function(properties) {
        Cls.init(this, properties);
    };

    Cls.init = function(inst, properties) {
	Parent.init(inst, properties);
    };

    Cls.parent = Parent;

    Cls.bank = function() {
        return DatabankObject.bank;
    };

    Cls.type = type;

    Cls.get = function(id, callback) {
        Cls.bank().read(Cls.type, id, function(err, value) {
            if (err) {
                callback(err, null);
            } else {
                callback(null, new Cls(value));
            }
        });
    };

    Cls.search = function(criteria, callback) {
        var results = [];

        Cls.bank().search(Cls.type,
                          criteria, 
                          function(value) {
                              results.push(new Cls(value));
                          },
                          function(err) {
                              if (err) {
                                  callback(err, null);
                              } else {
                                  callback(null, results);
                              }
                          });
    };

    Cls.pkey = function() {
        var bank = Cls.bank();
        if (bank && bank.schema && bank.schema[Cls.type]) {
            return bank.schema[Cls.type].pkey;
        } else {
            return 'id';
        }
    };

    Cls.create = function(props, callback) {
        Cls.bank().create(Cls.type, props[Cls.pkey()], props, function(err, value) {
            if (err) {
                callback(err, null);
            } else {
                callback(null, new Cls(value));
            }
        });
    };

    Cls.readAll = function(ids, callback) {
        Cls.bank().readAll(Cls.type, ids, function(err, map) {
            if (err) {
                callback(err, null);
            } else {
                var clsMap = {}, id;
                for (id in map) {
                    if (map[id]) {
                        clsMap[id] = new Cls(map[id]);
                    } else {
                        clsMap[id] = null;
                    }
                }
                callback(null, clsMap);
            }
        });
    };

    Cls.prototype = new Parent({
        update: function(props, callback) {
            var inst = this;
            DatabankObject.copy(this, props);
            Cls.bank().update(Cls.type, this[Cls.pkey()], this, function(err, value) {
                if (err) {
                    callback(err, null);
                } else {
                    DatabankObject.copy(inst, value); // may be updated
                    callback(null, inst);
                }
            });
        },
        del: function(callback) {<commit_msg>Use hasOwnProperty() for map<commit_after>// databankobject.js
//
// abstraction for CRUD'ing an object as JSON to a Databank
//
// Copyright 2011, StatusNet Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var Databank = require('./databank').Databank;

var DatabankObject = function(properties) {
    DatabankObject.init(this, properties);
};

DatabankObject.init = function(obj, properties) {
    DatabankObject.copy(obj, properties);
};

DatabankObject.copy = function(obj, properties) {
    var property;
    for (property in properties) {
        obj[property] = properties[property];
    }
};

DatabankObject.driver = null;
DatabankObject.params = {};
DatabankObject.bank = null;

DatabankObject.subClass = function(type, Parent) {

    var Cls;

    if (!Parent) {
        Parent = DatabankObject;
    }

    Cls = function(properties) {
        Cls.init(this, properties);
    };

    Cls.init = function(inst, properties) {
	Parent.init(inst, properties);
    };

    Cls.parent = Parent;

    Cls.bank = function() {
        return DatabankObject.bank;
    };

    Cls.type = type;

    Cls.get = function(id, callback) {
        Cls.bank().read(Cls.type, id, function(err, value) {
            if (err) {
                callback(err, null);
            } else {
                callback(null, new Cls(value));
            }
        });
    };

    Cls.search = function(criteria, callback) {
        var results = [];

        Cls.bank().search(Cls.type,
                          criteria, 
                          function(value) {
                              results.push(new Cls(value));
                          },
                          function(err) {
                              if (err) {
                                  callback(err, null);
                              } else {
                                  callback(null, results);
                              }
                          });
    };

    Cls.pkey = function() {
        var bank = Cls.bank();
        if (bank && bank.schema && bank.schema[Cls.type]) {
            return bank.schema[Cls.type].pkey;
        } else {
            return 'id';
        }
    };

    Cls.create = function(props, callback) {
        Cls.bank().create(Cls.type, props[Cls.pkey()], props, function(err, value) {
            if (err) {
                callback(err, null);
            } else {
                callback(null, new Cls(value));
            }
        });
    };

    Cls.readAll = function(ids, callback) {
        Cls.bank().readAll(Cls.type, ids, function(err, map) {
            if (err) {
                callback(err, null);
            } else {
                var clsMap = {}, id;
                for (id in map) {
                    if (map.hasOwnProperty(id)) {
			if (map[id]) {
                            clsMap[id] = new Cls(map[id]);
			} else {
                            clsMap[id] = null;
			}
                    }
                }
                callback(null, clsMap);
            }
        });
    };

    Cls.prototype = new Parent({
        update: function(props, callback) {
            var inst = this;
            DatabankObject.copy(this, props);
            Cls.bank().update(Cls.type, this[Cls.pkey()], this, function(err, value) {
                if (err) {
                    callback(err, null);
                } else {
                    DatabankObject.copy(inst, value); // may be updated
                    callback(null, inst);
                }
            });
        },
        del: function(callback) {
{'fraction_non_alphanumeric': 0.12030168150346192, 'fraction_numerical': 0.0019782393669634025, 'mean_word_length': 1.4676632092739474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '880921', 'n_tokens_mistral': 2300, 'n_tokens_neox': 2214, 'n_words': 547}