Changeset 9126
- Timestamp:
- 06/15/08 18:45:21 (4 months ago)
- Files:
-
- sandbox/blog-ng_hibernate/lib/hibernate.js (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/blog-ng_hibernate/lib/hibernate.js
r9125 r9126 81 81 * plus executing the actual Hibernate session API wrapper method operations. 82 82 */ 83 this.getHibernateTemplate = function ( params) {83 this.getHibernateTemplate = function (method, params) { 84 84 var sess = this.getSession(); 85 85 86 86 // do the actual operation 87 switch ( params.method) {87 switch (method) { 88 88 case 'save': 89 89 sess['saveOrUpdate(java.lang.String,java.lang.Object)'](params.object._type || … … 112 112 break; 113 113 case 'list': 114 var criteria = sess['createCriteria(java.lang.String)'](params. listParams.type);114 var criteria = sess['createCriteria(java.lang.String)'](params.type); 115 115 criteria.setCacheable(true); 116 if (params. listParams.orderBy) {117 var order = (params. listParams.order == 'asc') ?118 org.hibernate.criterion.Order.asc(params. listParams.orderBy) :119 org.hibernate.criterion.Order.desc(params. listParams.orderBy);116 if (params.orderBy) { 117 var order = (params.order == 'asc') ? 118 org.hibernate.criterion.Order.asc(params.orderBy) : 119 org.hibernate.criterion.Order.desc(params.orderBy); 120 120 criteria.addOrder(order); 121 121 } 122 if (params. listParams.max && (typeof params.listParams.max == 'number')) {123 criteria.setMaxResults(params. listParams.max);122 if (params.max && (typeof params.max == 'number')) { 123 criteria.setMaxResults(params.max); 124 124 } 125 125 … … 141 141 this.save = function (object) { 142 142 try { 143 return this.getHibernateTemplate( { method: 'save',object: object });143 return this.getHibernateTemplate('save', { object: object }); 144 144 } catch (e) { 145 145 log.error('in "save": ' + e.toString()); … … 150 150 this.get = function (type, id) { 151 151 try { 152 return this.getHibernateTemplate( { method: 'get',type: type, id: id });152 return this.getHibernateTemplate('get', { type: type, id: id }); 153 153 } catch (e) { 154 154 log.error('in "get": ' + e.toString()); … … 159 159 this.find = function (query) { 160 160 try { 161 return this.getHibernateTemplate( { method: 'find',query: query });161 return this.getHibernateTemplate('find', { query: query }); 162 162 } catch (e) { 163 163 log.error('in "find": ' + e.toString()); … … 168 168 this.all = function (type) { 169 169 try { 170 return this.getHibernateTemplate( { method: 'all',type: type });170 return this.getHibernateTemplate('all', { type: type }); 171 171 } catch (e) { 172 172 log.error('in "all": ' + e.toString()); … … 177 177 this.remove = function (object) { 178 178 try { 179 return this.getHibernateTemplate( { method: 'remove',object: object });179 return this.getHibernateTemplate('remove', { object: object }); 180 180 } catch (e) { 181 181 log.error('in "remove": ' + e.toString()); … … 186 186 this.list = function (params) { 187 187 try { 188 return this.getHibernateTemplate( { method: 'list', listParams: params });188 return this.getHibernateTemplate('list', params); 189 189 } catch (e) { 190 190 log.error('in "list": ' + e.toString());