Changeset 413 for GearsORM/branches

Show
Ignore:
Timestamp:
03/22/08 13:32:22 (8 months ago)
Author:
uriel
Message:

renamed namespace to JsORM

Location:
GearsORM/branches/JsORM
Files:
17 modified

Legend:

Unmodified
Added
Removed
  • GearsORM/branches/JsORM/JsORM.Events.js

    r412 r413  
    11/* 
    2         Script: GearsORM.Events.js 
    3                 Event support for GearsORM  
     2        Script: JsORM.Events.js 
     3                Event support for JsORM  
    44         
    55        License: 
     
    88 
    99/* 
    10  Class: GearsORM.Events 
     10 Class: JsORM.Events 
    1111        add event support to a class 
    1212         
     
    1414  
    1515 */ 
    16 GearsORM.Events = function() 
     16JsORM.Events = function() 
    1717{ 
    1818        this.$events = {}; 
    1919} 
    20 GearsORM.Events.prototype =  
     20JsORM.Events.prototype =  
    2121{ 
    2222        /* 
     
    7575        object - the object who fire the events 
    7676 */ 
    77 GearsORM.Events.wrapFunction=function(fn,name,object) 
     77JsORM.Events.wrapFunction=function(fn,name,object) 
    7878{ 
    7979        return function() 
  • GearsORM/branches/JsORM/JsORM.Fields.js

    r412 r413  
    11/* 
    2         Script: GearsORM.Fields.js 
     2        Script: JsORM.Fields.js 
    33                Contains the fields to be used in the models. 
    44         
     
    77*/ 
    88 
    9 GearsORM.Field = {}; 
    10 /* 
    11  Class: GearsORM.Field.Primitive 
     9JsORM.Field = {}; 
     10/* 
     11 Class: JsORM.Field.Primitive 
    1212        a meta class for basic field types like varchar,integer,real and timestamp 
    1313         
     
    1717        sqlType - the sql string for the type 
    1818 */ 
    19 GearsORM.Field.Primitive = function(sqlType) 
     19JsORM.Field.Primitive = function(sqlType) 
    2020{ 
    2121        var field = function(options) 
     
    3737                isRelation:false 
    3838        }; 
    39         field.constructor = GearsORM.Field.Primitive; 
     39        field.constructor = JsORM.Field.Primitive; 
    4040        return field; 
    4141}; 
     
    4343  a object holding all the field types(including relations) 
    4444 */ 
    45 GearsORM.Fields = 
    46 { 
    47         String:new GearsORM.Field.Primitive("VARCHAR"), 
    48         Integer:new GearsORM.Field.Primitive("INTEGER"), 
    49         Float:new GearsORM.Field.Primitive("REAL"), 
    50         TimeStamp:new GearsORM.Field.Primitive("TIMESTAMP") 
    51 }; 
    52  
    53 /* 
    54  Class: GearsORM.Fields.ManyToOne 
     45JsORM.Fields = 
     46{ 
     47        String:new JsORM.Field.Primitive("VARCHAR"), 
     48        Integer:new JsORM.Field.Primitive("INTEGER"), 
     49        Float:new JsORM.Field.Primitive("REAL"), 
     50        TimeStamp:new JsORM.Field.Primitive("TIMESTAMP") 
     51}; 
     52 
     53/* 
     54 Class: JsORM.Fields.ManyToOne 
    5555  
    5656  represent a ManyToOne relation,this isn`t a actual table field. 
     
    6666  } 
    6767 */ 
    68 GearsORM.Fields.ManyToOne = function(options) 
     68JsORM.Fields.ManyToOne = function(options) 
    6969{ 
    7070        this.options = options;  
    7171}; 
    7272 
    73 GearsORM.Fields.ManyToOne.prototype = 
     73JsORM.Fields.ManyToOne.prototype = 
    7474{ 
    7575        /* 
     
    7979        copy:function() 
    8080        { 
    81                 return new GearsORM.Fields.ManyToOne(this.options);  
     81                return new JsORM.Fields.ManyToOne(this.options);  
    8282        }, 
    8383        /* 
     
    119119        getRelatedClass:function() 
    120120        { 
    121                 return GearsORM._models[this.options.related]; 
     121                return JsORM._models[this.options.related]; 
    122122        }, 
    123123        _selectRemove:function(whereExpression,params,method) 
     
    134134 
    135135/* 
    136  Class: GearsORM.Fields.OneToMany 
     136 Class: JsORM.Fields.OneToMany 
    137137  represent a forigen key relation 
    138138   
     
    148148  } 
    149149 */ 
    150 GearsORM.Fields.OneToMany = function(options) 
     150JsORM.Fields.OneToMany = function(options) 
    151151{ 
    152152        this.options = options; 
    153153}; 
    154154 
    155 GearsORM.Fields.OneToMany.prototype = 
     155JsORM.Fields.OneToMany.prototype = 
    156156{ 
    157157        /* 
     
    161161        copy:function() 
    162162        { 
    163                 return new GearsORM.Fields.OneToMany(this.options);  
     163                return new JsORM.Fields.OneToMany(this.options);  
    164164        }, 
    165165        /* 
     
    169169        toSql:function() 
    170170        { 
    171                 return GearsORM.Sql.oneToManySql(this.options.related,this.options.allowNull); 
     171                return JsORM.Sql.oneToManySql(this.options.related,this.options.allowNull); 
    172172        }, 
    173173        /* 
     
    177177        getRelatedClass:function() 
    178178        { 
    179                 return GearsORM._models[this.options.related]; 
     179                return JsORM._models[this.options.related]; 
    180180        }, 
    181181        isBackwardRelation:false, 
     
    183183}; 
    184184/* 
    185  Class: GearsORM.Fields.ManyToMany 
     185 Class: JsORM.Fields.ManyToMany 
    186186  represent a many to many relation between two tables using a many to many relation table 
    187187   
     
    196196  } 
    197197 */ 
    198 GearsORM.Fields.ManyToMany = function(options) 
     198JsORM.Fields.ManyToMany = function(options) 
    199199{ 
    200200        this.options = options; 
    201201}; 
    202202 
    203 GearsORM.Fields.ManyToMany.prototype = 
     203JsORM.Fields.ManyToMany.prototype = 
    204204{ 
    205205        _m2mModel:null, 
     
    210210        copy:function() 
    211211        { 
    212                 return new GearsORM.Fields.ManyToMany(this.options);  
     212                return new JsORM.Fields.ManyToMany(this.options);  
    213213        }, 
    214214        /* 
     
    225225                         
    226226                        var fields = {}; 
    227                         fields[relatedModelName] = new GearsORM.Fields.OneToMany({related:relatedModelName,onDeleteCascade:true}); 
    228                         fields[thisModelName] = new GearsORM.Fields.OneToMany({related:thisModelName,onDeleteCascade:true}); 
     227                        fields[relatedModelName] = new JsORM.Fields.OneToMany({related:relatedModelName,onDeleteCascade:true}); 
     228                        fields[thisModelName] = new JsORM.Fields.OneToMany({related:thisModelName,onDeleteCascade:true}); 
    229229                         
    230                         this._m2mModel = new GearsORM.Model({ 
     230                        this._m2mModel = new JsORM.Model({ 
    231231                                name:"m2m_"+ thisModelName + "_"+ relatedModelName, 
    232232                                fields:fields 
     
    266266        { 
    267267                //create a new table for the many-to-many relation only if related class is defined 
    268                 if(GearsORM._models[this.options.related]) 
     268                if(JsORM._models[this.options.related]) 
    269269                { 
    270270                        this.getRelationModel().createTable(); 
     
    283283                var m2mTableName = this.getRelationModel().options.name; 
    284284                var relatedClass = this.getRelatedClass(); 
    285                 return new GearsORM.ResultIterator(GearsORM.execute(GearsORM.Sql.selectWithManyToMany(this.modelClass,relatedClass,m2mTableName,whereExpression,this.instance.rowid),params),relatedClass); 
     285                return new JsORM.ResultIterator(JsORM.execute(JsORM.Sql.selectWithManyToMany(this.modelClass,relatedClass,m2mTableName,whereExpression,this.instance.rowid),params),relatedClass); 
    286286        }, 
    287287        /* 
     
    311311        getRelatedClass:function() 
    312312        { 
    313                 return GearsORM._models[this.options.related]; 
     313                return JsORM._models[this.options.related]; 
    314314        }, 
    315315        isBackwardRelation:true, 
  • GearsORM/branches/JsORM/JsORM.Introspection.js

    r412 r413  
    11/* 
    2         Script: GearsORM.Introspection.js 
    3                 Contains the GearsORM.Introspection utility class, 
     2        Script: JsORM.Introspection.js 
     3                Contains the JsORM.Introspection utility class, 
    44                which contain also a model for sqlite_master table 
    55         
     
    99 
    1010/* 
    11   Class: GearsORM.Introspection 
     11  Class: JsORM.Introspection 
    1212        a utility class to do database introspection. 
    1313 */ 
    14 GearsORM.Introspection = 
     14JsORM.Introspection = 
    1515{ 
    1616        /* 
    17          Property: GearsORM.Introspection.sqliteMasterModel 
     17         Property: JsORM.Introspection.sqliteMasterModel 
    1818                a model to work with sqlite_master(provide information on the schema) table 
    1919                sqlite_master definition from sqlite site: 
     
    2626                ); 
    2727         */ 
    28         sqliteMasterModel:new GearsORM.Model({ 
     28        sqliteMasterModel:new JsORM.Model({ 
    2929                name:"sqlite_master", 
    3030                fields: 
    3131                { 
    32                         type:new GearsORM.Fields.String(), 
    33                         name:new GearsORM.Fields.String(), 
    34                         tbl_name:new GearsORM.Fields.String(), 
    35                         rootpage:new GearsORM.Fields.Integer(), 
    36                         sql:new GearsORM.Fields.String() 
     32                        type:new JsORM.Fields.String(), 
     33                        name:new JsORM.Fields.String(), 
     34                        tbl_name:new JsORM.Fields.String(), 
     35                        rootpage:new JsORM.Fields.Integer(), 
     36                        sql:new JsORM.Fields.String() 
    3737                } 
    3838        }), 
     
    5656                var query = ["sqlite_master.type =? AND sqlite_master.name IN (",qmarks.join(","),")"].join(""); 
    5757                 
    58                 return GearsORM.Introspection.sqliteMasterModel 
     58                return JsORM.Introspection.sqliteMasterModel 
    5959                .count(query,vals) == argsLength; 
    6060        } 
  • GearsORM/branches/JsORM/JsORM.Model.js

    r412 r413  
    11/* 
    2         Script: GearsORM.Model.js 
    3                 Contains GearsORM.Model a metaclass used to define models 
     2        Script: JsORM.Model.js 
     3                Contains JsORM.Model a metaclass used to define models 
    44         
    55        License: 
     
    88 
    99/* 
    10  Class: GearsORM.Model 
     10 Class: JsORM.Model 
    1111        a metaclass to define models that represent database tables. 
    1212        a metaclass is a class in which the instances are also classes. 
     
    2121    fields:  
    2222    { 
    23         name_of_the_field:a_instance_of_GearsORM.Fields.* 
     23        name_of_the_field:a_instance_of_JsORM.Fields.* 
    2424    } 
    2525   } 
    2626 */ 
    27 GearsORM.Model = function(options) 
     27JsORM.Model = function(options) 
    2828{ 
    2929        if(!options || !options.fields || !options.name) 
     
    3232        } 
    3333        /* 
    34           Class: GearsORM.Model.model 
     34          Class: JsORM.Model.model 
    3535           
    3636                represent a model instance 
     
    5555                        else 
    5656                        { 
    57                                 GearsORM.extend(this,valuesOrRowID); 
     57                                JsORM.extend(this,valuesOrRowID); 
    5858                        } 
    5959                } 
     
    8181                { 
    8282                        if(this.rowid) 
    83                                 GearsORM.executeAndClose(GearsORM.Sql.deleteRowByIdAndTable(options.name),[this.rowid]); 
     83                                JsORM.executeAndClose(JsORM.Sql.deleteRowByIdAndTable(options.name),[this.rowid]); 
    8484                                 
    8585                        this.rowid = null; 
     
    103103                _updateInsert:function(update) 
    104104                { 
    105                         var query = update ? GearsORM.Sql.updateByModel(model) : GearsORM.Sql.insertRowByModel(model); 
     105                        var query = update ? JsORM.Sql.updateByModel(model) : JsORM.Sql.insertRowByModel(model); 
    106106 
    107107                        var values = []; 
     
    129129                        } 
    130130                        if(update)values.push(this.rowid); 
    131                         GearsORM.executeAndClose(query,values); 
    132                         if(!update)this.rowid = GearsORM.getDB().lastInsertRowId; 
     131                        JsORM.executeAndClose(query,values); 
     132                        if(!update)this.rowid = JsORM.getDB().lastInsertRowId; 
    133133                        return this; 
    134134                }, 
     
    198198                options.fields[fieldName].modelClass = model; 
    199199        } 
    200         GearsORM.extend(model,this); 
    201         GearsORM.extend(model,new GearsORM.Events); 
     200        JsORM.extend(model,this); 
     201        JsORM.extend(model,new JsORM.Events); 
    202202         
    203203        for(var i in model.prototype)//add events to save,remove,refresh 
    204204                if(i.charAt(0) != "_")//wrap only public functions 
    205                         model.prototype[i] = GearsORM.Events.wrapFunction(model.prototype[i],i.charAt(0).toUpperCase()+i.substring(1),model); 
     205                        model.prototype[i] = JsORM.Events.wrapFunction(model.prototype[i],i.charAt(0).toUpperCase()+i.substring(1),model); 
    206206 
    207         model.constructor = GearsORM.Model; 
     207        model.constructor = JsORM.Model; 
    208208        //register the model 
    209         GearsORM._models[options.name] = model; 
     209        JsORM._models[options.name] = model; 
    210210        return model; 
    211211}; 
    212212/* 
    213   class methods of GearsORM.Model  
     213  class methods of JsORM.Model  
    214214  this reffer to the model class 
    215215 */ 
    216 GearsORM.Model.prototype = 
     216JsORM.Model.prototype = 
    217217{ 
    218218        /* 
     
    232232        count:function(whereExpression,params) 
    233233        { 
    234                 var rs = GearsORM.execute(GearsORM.Sql.selectCount(this.options.name,whereExpression),params); 
     234                var rs = JsORM.execute(JsORM.Sql.selectCount(this.options.name,whereExpression),params); 
    235235                var count = rs.fieldByName("c"); 
    236236                rs.close(); 
     
    253253        select:function(whereExpression,params) 
    254254        { 
    255                 return new GearsORM.ResultIterator(GearsORM.execute(GearsORM.Sql.selectWithForigenKeys(this,whereExpression),params),this); 
     255                return new JsORM.ResultIterator(JsORM.execute(JsORM.Sql.selectWithForigenKeys(this,whereExpression),params),this); 
    256256        }, 
    257257        /* 
     
    267267        remove:function(whereExpression,params) 
    268268        { 
    269                 GearsORM.executeAndClose(GearsORM.Sql.deleteFromTableWhere(this.options.name,whereExpression),params); 
     269                JsORM.executeAndClose(JsORM.Sql.deleteFromTableWhere(this.options.name,whereExpression),params); 
    270270        }, 
    271271        /* 
     
    276276        createTable:function() 
    277277        { 
    278                 GearsORM.Transaction(function(){ 
    279                         GearsORM.executeAndClose(GearsORM.Sql.createTableByModelClass(this)); 
     278                JsORM.Transaction(function(){ 
     279                        JsORM.executeAndClose(JsORM.Sql.createTableByModelClass(this)); 
    280280                        var fields = this.options.fields; 
    281281                        for(var fieldName in fields) 
     
    295295        dropTable:function() 
    296296        { 
    297                 GearsORM.Transaction(function(){ 
    298                         GearsORM.executeAndClose(GearsORM.Sql.dropTableByName(this.options.name)); 
     297                JsORM.Transaction(function(){ 
     298                        JsORM.executeAndClose(JsORM.Sql.dropTableByName(this.options.name)); 
    299299                        this.dropTriggers(); 
    300300                },this); 
     
    317317                        } 
    318318                        //if one of the tables doesn`t exist don`t create the triggers 
    319                         if(!GearsORM.Introspection.doesTableExist.apply(this,tableNames)) 
     319                        if(!JsORM.Introspection.doesTableExist.apply(this,tableNames)) 
    320320                                return; 
    321321                };                       
    322322                var fields = this.options.fields; 
    323323                var name = this.options.name; 
    324                 GearsORM.Transaction(function(){ 
     324                JsORM.Transaction(function(){ 
    325325                        for(var fieldName in fields) 
    326326                        { 
     
    329329                                { 
    330330                                        //on insert,check that forigen key is valid since sqlite doesn`t enforce forigenkeys 
    331                                         GearsORM.executeAndClose(GearsORM.Sql.createInsertForigenKeyTrigger(name,field.getRelatedClass().options.name,field.options.allowNull)); 
     331                                        JsORM.executeAndClose(JsORM.Sql.createInsertForigenKeyTrigger(name,field.getRelatedClass().options.name,field.options.allowNull)); 
    332332                                        //on update,check that forigen key is valid     since sqlite doesn`t enforce forigenkeys 
    333                                         GearsORM.executeAndClose(GearsORM.Sql.createUpdateForigenKeyTrigger(name,field.getRelatedClass().options.name,field.options.allowNull)); 
     333                                        JsORM.executeAndClose(JsORM.Sql.createUpdateForigenKeyTrigger(name,field.getRelatedClass().options.name,field.options.allowNull)); 
    334334                                         
    335335                                        if(field.options.onDeleteCascade) 
    336336                                                //on delete from parent table,delete all rows that reference the row that is going to be deleted 
    337                                                 GearsORM.executeAndClose(GearsORM.Sql.createDeleteCascadeTrigger(name,field.getRelatedClass().options.name)); 
     337                                                JsORM.executeAndClose(JsORM.Sql.createDeleteCascadeTrigger(name,field.getRelatedClass().options.name)); 
    338338                                        else 
    339339                                                //on delete from parent table,if there is a row that reference the row that is going to be deleted throw a exception 
    340                                                 GearsORM.executeAndClose(GearsORM.Sql.createDeleteRestrictTrigger(name,field.getRelatedClass().options.name)); 
     340                                                JsORM.executeAndClose(JsORM.Sql.createDeleteRestrictTrigger(name,field.getRelatedClass().options.name)); 
    341341                                } 
    342342                        } 
     
    352352                var fields = this.options.fields; 
    353353                var name = this.options.name; 
    354                 GearsORM.Transaction(function(){ 
     354                JsORM.Transaction(function(){ 
    355355                        for(var fieldName in fields) 
    356356                        { 
     
    359359                                { 
    360360                                        //INSERT 
    361                                         GearsORM.executeAndClose(GearsORM.Sql.dropForigenKeyInsertTrigger(name,field.getRelatedClass().options.name)); 
     361                                        JsORM.executeAndClose(JsORM.Sql.dropForigenKeyInsertTrigger(name,field.getRelatedClass().options.name)); 
    362362                                        //UPDATE 
    363                                         GearsORM.executeAndClose(GearsORM.Sql.dropForigenKeyUpdateTrigger(name,field.getRelatedClass().options.name)); 
     363                                        JsORM.executeAndClose(JsORM.Sql.dropForigenKeyUpdateTrigger(name,field.getRelatedClass().options.name)); 
    364364                                        //DELETE 
    365                                         GearsORM.executeAndClose(GearsORM.Sql.dropForigenKeyDeleteTrigger(name,field.getRelatedClass().options.name)); 
     365                                        JsORM.executeAndClose(JsORM.Sql.dropForigenKeyDeleteTrigger(name,field.getRelatedClass().options.name)); 
    366366                                } 
    367367                                else if(field._m2mModel) 
     
    398398                        } 
    399399                } 
    400                 if(save)GearsORM.Transaction(map); 
     400                if(save)JsORM.Transaction(map); 
    401401                else map(); 
    402402                return mappedObjects; 
  • GearsORM/branches/JsORM/JsORM.ResultIterator.js

    r412 r413  
    11/* 
    2         Script: GearsORM.ResultIterator.js 
     2        Script: JsORM.ResultIterator.js 
    33                Contains the ResultIterator class. 
    44         
     
    88 
    99/* 
    10  Class: GearsORM.ResultIterator 
     10 Class: JsORM.ResultIterator 
    1111        a iterator on a Google Gears ResultSet 
    1212         
     
    1515        modelClass - the model class used to map the results  
    1616 */ 
    17 GearsORM.ResultIterator = function(result,modelClass) 
     17JsORM.ResultIterator = function(result,modelClass) 
    1818{ 
    1919        this.result = result; 
     
    2222}; 
    2323