/* * Generated by haxORMap */ import data.model.Error; class Orders extends data.model.Haxormanager { public static var instance : Dynamic; private function init() { TABLE = "order"; if(instance == null) instance = this; } private static var _cache = new Hash(); public function _new(?resultObj : Dynamic, ?pre : String) : Order { if(pre == null) pre = ''; var o = Type.createEmptyInstance(Order); Reflect.setField(o, "client", Clients.instance._object(resultObj, pre+'_c_')); Reflect.setField(o, "referrer", Clients.instance._object(resultObj, pre+'_c0_')); return o; } public function _object(resultObj : Dynamic, ?pre : String) : Order { if(resultObj == null) throw '_object() called on empty Resultset'; //return null(); if(pre == null) pre = ''; var key = _cacheKey(resultObj, pre); var o : Dynamic = if(_cache.exists(key)) _cache.get(key); else _new(resultObj, pre); o.id = Reflect.field(resultObj, pre+"id"); o.date = Date.fromString(Reflect.field(resultObj, pre+"date")); return o; } private function _cacheKey(obj : Dynamic, pre : String) : String { var k = new StringBuf(); k.add('#'); k.add(Reflect.field(pre+"id", obj)); k.add('#'); k.add(Reflect.field(pre+"clientid", obj)); return k.toString(); } // -- No return values -- // public function insert(obj : Order) : Void { request(engine().insert(cnx,obj,null)); } public function delete(obj : Order) : Void { request(engine().delete(cnx,obj,null)); } public function update(obj : Order) : Void { request(engine().update(cnx,obj,null)); } public function save(obj : Order) : Void { request(engine().save(cnx,obj,null)); } // -- Return single object -- // public function get(id:Int, clientId:Int) : Order { return _object( request(engine().get(cnx,{id:id, client:{id:clientId}},null)).next() ); } public function row(id:Int, clientId:Int) : Order { return _object( request(engine().row(cnx,{id:id, client:{id:clientId}},null)).next() ); } // -- Return List of objects -- // public function select(id:Int, clientId:Int, ?where : String) : List { return objectList( request(engine().select(cnx,{id:id, client:{id:clientId}},where)) ); } public function search(id:Int, clientId:Int, ?where : String) : List { return objectList( request(engine().search(cnx,{id:id, client:{id:clientId}},where)) ); } // --- DBMS abstraction --- // private function MySQLEngine(){ queryEngine = MySQLQueries; } private function SQLiteEngine(){ queryEngine = SQLiteQueries; } private static var MySQLQueries = { insert : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('INSERT `order` VALUES ('); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(','); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); s.add(','); s.add(if(v.date == null) "NULL" else v.date.toString()); s.add(','); s.add(if(v.referrer.id == null) "NULL" else v.referrer.id); s.add(')'); return s; }, delete : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('DELETE `order` '); var q=s.toString(); s=new StringBuf(); s.add('WHERE `id`='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND `clientid`='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, update : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('UPDATE `order` SET id='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(', clientid='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); s.add(', date='); s.add(if(v.date == null) "NULL" else v.date.toString()); s.add(', referrer_clientid='); s.add(if(v.referrer.id == null) "NULL" else v.referrer.id); s.add(' '); var q=s.toString(); s=new StringBuf(); s.add('WHERE `id`='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND `clientid`='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, save : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('UPDATE `order` SET date='); s.add(if(v.date == null) "NULL" else v.date.toString()); s.add(', referrer_clientid='); s.add(if(v.referrer.id == null) "NULL" else v.referrer.id); s.add(' '); var q=s.toString(); s=new StringBuf(); s.add('WHERE `id`='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND `clientid`='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, select : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('SELECT `o`.`id`, `o`.`clientid` AS `_c_id`, `o`.`date`, `o`.`referrer_clientid` AS `_c0_id`, `c`.`address` AS `_c_address`, `c`.`name` AS `_c_name`, `c0`.`address` AS `_c0_address`, `c0`.`name` AS `_c0_name` FROM `order` AS `o` LEFT JOIN `client` AS `c` ON `o`.`clientid`=`c`.`id` LEFT JOIN `client` AS `c0` ON `o`.`referrer_clientid`=`c0`.`id` '); var q=s.toString(); s=new StringBuf(); s.add('WHERE '); if(v.id != null){ s.add('`o`.`id`='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND'); } s.add(' '); if(v.client.id != null){ s.add('`c`.`clientid`='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); } var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, search : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('SELECT `o`.`id`, `o`.`clientid` AS `_c_id`, `o`.`date`, `o`.`referrer_clientid` AS `_c0_id`, `c`.`address` AS `_c_address`, `c`.`name` AS `_c_name`, `c0`.`address` AS `_c0_address`, `c0`.`name` AS `_c0_name` FROM `order` AS `o` LEFT JOIN `client` AS `c` ON `o`.`clientid`=`c`.`id` LEFT JOIN `client` AS `c0` ON `o`.`referrer_clientid`=`c0`.`id` '); var q=s.toString(); s=new StringBuf(); s.add('WHERE '); if(v.id != null){ s.add('`o`.`id` LIKE "%'); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add('%" AND'); } s.add(' '); if(v.client.id != null){ s.add('`c`.`clientid` LIKE "%'); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); s.add('%"'); } var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, get : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('SELECT `o`.`id`, `o`.`clientid` AS `_c_id`, `o`.`date`, `o`.`referrer_clientid` AS `_c0_id`, `c`.`address` AS `_c_address`, `c`.`name` AS `_c_name`, `c0`.`address` AS `_c0_address`, `c0`.`name` AS `_c0_name` FROM `order` AS `o` LEFT JOIN `client` AS `c` ON `o`.`clientid`=`c`.`id` LEFT JOIN `client` AS `c0` ON `o`.`referrer_clientid`=`c0`.`id` '); var q=s.toString(); s=new StringBuf(); s.add('WHERE `o`.`id`='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND `c`.`clientid`='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); s.add(' LIMIT 1'); return s; }, row : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('SELECT * FROM `order` '); var q=s.toString(); s=new StringBuf(); s.add('WHERE `id`='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND `clientid`='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); s.add(' LIMIT 1'); return s; }, } private static var SQLiteQueries = { insert : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('INSERT "order" VALUES ('); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(','); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); s.add(','); s.add(if(v.date == null) "NULL" else v.date.toString()); s.add(','); s.add(if(v.referrer.id == null) "NULL" else v.referrer.id); s.add(')'); return s; }, delete : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('DELETE "order" '); var q=s.toString(); s=new StringBuf(); s.add('WHERE "id"='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND "clientid"='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, update : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('UPDATE "order" SET id='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(', clientid='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); s.add(', date='); s.add(if(v.date == null) "NULL" else v.date.toString()); s.add(', referrer_clientid='); s.add(if(v.referrer.id == null) "NULL" else v.referrer.id); s.add(' '); var q=s.toString(); s=new StringBuf(); s.add('WHERE "id"='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND "clientid"='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, save : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('UPDATE "order" SET date='); s.add(if(v.date == null) "NULL" else v.date.toString()); s.add(', referrer_clientid='); s.add(if(v.referrer.id == null) "NULL" else v.referrer.id); s.add(' '); var q=s.toString(); s=new StringBuf(); s.add('WHERE "id"='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND "clientid"='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, select : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('SELECT "o"."id", "o"."clientid" AS "_c_id", "o"."date", "o"."referrer_clientid" AS "_c0_id", "c"."address" AS "_c_address", "c"."name" AS "_c_name", "c0"."address" AS "_c0_address", "c0"."name" AS "_c0_name" FROM "order" AS "o" LEFT JOIN "client" AS "c" ON "o"."clientid"="c"."id" LEFT JOIN "client" AS "c0" ON "o"."referrer_clientid"="c0"."id" '); var q=s.toString(); s=new StringBuf(); s.add('WHERE '); if(v.id != null){ s.add('"o"."id"='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND'); } s.add(' '); if(v.client.id != null){ s.add('"c"."clientid"='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); } var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, search : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('SELECT "o"."id", "o"."clientid" AS "_c_id", "o"."date", "o"."referrer_clientid" AS "_c0_id", "c"."address" AS "_c_address", "c"."name" AS "_c_name", "c0"."address" AS "_c0_address", "c0"."name" AS "_c0_name" FROM "order" AS "o" LEFT JOIN "client" AS "c" ON "o"."clientid"="c"."id" LEFT JOIN "client" AS "c0" ON "o"."referrer_clientid"="c0"."id" '); var q=s.toString(); s=new StringBuf(); s.add('WHERE '); if(v.id != null){ s.add('"o"."id" LIKE "%'); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add('%" AND'); } s.add(' '); if(v.client.id != null){ s.add('"c"."clientid" LIKE "%'); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); s.add('%"'); } var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); return s; }, get : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('SELECT "o"."id", "o"."clientid" AS "_c_id", "o"."date", "o"."referrer_clientid" AS "_c0_id", "c"."address" AS "_c_address", "c"."name" AS "_c_name", "c0"."address" AS "_c0_address", "c0"."name" AS "_c0_name" FROM "order" AS "o" LEFT JOIN "client" AS "c" ON "o"."clientid"="c"."id" LEFT JOIN "client" AS "c0" ON "o"."referrer_clientid"="c0"."id" '); var q=s.toString(); s=new StringBuf(); s.add('WHERE "o"."id"='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND "c"."clientid"='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); s.add(' LIMIT 1'); return s; }, row : function (cnx, v : Dynamic, where : String) : StringBuf { var s = new StringBuf(); s.add('SELECT * FROM "order" '); var q=s.toString(); s=new StringBuf(); s.add('WHERE "id"='); s.add(if(v.id == null) throw NullValue(v, "id", "id") else v.id); s.add(' AND "clientid"='); s.add(if(v.client.id == null) throw NullValue(v.client, "id", "client.id") else v.client.id); var w=s.toString(); s=new StringBuf(); s.add(q); if(w.length > 10) s.add(w); s.add(' LIMIT 1'); return s; }, } }