001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * OrderLineDetailFactory.java 021 */ 022 023package com.echothree.model.data.order.server.factory; 024 025import com.echothree.model.data.order.common.pk.OrderLinePK; 026import com.echothree.model.data.order.common.pk.OrderPK; 027import com.echothree.model.data.order.common.pk.OrderShipmentGroupPK; 028import com.echothree.model.data.item.common.pk.ItemPK; 029import com.echothree.model.data.inventory.common.pk.InventoryConditionPK; 030import com.echothree.model.data.uom.common.pk.UnitOfMeasureTypePK; 031import com.echothree.model.data.cancellationpolicy.common.pk.CancellationPolicyPK; 032import com.echothree.model.data.returnpolicy.common.pk.ReturnPolicyPK; 033 034import com.echothree.model.data.order.server.entity.OrderLine; 035import com.echothree.model.data.order.server.entity.Order; 036import com.echothree.model.data.order.server.entity.OrderShipmentGroup; 037import com.echothree.model.data.item.server.entity.Item; 038import com.echothree.model.data.inventory.server.entity.InventoryCondition; 039import com.echothree.model.data.uom.server.entity.UnitOfMeasureType; 040import com.echothree.model.data.cancellationpolicy.server.entity.CancellationPolicy; 041import com.echothree.model.data.returnpolicy.server.entity.ReturnPolicy; 042 043import com.echothree.model.data.order.common.OrderLineDetailConstants; 044import com.echothree.model.data.order.common.pk.OrderLineDetailPK; 045import com.echothree.model.data.order.server.value.OrderLineDetailValue; 046import com.echothree.model.data.order.server.entity.OrderLineDetail; 047import com.echothree.util.common.exception.PersistenceDatabaseException; 048import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 049import com.echothree.util.common.exception.PersistenceNotNullException; 050import com.echothree.util.server.persistence.BaseFactory; 051import com.echothree.util.server.persistence.EntityIdGenerator; 052import com.echothree.util.server.persistence.EntityPermission; 053import com.echothree.util.server.persistence.PersistenceDebugFlags; 054import com.echothree.util.server.persistence.Session; 055import com.echothree.util.server.persistence.ThreadSession; 056import java.sql.PreparedStatement; 057import java.sql.ResultSet; 058import java.sql.SQLException; 059import java.sql.Types; 060import java.io.ByteArrayInputStream; 061import java.io.StringReader; 062import java.util.ArrayList; 063import java.util.Collection; 064import java.util.HashSet; 065import java.util.List; 066import java.util.Map; 067import java.util.Set; 068import org.apache.commons.logging.Log; 069import org.apache.commons.logging.LogFactory; 070 071public class OrderLineDetailFactory 072 implements BaseFactory<OrderLineDetailPK, OrderLineDetail> { 073 074 //final private static Log log = LogFactory.getLog(OrderLineDetailFactory.class); 075 076 final private static String SQL_SELECT_READ_ONLY = "SELECT ordldt_orderlinedetailid, ordldt_ordl_orderlineid, ordldt_ord_orderid, ordldt_orderlinesequence, ordldt_parentorderlineid, ordldt_ordshpgrp_ordershipmentgroupid, ordldt_itm_itemid, ordldt_invcon_inventoryconditionid, ordldt_uomt_unitofmeasuretypeid, ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid, ordldt_rtnplcy_returnpolicyid, ordldt_taxable, ordldt_fromtime, ordldt_thrutime FROM orderlinedetails WHERE ordldt_orderlinedetailid = ?"; 077 final private static String SQL_SELECT_READ_WRITE = "SELECT ordldt_orderlinedetailid, ordldt_ordl_orderlineid, ordldt_ord_orderid, ordldt_orderlinesequence, ordldt_parentorderlineid, ordldt_ordshpgrp_ordershipmentgroupid, ordldt_itm_itemid, ordldt_invcon_inventoryconditionid, ordldt_uomt_unitofmeasuretypeid, ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid, ordldt_rtnplcy_returnpolicyid, ordldt_taxable, ordldt_fromtime, ordldt_thrutime FROM orderlinedetails WHERE ordldt_orderlinedetailid = ? FOR UPDATE"; 078 final private static String SQL_INSERT = "INSERT INTO orderlinedetails (ordldt_orderlinedetailid, ordldt_ordl_orderlineid, ordldt_ord_orderid, ordldt_orderlinesequence, ordldt_parentorderlineid, ordldt_ordshpgrp_ordershipmentgroupid, ordldt_itm_itemid, ordldt_invcon_inventoryconditionid, ordldt_uomt_unitofmeasuretypeid, ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid, ordldt_rtnplcy_returnpolicyid, ordldt_taxable, ordldt_fromtime, ordldt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 079 final private static String SQL_UPDATE = "UPDATE orderlinedetails SET ordldt_ordl_orderlineid = ?, ordldt_ord_orderid = ?, ordldt_orderlinesequence = ?, ordldt_parentorderlineid = ?, ordldt_ordshpgrp_ordershipmentgroupid = ?, ordldt_itm_itemid = ?, ordldt_invcon_inventoryconditionid = ?, ordldt_uomt_unitofmeasuretypeid = ?, ordldt_quantity = ?, ordldt_unitamount = ?, ordldt_description = ?, ordldt_cnclplcy_cancellationpolicyid = ?, ordldt_rtnplcy_returnpolicyid = ?, ordldt_taxable = ?, ordldt_fromtime = ?, ordldt_thrutime = ? WHERE ordldt_orderlinedetailid = ?"; 080 final private static String SQL_DELETE = "DELETE FROM orderlinedetails WHERE ordldt_orderlinedetailid = ?"; 081 final private static String SQL_VALID = "SELECT COUNT(*) FROM orderlinedetails WHERE ordldt_orderlinedetailid = ?"; 082 083 final private static String PK_COLUMN = "ordldt_orderlinedetailid"; 084 final private static String ALL_COLUMNS = "ordldt_orderlinedetailid, ordldt_ordl_orderlineid, ordldt_ord_orderid, ordldt_orderlinesequence, ordldt_parentorderlineid, ordldt_ordshpgrp_ordershipmentgroupid, ordldt_itm_itemid, ordldt_invcon_inventoryconditionid, ordldt_uomt_unitofmeasuretypeid, ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid, ordldt_rtnplcy_returnpolicyid, ordldt_taxable, ordldt_fromtime, ordldt_thrutime"; 085 final public static String TABLE_NAME = "orderlinedetails"; 086 087 final public static String ORDLDT_ORDERLINEDETAILID = "ordldt_orderlinedetailid"; 088 final public static String ORDLDT_ORDL_ORDERLINEID = "ordldt_ordl_orderlineid"; 089 final public static String ORDLDT_ORD_ORDERID = "ordldt_ord_orderid"; 090 final public static String ORDLDT_ORDERLINESEQUENCE = "ordldt_orderlinesequence"; 091 final public static String ORDLDT_PARENTORDERLINEID = "ordldt_parentorderlineid"; 092 final public static String ORDLDT_ORDSHPGRP_ORDERSHIPMENTGROUPID = "ordldt_ordshpgrp_ordershipmentgroupid"; 093 final public static String ORDLDT_ITM_ITEMID = "ordldt_itm_itemid"; 094 final public static String ORDLDT_INVCON_INVENTORYCONDITIONID = "ordldt_invcon_inventoryconditionid"; 095 final public static String ORDLDT_UOMT_UNITOFMEASURETYPEID = "ordldt_uomt_unitofmeasuretypeid"; 096 final public static String ORDLDT_QUANTITY = "ordldt_quantity"; 097 final public static String ORDLDT_UNITAMOUNT = "ordldt_unitamount"; 098 final public static String ORDLDT_DESCRIPTION = "ordldt_description"; 099 final public static String ORDLDT_CNCLPLCY_CANCELLATIONPOLICYID = "ordldt_cnclplcy_cancellationpolicyid"; 100 final public static String ORDLDT_RTNPLCY_RETURNPOLICYID = "ordldt_rtnplcy_returnpolicyid"; 101 final public static String ORDLDT_TAXABLE = "ordldt_taxable"; 102 final public static String ORDLDT_FROMTIME = "ordldt_fromtime"; 103 final public static String ORDLDT_THRUTIME = "ordldt_thrutime"; 104 105 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(OrderLineDetailConstants.COMPONENT_VENDOR_NAME, OrderLineDetailConstants.ENTITY_TYPE_NAME); 106 107 /** Creates a new instance of OrderLineDetailFactory */ 108 private OrderLineDetailFactory() { 109 super(); 110 } 111 112 private static class OrderLineDetailFactoryHolder { 113 static OrderLineDetailFactory instance = new OrderLineDetailFactory(); 114 } 115 116 public static OrderLineDetailFactory getInstance() { 117 return OrderLineDetailFactoryHolder.instance; 118 } 119 120 @Override 121 public String getPKColumn() { 122 return PK_COLUMN; 123 } 124 125 @Override 126 public String getAllColumns() { 127 return ALL_COLUMNS; 128 } 129 130 @Override 131 public String getTableName() { 132 return TABLE_NAME; 133 } 134 135 @Override 136 public String getComponentVendorName() { 137 return OrderLineDetailConstants.COMPONENT_VENDOR_NAME; 138 } 139 140 @Override 141 public String getEntityTypeName() { 142 return OrderLineDetailConstants.ENTITY_TYPE_NAME; 143 } 144 145 public PreparedStatement prepareStatement(String query) { 146 return ThreadSession.currentSession().prepareStatement(OrderLineDetailFactory.class, query); 147 } 148 149 public OrderLineDetailPK getNextPK() { 150 return new OrderLineDetailPK(entityIdGenerator.getNextEntityId()); 151 } 152 153 public Set<OrderLineDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 154 throws PersistenceDatabaseException { 155 Set<OrderLineDetailPK> _result = new HashSet<>(); 156 157 try { 158 while(rs.next()) { 159 _result.add(getPKFromResultSet(rs)); 160 } 161 } catch (SQLException se) { 162 throw new PersistenceDatabaseException(se); 163 } 164 165 return _result; 166 } 167 168 public java.util.List<OrderLineDetailPK> getPKsFromResultSetAsList(ResultSet rs) 169 throws PersistenceDatabaseException { 170 java.util.List<OrderLineDetailPK> _result = new ArrayList<>(); 171 172 try { 173 while(rs.next()) { 174 _result.add(getPKFromResultSet(rs)); 175 } 176 } catch (SQLException se) { 177 throw new PersistenceDatabaseException(se); 178 } 179 180 return _result; 181 } 182 183 public OrderLineDetailPK getPKFromResultSet(ResultSet rs) 184 throws PersistenceDatabaseException { 185 OrderLineDetailPK _result; 186 187 try { 188 long ordldt_orderlinedetailid = rs.getLong(ORDLDT_ORDERLINEDETAILID); 189 Long _entityId = rs.wasNull() ? null : ordldt_orderlinedetailid; 190 191 _result = new OrderLineDetailPK(_entityId); 192 } catch (SQLException se) { 193 throw new PersistenceDatabaseException(se); 194 } 195 196 return _result; 197 } 198 199 public java.util.List<OrderLineDetailValue> getValuesFromPKs(Session session, Collection<OrderLineDetailPK> pks) 200 throws PersistenceDatabaseException { 201 java.util.List<OrderLineDetailValue> _values = new ArrayList<>(pks.size()); 202 203 for(OrderLineDetailPK _pk: pks) { 204 _values.add(getValueFromPK(session, _pk)); 205 } 206 207 return _values; 208 } 209 210 public OrderLineDetailValue getValueFromPK(Session session, OrderLineDetailPK pk) 211 throws PersistenceDatabaseException { 212 OrderLineDetailValue _value; 213 214 // See if we already have the entity in the session cache 215 OrderLineDetail _entity = (OrderLineDetail)session.getEntity(pk); 216 if(_entity == null) 217 _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getOrderLineDetailValue(); 218 else 219 _value = _entity.getOrderLineDetailValue(); 220 221 return _value; 222 } 223 224 public java.util.List<OrderLineDetailValue> getValuesFromResultSet(Session session, ResultSet rs) 225 throws PersistenceDatabaseException { 226 java.util.List<OrderLineDetailValue> _result = new ArrayList<>(); 227 228 try { 229 while(rs.next()) { 230 _result.add(getValueFromResultSet(session, rs)); 231 } 232 } catch (SQLException se) { 233 throw new PersistenceDatabaseException(se); 234 } 235 236 return _result; 237 } 238 239 public OrderLineDetailValue getValueFromResultSet(Session session, ResultSet rs) 240 throws PersistenceDatabaseException { 241 OrderLineDetailValue _value; 242 243 try { 244 Long ordldt_orderlinedetailid = rs.getLong(ORDLDT_ORDERLINEDETAILID); 245 OrderLineDetailPK _pk = new OrderLineDetailPK(ordldt_orderlinedetailid); 246 247 // See if we already have the entity in the session cache 248 OrderLineDetail _entity = (OrderLineDetail)session.getEntity(_pk); 249 250 if(_entity == null) { 251 Long ordldt_ordl_orderlineid = rs.getLong(ORDLDT_ORDL_ORDERLINEID); 252 if(rs.wasNull()) 253 ordldt_ordl_orderlineid = null; 254 255 Long ordldt_ord_orderid = rs.getLong(ORDLDT_ORD_ORDERID); 256 if(rs.wasNull()) 257 ordldt_ord_orderid = null; 258 259 Integer ordldt_orderlinesequence = rs.getInt(ORDLDT_ORDERLINESEQUENCE); 260 if(rs.wasNull()) 261 ordldt_orderlinesequence = null; 262 263 Long ordldt_parentorderlineid = rs.getLong(ORDLDT_PARENTORDERLINEID); 264 if(rs.wasNull()) 265 ordldt_parentorderlineid = null; 266 267 Long ordldt_ordshpgrp_ordershipmentgroupid = rs.getLong(ORDLDT_ORDSHPGRP_ORDERSHIPMENTGROUPID); 268 if(rs.wasNull()) 269 ordldt_ordshpgrp_ordershipmentgroupid = null; 270 271 Long ordldt_itm_itemid = rs.getLong(ORDLDT_ITM_ITEMID); 272 if(rs.wasNull()) 273 ordldt_itm_itemid = null; 274 275 Long ordldt_invcon_inventoryconditionid = rs.getLong(ORDLDT_INVCON_INVENTORYCONDITIONID); 276 if(rs.wasNull()) 277 ordldt_invcon_inventoryconditionid = null; 278 279 Long ordldt_uomt_unitofmeasuretypeid = rs.getLong(ORDLDT_UOMT_UNITOFMEASURETYPEID); 280 if(rs.wasNull()) 281 ordldt_uomt_unitofmeasuretypeid = null; 282 283 Long ordldt_quantity = rs.getLong(ORDLDT_QUANTITY); 284 if(rs.wasNull()) 285 ordldt_quantity = null; 286 287 Long ordldt_unitamount = rs.getLong(ORDLDT_UNITAMOUNT); 288 if(rs.wasNull()) 289 ordldt_unitamount = null; 290 291 String ordldt_description = rs.getString(ORDLDT_DESCRIPTION); 292 if(rs.wasNull()) 293 ordldt_description = null; 294 295 Long ordldt_cnclplcy_cancellationpolicyid = rs.getLong(ORDLDT_CNCLPLCY_CANCELLATIONPOLICYID); 296 if(rs.wasNull()) 297 ordldt_cnclplcy_cancellationpolicyid = null; 298 299 Long ordldt_rtnplcy_returnpolicyid = rs.getLong(ORDLDT_RTNPLCY_RETURNPOLICYID); 300 if(rs.wasNull()) 301 ordldt_rtnplcy_returnpolicyid = null; 302 303 Boolean ordldt_taxable = rs.getInt(ORDLDT_TAXABLE) == 1; 304 if(rs.wasNull()) 305 ordldt_taxable = null; 306 307 Long ordldt_fromtime = rs.getLong(ORDLDT_FROMTIME); 308 if(rs.wasNull()) 309 ordldt_fromtime = null; 310 311 Long ordldt_thrutime = rs.getLong(ORDLDT_THRUTIME); 312 if(rs.wasNull()) 313 ordldt_thrutime = null; 314 315 _value = new OrderLineDetailValue(_pk, new OrderLinePK(ordldt_ordl_orderlineid), new OrderPK(ordldt_ord_orderid), ordldt_orderlinesequence, new OrderLinePK(ordldt_parentorderlineid), new OrderShipmentGroupPK(ordldt_ordshpgrp_ordershipmentgroupid), new ItemPK(ordldt_itm_itemid), new InventoryConditionPK(ordldt_invcon_inventoryconditionid), new UnitOfMeasureTypePK(ordldt_uomt_unitofmeasuretypeid), ordldt_quantity, ordldt_unitamount, ordldt_description, new CancellationPolicyPK(ordldt_cnclplcy_cancellationpolicyid), new ReturnPolicyPK(ordldt_rtnplcy_returnpolicyid), ordldt_taxable, ordldt_fromtime, ordldt_thrutime); 316 } else 317 _value = _entity.getOrderLineDetailValue(); 318 } catch (SQLException se) { 319 throw new PersistenceDatabaseException(se); 320 } 321 322 return _value; 323 } 324 325 public java.util.List<OrderLineDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<OrderLineDetailPK> pks) 326 throws PersistenceDatabaseException { 327 return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks); 328 } 329 330 public java.util.List<OrderLineDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<OrderLineDetailPK> pks) 331 throws PersistenceDatabaseException { 332 java.util.List<OrderLineDetail> _entities = new ArrayList<>(pks.size()); 333 334 for(OrderLineDetailPK _pk: pks) { 335 _entities.add(getEntityFromPK(session, entityPermission, _pk)); 336 } 337 338 return _entities; 339 } 340 341 public OrderLineDetail getEntityFromValue(EntityPermission entityPermission, OrderLineDetailValue value) { 342 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey()); 343 } 344 345 public OrderLineDetail getEntityFromValue(Session session, EntityPermission entityPermission, OrderLineDetailValue value) { 346 return getEntityFromPK(session, entityPermission, value.getPrimaryKey()); 347 } 348 349 public OrderLineDetail getEntityFromPK(EntityPermission entityPermission, OrderLineDetailPK pk) 350 throws PersistenceDatabaseException { 351 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk); 352 } 353 354 public OrderLineDetail getEntityFromCache(Session session, OrderLineDetailPK pk) { 355 OrderLineDetailValue _value = (OrderLineDetailValue)session.getValueCache().get(pk); 356 357 return _value == null ? null : new OrderLineDetail(_value, EntityPermission.READ_ONLY); 358 } 359 360 public OrderLineDetail getEntityFromPK(Session session, EntityPermission entityPermission, OrderLineDetailPK pk) 361 throws PersistenceDatabaseException { 362 OrderLineDetail _entity; 363 364 // See if we already have the entity in the session cache 365 _entity = (OrderLineDetail)session.getEntity(pk); 366 if(_entity != null) { 367 // If the requested permission is READ_WRITE, and the cached permission is 368 // READ_ONLY, then pretend that the cached object wasn't found, and create 369 // a new entity that is READ_WRITE. 370 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 371 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 372 _entity = null; 373 } 374 } 375 376 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 377 _entity = getEntityFromCache(session, pk); 378 } 379 380 if(_entity == null) { 381 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 382 long _entityId = pk.getEntityId(); 383 ResultSet _rs = null; 384 385 try { 386 _ps.setLong(1, _entityId); 387 _rs = _ps.executeQuery(); 388 if(_rs.next()) { 389 _entity = getEntityFromResultSet(session, entityPermission, _rs); 390 } 391 } catch (SQLException se) { 392 throw new PersistenceDatabaseException(se); 393 } finally { 394 if(_rs != null) { 395 try { 396 _rs.close(); 397 } catch (SQLException se) { 398 // do nothing 399 } 400 } 401 } 402 } 403 404 return _entity; 405 } 406 407 public Set<OrderLineDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 408 throws PersistenceDatabaseException { 409 Set<OrderLineDetailPK> _pks; 410 ResultSet _rs = null; 411 412 try { 413 if(params.length != 0) { 414 Session.setQueryParams(ps, params); 415 } 416 417 _rs = ps.executeQuery(); 418 _pks = getPKsFromResultSetAsSet(_rs); 419 _rs.close(); 420 } catch (SQLException se) { 421 throw new PersistenceDatabaseException(se); 422 } finally { 423 if(_rs != null) { 424 try { 425 _rs.close(); 426 } catch (SQLException se) { 427 // do nothing 428 } 429 } 430 } 431 432 return _pks; 433 } 434 435 public java.util.List<OrderLineDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 436 throws PersistenceDatabaseException { 437 java.util.List<OrderLineDetailPK> _pks; 438 ResultSet _rs = null; 439 440 try { 441 if(params.length != 0) { 442 Session.setQueryParams(ps, params); 443 } 444 445 _rs = ps.executeQuery(); 446 _pks = getPKsFromResultSetAsList(_rs); 447 _rs.close(); 448 } catch (SQLException se) { 449 throw new PersistenceDatabaseException(se); 450 } finally { 451 if(_rs != null) { 452 try { 453 _rs.close(); 454 } catch (SQLException se) { 455 // do nothing 456 } 457 } 458 } 459 460 return _pks; 461 } 462 463 public OrderLineDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 464 throws PersistenceDatabaseException { 465 OrderLineDetailPK _pk = null; 466 ResultSet _rs = null; 467 468 try { 469 if(params.length != 0) { 470 Session.setQueryParams(ps, params); 471 } 472 473 _rs = ps.executeQuery(); 474 if(_rs.next()) { 475 _pk = getPKFromResultSet(_rs); 476 } 477 _rs.close(); 478 } catch (SQLException se) { 479 throw new PersistenceDatabaseException(se); 480 } finally { 481 if(_rs != null) { 482 try { 483 _rs.close(); 484 } catch (SQLException se) { 485 // do nothing 486 } 487 } 488 } 489 490 return _pk; 491 } 492 493 public java.util.List<OrderLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 494 throws PersistenceDatabaseException { 495 PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission)); 496 497 return getEntitiesFromQuery(session, entityPermission, ps, params); 498 } 499 500 public java.util.List<OrderLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 501 throws PersistenceDatabaseException { 502 Session session = ThreadSession.currentSession(); 503 PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission)); 504 505 return getEntitiesFromQuery(session, entityPermission, ps, params); 506 } 507 508 public java.util.List<OrderLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 509 throws PersistenceDatabaseException { 510 PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission)); 511 512 return getEntitiesFromQuery(session, entityPermission, ps); 513 } 514 515 public java.util.List<OrderLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 516 throws PersistenceDatabaseException { 517 Session session = ThreadSession.currentSession(); 518 PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission)); 519 520 return getEntitiesFromQuery(session, entityPermission, ps); 521 } 522 523 public java.util.List<OrderLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps) 524 throws PersistenceDatabaseException { 525 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps); 526 } 527 528 public java.util.List<OrderLineDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 529 throws PersistenceDatabaseException { 530 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 531 } 532 533 public java.util.List<OrderLineDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 534 throws PersistenceDatabaseException { 535 java.util.List<OrderLineDetail> _entities; 536 ResultSet _rs = null; 537 538 try { 539 if(params.length != 0) { 540 Session.setQueryParams(ps, params); 541 } 542 543 _rs = ps.executeQuery(); 544 _entities = getEntitiesFromResultSet(session, entityPermission, _rs); 545 _rs.close(); 546 } catch (SQLException se) { 547 throw new PersistenceDatabaseException(se); 548 } finally { 549 if(_rs != null) { 550 try { 551 _rs.close(); 552 } catch (SQLException se) { 553 // do nothing 554 } 555 } 556 } 557 558 return _entities; 559 } 560 561 public OrderLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 562 throws PersistenceDatabaseException { 563 PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission)); 564 565 return getEntityFromQuery(session, entityPermission, ps, params); 566 } 567 568 public OrderLineDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 569 throws PersistenceDatabaseException { 570 Session session = ThreadSession.currentSession(); 571 PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission)); 572 573 return getEntityFromQuery(session, entityPermission, ps, params); 574 } 575 576 public OrderLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 577 throws PersistenceDatabaseException { 578 PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission)); 579 580 return getEntityFromQuery(session, entityPermission, ps); 581 } 582 583 public OrderLineDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 584 throws PersistenceDatabaseException { 585 Session session = ThreadSession.currentSession(); 586 PreparedStatement ps = session.prepareStatement(OrderLineDetailFactory.class, queryMap.get(entityPermission)); 587 588 return getEntityFromQuery(session, entityPermission, ps); 589 } 590 591 public OrderLineDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps) 592 throws PersistenceDatabaseException { 593 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps); 594 } 595 596 public OrderLineDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 597 throws PersistenceDatabaseException { 598 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 599 } 600 601 public OrderLineDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 602 throws PersistenceDatabaseException { 603 OrderLineDetail _entity = null; 604 ResultSet _rs = null; 605 606 try { 607 if(params.length != 0) { 608 Session.setQueryParams(ps, params); 609 } 610 611 _rs = ps.executeQuery(); 612 if(_rs.next()) { 613 _entity = getEntityFromResultSet(session, entityPermission, _rs); 614 } 615 _rs.close(); 616 } catch (SQLException se) { 617 throw new PersistenceDatabaseException(se); 618 } finally { 619 if(_rs != null) { 620 try { 621 _rs.close(); 622 } catch (SQLException se) { 623 // do nothing 624 } 625 } 626 } 627 628 return _entity; 629 } 630 631 public java.util.List<OrderLineDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 632 throws PersistenceDatabaseException { 633 return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 634 } 635 636 public java.util.List<OrderLineDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 637 throws PersistenceDatabaseException { 638 java.util.List<OrderLineDetail> _result = new ArrayList<>(); 639 640 try { 641 while(rs.next()) { 642 _result.add(getEntityFromResultSet(session, entityPermission, rs)); 643 } 644 } catch (SQLException se) { 645 throw new PersistenceDatabaseException(se); 646 } 647 648 return _result; 649 } 650 651 public OrderLineDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 652 throws PersistenceDatabaseException { 653 return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 654 } 655 656 public OrderLineDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 657 throws PersistenceDatabaseException { 658 OrderLineDetail _entity; 659 660 try { 661 Long ordldt_orderlinedetailid = rs.getLong(ORDLDT_ORDERLINEDETAILID); 662 OrderLineDetailPK _pk = new OrderLineDetailPK(ordldt_orderlinedetailid); 663 664 // See if we already have the entity in the session cache 665 _entity = (OrderLineDetail)session.getEntity(_pk); 666 if(_entity != null) { 667 // If the requested permission is READ_WRITE, and the cached permission is 668 // READ_ONLY, then pretend that the cached object wasn't found, and create 669 // a new entity that is READ_WRITE. 670 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 671 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 672 _entity = null; 673 } 674 } 675 boolean foundInSessionCache = _entity != null; 676 677 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 678 _entity = getEntityFromCache(session, _pk); 679 } 680 681 if(_entity == null) { 682 Long ordldt_ordl_orderlineid = rs.getLong(ORDLDT_ORDL_ORDERLINEID); 683 if(rs.wasNull()) 684 ordldt_ordl_orderlineid = null; 685 686 Long ordldt_ord_orderid = rs.getLong(ORDLDT_ORD_ORDERID); 687 if(rs.wasNull()) 688 ordldt_ord_orderid = null; 689 690 Integer ordldt_orderlinesequence = rs.getInt(ORDLDT_ORDERLINESEQUENCE); 691 if(rs.wasNull()) 692 ordldt_orderlinesequence = null; 693 694 Long ordldt_parentorderlineid = rs.getLong(ORDLDT_PARENTORDERLINEID); 695 if(rs.wasNull()) 696 ordldt_parentorderlineid = null; 697 698 Long ordldt_ordshpgrp_ordershipmentgroupid = rs.getLong(ORDLDT_ORDSHPGRP_ORDERSHIPMENTGROUPID); 699 if(rs.wasNull()) 700 ordldt_ordshpgrp_ordershipmentgroupid = null; 701 702 Long ordldt_itm_itemid = rs.getLong(ORDLDT_ITM_ITEMID); 703 if(rs.wasNull()) 704 ordldt_itm_itemid = null; 705 706 Long ordldt_invcon_inventoryconditionid = rs.getLong(ORDLDT_INVCON_INVENTORYCONDITIONID); 707 if(rs.wasNull()) 708 ordldt_invcon_inventoryconditionid = null; 709 710 Long ordldt_uomt_unitofmeasuretypeid = rs.getLong(ORDLDT_UOMT_UNITOFMEASURETYPEID); 711 if(rs.wasNull()) 712 ordldt_uomt_unitofmeasuretypeid = null; 713 714 Long ordldt_quantity = rs.getLong(ORDLDT_QUANTITY); 715 if(rs.wasNull()) 716 ordldt_quantity = null; 717 718 Long ordldt_unitamount = rs.getLong(ORDLDT_UNITAMOUNT); 719 if(rs.wasNull()) 720 ordldt_unitamount = null; 721 722 String ordldt_description = rs.getString(ORDLDT_DESCRIPTION); 723 if(rs.wasNull()) 724 ordldt_description = null; 725 726 Long ordldt_cnclplcy_cancellationpolicyid = rs.getLong(ORDLDT_CNCLPLCY_CANCELLATIONPOLICYID); 727 if(rs.wasNull()) 728 ordldt_cnclplcy_cancellationpolicyid = null; 729 730 Long ordldt_rtnplcy_returnpolicyid = rs.getLong(ORDLDT_RTNPLCY_RETURNPOLICYID); 731 if(rs.wasNull()) 732 ordldt_rtnplcy_returnpolicyid = null; 733 734 Boolean ordldt_taxable = rs.getInt(ORDLDT_TAXABLE) == 1; 735 if(rs.wasNull()) 736 ordldt_taxable = null; 737 738 Long ordldt_fromtime = rs.getLong(ORDLDT_FROMTIME); 739 if(rs.wasNull()) 740 ordldt_fromtime = null; 741 742 Long ordldt_thrutime = rs.getLong(ORDLDT_THRUTIME); 743 if(rs.wasNull()) 744 ordldt_thrutime = null; 745 746 OrderLineDetailValue _value = new OrderLineDetailValue(_pk, ordldt_ordl_orderlineid == null? null: new OrderLinePK(ordldt_ordl_orderlineid), ordldt_ord_orderid == null? null: new OrderPK(ordldt_ord_orderid), ordldt_orderlinesequence, ordldt_parentorderlineid == null? null: new OrderLinePK(ordldt_parentorderlineid), ordldt_ordshpgrp_ordershipmentgroupid == null? null: new OrderShipmentGroupPK(ordldt_ordshpgrp_ordershipmentgroupid), ordldt_itm_itemid == null? null: new ItemPK(ordldt_itm_itemid), ordldt_invcon_inventoryconditionid == null? null: new InventoryConditionPK(ordldt_invcon_inventoryconditionid), ordldt_uomt_unitofmeasuretypeid == null? null: new UnitOfMeasureTypePK(ordldt_uomt_unitofmeasuretypeid), ordldt_quantity, ordldt_unitamount, ordldt_description, ordldt_cnclplcy_cancellationpolicyid == null? null: new CancellationPolicyPK(ordldt_cnclplcy_cancellationpolicyid), ordldt_rtnplcy_returnpolicyid == null? null: new ReturnPolicyPK(ordldt_rtnplcy_returnpolicyid), ordldt_taxable, ordldt_fromtime, ordldt_thrutime); 747 _entity = new OrderLineDetail(_value, entityPermission); 748 } 749 750 if(!foundInSessionCache) { 751 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 752 session.putReadOnlyEntity(_pk, _entity); 753 session.getValueCache().put(_entity.getOrderLineDetailValue()); 754 } else { 755 session.putReadWriteEntity(_pk, _entity); 756 } 757 } 758 } catch (SQLException se) { 759 throw new PersistenceDatabaseException(se); 760 } 761 762 return _entity; 763 } 764 765 public OrderLineDetail create(Session session, OrderLine orderLine, Order order, Integer orderLineSequence, OrderLine parentOrderLine, OrderShipmentGroup orderShipmentGroup, Item item, InventoryCondition inventoryCondition, UnitOfMeasureType unitOfMeasureType, Long quantity, Long unitAmount, String description, CancellationPolicy cancellationPolicy, ReturnPolicy returnPolicy, Boolean taxable, Long fromTime, Long thruTime) 766 throws PersistenceDatabaseException, PersistenceNotNullException { 767 return create(session, orderLine == null ? null : orderLine.getPrimaryKey(), order == null ? null : order.getPrimaryKey(), orderLineSequence, parentOrderLine == null ? null : parentOrderLine.getPrimaryKey(), orderShipmentGroup == null ? null : orderShipmentGroup.getPrimaryKey(), item == null ? null : item.getPrimaryKey(), inventoryCondition == null ? null : inventoryCondition.getPrimaryKey(), unitOfMeasureType == null ? null : unitOfMeasureType.getPrimaryKey(), quantity, unitAmount, description, cancellationPolicy == null ? null : cancellationPolicy.getPrimaryKey(), returnPolicy == null ? null : returnPolicy.getPrimaryKey(), taxable, fromTime, thruTime); 768 } 769 770 public OrderLineDetail create(OrderLine orderLine, Order order, Integer orderLineSequence, OrderLine parentOrderLine, OrderShipmentGroup orderShipmentGroup, Item item, InventoryCondition inventoryCondition, UnitOfMeasureType unitOfMeasureType, Long quantity, Long unitAmount, String description, CancellationPolicy cancellationPolicy, ReturnPolicy returnPolicy, Boolean taxable, Long fromTime, Long thruTime) 771 throws PersistenceDatabaseException, PersistenceNotNullException { 772 return create(ThreadSession.currentSession(), orderLine == null ? null : orderLine.getPrimaryKey(), order == null ? null : order.getPrimaryKey(), orderLineSequence, parentOrderLine == null ? null : parentOrderLine.getPrimaryKey(), orderShipmentGroup == null ? null : orderShipmentGroup.getPrimaryKey(), item == null ? null : item.getPrimaryKey(), inventoryCondition == null ? null : inventoryCondition.getPrimaryKey(), unitOfMeasureType == null ? null : unitOfMeasureType.getPrimaryKey(), quantity, unitAmount, description, cancellationPolicy == null ? null : cancellationPolicy.getPrimaryKey(), returnPolicy == null ? null : returnPolicy.getPrimaryKey(), taxable, fromTime, thruTime); 773 } 774 775 private void bindForCreate(PreparedStatement _ps, OrderLineDetailValue _value) 776 throws SQLException { 777 _ps.setLong(1, _value.getEntityId()); 778 779 OrderLinePK ordldt_ordl_orderlineid = _value.getOrderLinePK(); 780 if(ordldt_ordl_orderlineid == null) 781 _ps.setNull(2, Types.BIGINT); 782 else 783 _ps.setLong(2, ordldt_ordl_orderlineid.getEntityId()); 784 785 OrderPK ordldt_ord_orderid = _value.getOrderPK(); 786 if(ordldt_ord_orderid == null) 787 _ps.setNull(3, Types.BIGINT); 788 else 789 _ps.setLong(3, ordldt_ord_orderid.getEntityId()); 790 791 Integer ordldt_orderlinesequence = _value.getOrderLineSequence(); 792 if(ordldt_orderlinesequence == null) 793 _ps.setNull(4, Types.INTEGER); 794 else 795 _ps.setInt(4, ordldt_orderlinesequence); 796 797 OrderLinePK ordldt_parentorderlineid = _value.getParentOrderLinePK(); 798 if(ordldt_parentorderlineid == null) 799 _ps.setNull(5, Types.BIGINT); 800 else 801 _ps.setLong(5, ordldt_parentorderlineid.getEntityId()); 802 803 OrderShipmentGroupPK ordldt_ordshpgrp_ordershipmentgroupid = _value.getOrderShipmentGroupPK(); 804 if(ordldt_ordshpgrp_ordershipmentgroupid == null) 805 _ps.setNull(6, Types.BIGINT); 806 else 807 _ps.setLong(6, ordldt_ordshpgrp_ordershipmentgroupid.getEntityId()); 808 809 ItemPK ordldt_itm_itemid = _value.getItemPK(); 810 if(ordldt_itm_itemid == null) 811 _ps.setNull(7, Types.BIGINT); 812 else 813 _ps.setLong(7, ordldt_itm_itemid.getEntityId()); 814 815 InventoryConditionPK ordldt_invcon_inventoryconditionid = _value.getInventoryConditionPK(); 816 if(ordldt_invcon_inventoryconditionid == null) 817 _ps.setNull(8, Types.BIGINT); 818 else 819 _ps.setLong(8, ordldt_invcon_inventoryconditionid.getEntityId()); 820 821 UnitOfMeasureTypePK ordldt_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK(); 822 if(ordldt_uomt_unitofmeasuretypeid == null) 823 _ps.setNull(9, Types.BIGINT); 824 else 825 _ps.setLong(9, ordldt_uomt_unitofmeasuretypeid.getEntityId()); 826 827 Long ordldt_quantity = _value.getQuantity(); 828 if(ordldt_quantity == null) 829 _ps.setNull(10, Types.BIGINT); 830 else 831 _ps.setLong(10, ordldt_quantity); 832 833 Long ordldt_unitamount = _value.getUnitAmount(); 834 if(ordldt_unitamount == null) 835 _ps.setNull(11, Types.BIGINT); 836 else 837 _ps.setLong(11, ordldt_unitamount); 838 839 String ordldt_description = _value.getDescription(); 840 if(ordldt_description == null) 841 _ps.setNull(12, Types.VARCHAR); 842 else 843 _ps.setString(12, ordldt_description); 844 845 CancellationPolicyPK ordldt_cnclplcy_cancellationpolicyid = _value.getCancellationPolicyPK(); 846 if(ordldt_cnclplcy_cancellationpolicyid == null) 847 _ps.setNull(13, Types.BIGINT); 848 else 849 _ps.setLong(13, ordldt_cnclplcy_cancellationpolicyid.getEntityId()); 850 851 ReturnPolicyPK ordldt_rtnplcy_returnpolicyid = _value.getReturnPolicyPK(); 852 if(ordldt_rtnplcy_returnpolicyid == null) 853 _ps.setNull(14, Types.BIGINT); 854 else 855 _ps.setLong(14, ordldt_rtnplcy_returnpolicyid.getEntityId()); 856 857 Boolean ordldt_taxable = _value.getTaxable(); 858 if(ordldt_taxable == null) 859 _ps.setNull(15, Types.BIT); 860 else 861 _ps.setInt(15, ordldt_taxable? 1: 0); 862 863 Long ordldt_fromtime = _value.getFromTime(); 864 if(ordldt_fromtime == null) 865 _ps.setNull(16, Types.BIGINT); 866 else 867 _ps.setLong(16, ordldt_fromtime); 868 869 Long ordldt_thrutime = _value.getThruTime(); 870 if(ordldt_thrutime == null) 871 _ps.setNull(17, Types.BIGINT); 872 else 873 _ps.setLong(17, ordldt_thrutime); 874 875 } 876 877 public OrderLineDetail create(Session session, OrderLinePK orderLinePK, OrderPK orderPK, Integer orderLineSequence, OrderLinePK parentOrderLinePK, OrderShipmentGroupPK orderShipmentGroupPK, ItemPK itemPK, InventoryConditionPK inventoryConditionPK, UnitOfMeasureTypePK unitOfMeasureTypePK, Long quantity, Long unitAmount, String description, CancellationPolicyPK cancellationPolicyPK, ReturnPolicyPK returnPolicyPK, Boolean taxable, Long fromTime, Long thruTime) 878 throws PersistenceDatabaseException, PersistenceNotNullException { 879 OrderLineDetailPK _pk = getNextPK(); 880 OrderLineDetailValue _value = new OrderLineDetailValue(_pk, orderLinePK, orderPK, orderLineSequence, parentOrderLinePK, orderShipmentGroupPK, itemPK, inventoryConditionPK, unitOfMeasureTypePK, quantity, unitAmount, description, cancellationPolicyPK, returnPolicyPK, taxable, fromTime, thruTime); 881 882 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 883 884 try { 885 bindForCreate(_ps, _value); 886 887 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 888 int _count = _ps.executeUpdate(); 889 890 if(_count != 1) { 891 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 892 } 893 } else { 894 _ps.executeUpdate(); 895 } 896 897 session.getValueCache().put(_value); 898 } catch (SQLException se) { 899 throw new PersistenceDatabaseException(se); 900 } 901 902 OrderLineDetail _entity = new OrderLineDetail(_value, EntityPermission.READ_ONLY); 903 session.putReadOnlyEntity(_pk, _entity); 904 905 return _entity; 906 } 907 908 public OrderLineDetail create(OrderLinePK orderLinePK, OrderPK orderPK, Integer orderLineSequence, OrderLinePK parentOrderLinePK, OrderShipmentGroupPK orderShipmentGroupPK, ItemPK itemPK, InventoryConditionPK inventoryConditionPK, UnitOfMeasureTypePK unitOfMeasureTypePK, Long quantity, Long unitAmount, String description, CancellationPolicyPK cancellationPolicyPK, ReturnPolicyPK returnPolicyPK, Boolean taxable, Long fromTime, Long thruTime) 909 throws PersistenceDatabaseException, PersistenceNotNullException { 910 return create(ThreadSession.currentSession(), orderLinePK, orderPK, orderLineSequence, parentOrderLinePK, orderShipmentGroupPK, itemPK, inventoryConditionPK, unitOfMeasureTypePK, quantity, unitAmount, description, cancellationPolicyPK, returnPolicyPK, taxable, fromTime, thruTime); 911 } 912 913 public void create(Session session, Collection<OrderLineDetailValue> _values) 914 throws PersistenceDatabaseException, PersistenceNotNullException { 915 int _size = _values.size(); 916 917 if(_size > 0) { 918 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 919 List<OrderLineDetailValue> _cacheValues = new ArrayList<>(_size); 920 921 try { 922 for(OrderLineDetailValue _value : _values) { 923 _value.setEntityId(entityIdGenerator.getNextEntityId()); 924 bindForCreate(_ps, _value); 925 926 _ps.addBatch(); 927 928 _cacheValues.add(_value); 929 } 930 931 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 932 int[] _counts = _ps.executeBatch(); 933 934 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 935 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 936 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 937 } 938 } 939 } else { 940 _ps.executeBatch(); 941 } 942 943 _ps.clearBatch(); 944 } catch (SQLException se) { 945 throw new PersistenceDatabaseException(se); 946 } 947 948 _cacheValues.forEach((_cacheValue) -> { 949 OrderLineDetail _cacheEntity = new OrderLineDetail(_cacheValue, EntityPermission.READ_ONLY); 950 951 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 952 }); 953 } 954 } 955 956 public void create(Collection<OrderLineDetailValue> _values) 957 throws PersistenceDatabaseException, PersistenceNotNullException { 958 create(ThreadSession.currentSession(), _values); 959 } 960 961 private boolean bindForStore(PreparedStatement _ps, OrderLineDetailValue _value) 962 throws SQLException { 963 boolean _hasBeenModified = _value.hasBeenModified(); 964 965 if(_hasBeenModified) { 966 OrderLinePK ordldt_ordl_orderlineid = _value.getOrderLinePK(); 967 if(ordldt_ordl_orderlineid == null) 968 _ps.setNull(1, Types.BIGINT); 969 else 970 _ps.setLong(1, ordldt_ordl_orderlineid.getEntityId()); 971 972 OrderPK ordldt_ord_orderid = _value.getOrderPK(); 973 if(ordldt_ord_orderid == null) 974 _ps.setNull(2, Types.BIGINT); 975 else 976 _ps.setLong(2, ordldt_ord_orderid.getEntityId()); 977 978 Integer ordldt_orderlinesequence = _value.getOrderLineSequence(); 979 if(ordldt_orderlinesequence == null) 980 _ps.setNull(3, Types.INTEGER); 981 else 982 _ps.setInt(3, ordldt_orderlinesequence); 983 984 OrderLinePK ordldt_parentorderlineid = _value.getParentOrderLinePK(); 985 if(ordldt_parentorderlineid == null) 986 _ps.setNull(4, Types.BIGINT); 987 else 988 _ps.setLong(4, ordldt_parentorderlineid.getEntityId()); 989 990 OrderShipmentGroupPK ordldt_ordshpgrp_ordershipmentgroupid = _value.getOrderShipmentGroupPK(); 991 if(ordldt_ordshpgrp_ordershipmentgroupid == null) 992 _ps.setNull(5, Types.BIGINT); 993 else 994 _ps.setLong(5, ordldt_ordshpgrp_ordershipmentgroupid.getEntityId()); 995 996 ItemPK ordldt_itm_itemid = _value.getItemPK(); 997 if(ordldt_itm_itemid == null) 998 _ps.setNull(6, Types.BIGINT); 999 else 1000 _ps.setLong(6, ordldt_itm_itemid.getEntityId()); 1001 1002 InventoryConditionPK ordldt_invcon_inventoryconditionid = _value.getInventoryConditionPK(); 1003 if(ordldt_invcon_inventoryconditionid == null) 1004 _ps.setNull(7, Types.BIGINT); 1005 else 1006 _ps.setLong(7, ordldt_invcon_inventoryconditionid.getEntityId()); 1007 1008 UnitOfMeasureTypePK ordldt_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK(); 1009 if(ordldt_uomt_unitofmeasuretypeid == null) 1010 _ps.setNull(8, Types.BIGINT); 1011 else 1012 _ps.setLong(8, ordldt_uomt_unitofmeasuretypeid.getEntityId()); 1013 1014 Long ordldt_quantity = _value.getQuantity(); 1015 if(ordldt_quantity == null) 1016 _ps.setNull(9, Types.BIGINT); 1017 else 1018 _ps.setLong(9, ordldt_quantity); 1019 1020 Long ordldt_unitamount = _value.getUnitAmount(); 1021 if(ordldt_unitamount == null) 1022 _ps.setNull(10, Types.BIGINT); 1023 else 1024 _ps.setLong(10, ordldt_unitamount); 1025 1026 String ordldt_description = _value.getDescription(); 1027 if(ordldt_description == null) 1028 _ps.setNull(11, Types.VARCHAR); 1029 else 1030 _ps.setString(11, ordldt_description); 1031 1032 CancellationPolicyPK ordldt_cnclplcy_cancellationpolicyid = _value.getCancellationPolicyPK(); 1033 if(ordldt_cnclplcy_cancellationpolicyid == null) 1034 _ps.setNull(12, Types.BIGINT); 1035 else 1036 _ps.setLong(12, ordldt_cnclplcy_cancellationpolicyid.getEntityId()); 1037 1038 ReturnPolicyPK ordldt_rtnplcy_returnpolicyid = _value.getReturnPolicyPK(); 1039 if(ordldt_rtnplcy_returnpolicyid == null) 1040 _ps.setNull(13, Types.BIGINT); 1041 else 1042 _ps.setLong(13, ordldt_rtnplcy_returnpolicyid.getEntityId()); 1043 1044 Boolean ordldt_taxable = _value.getTaxable(); 1045 if(ordldt_taxable == null) 1046 _ps.setNull(14, Types.BIT); 1047 else 1048 _ps.setInt(14, ordldt_taxable? 1: 0); 1049 1050 Long ordldt_fromtime = _value.getFromTime(); 1051 if(ordldt_fromtime == null) 1052 _ps.setNull(15, Types.BIGINT); 1053 else 1054 _ps.setLong(15, ordldt_fromtime); 1055 1056 Long ordldt_thrutime = _value.getThruTime(); 1057 if(ordldt_thrutime == null) 1058 _ps.setNull(16, Types.BIGINT); 1059 else 1060 _ps.setLong(16, ordldt_thrutime); 1061 1062 _ps.setLong(17, _value.getPrimaryKey().getEntityId()); 1063 1064 _value.clearHasBeenModified(); 1065 } 1066 1067 return _hasBeenModified; 1068 } 1069 1070 @Override 1071 public void store(Session session, OrderLineDetail entity) 1072 throws PersistenceDatabaseException { 1073 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 1074 1075 try { 1076 OrderLineDetailValue _value = entity.getOrderLineDetailValue(); 1077 1078 if(bindForStore(_ps, _value)) { 1079 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 1080 int _count = _ps.executeUpdate(); 1081 1082 if(_count != 1) { 1083 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 1084 } 1085 } else { 1086 _ps.executeUpdate(); 1087 } 1088 1089 session.getValueCache().put(_value); 1090 } 1091 } catch (SQLException se) { 1092 throw new PersistenceDatabaseException(se); 1093 } 1094 } 1095 1096 @Override 1097 public void store(Session session, Collection<OrderLineDetail> entities) 1098 throws PersistenceDatabaseException { 1099 if(entities.size() > 0) { 1100 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 1101 int _modifiedEntities = 0; 1102 1103 try { 1104 for(OrderLineDetail entity : entities) { 1105 if(bindForStore(_ps, entity.getOrderLineDetailValue())) { 1106 _ps.addBatch(); 1107 _modifiedEntities++; 1108 } 1109 } 1110 1111 if(_modifiedEntities != 0) { 1112 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 1113 int[] _counts = _ps.executeBatch(); 1114 1115 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1116 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1117 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1118 } 1119 } 1120 } else { 1121 _ps.executeBatch(); 1122 } 1123 1124 _ps.clearBatch(); 1125 1126 entities.forEach((entity) -> { 1127 session.getValueCache().put(entity.getOrderLineDetailValue()); 1128 }); 1129 } 1130 } catch (SQLException se) { 1131 throw new PersistenceDatabaseException(se); 1132 } 1133 } 1134 } 1135 1136 @Override 1137 public void store(Collection<OrderLineDetail> entities) 1138 throws PersistenceDatabaseException { 1139 store(ThreadSession.currentSession(), entities); 1140 } 1141 1142 @Override 1143 public void remove(Session session, OrderLineDetail entity) 1144 throws PersistenceDatabaseException { 1145 remove(session, entity.getPrimaryKey()); 1146 } 1147 1148 @Override 1149 public void remove(Session session, OrderLineDetailPK pk) 1150 throws PersistenceDatabaseException { 1151 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1152 long _entityId = pk.getEntityId(); 1153 1154 try { 1155 _ps.setLong(1, _entityId); 1156 1157 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1158 int _count = _ps.executeUpdate(); 1159 1160 if(_count != 1) { 1161 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 1162 } 1163 } else { 1164 _ps.executeUpdate(); 1165 } 1166 1167 session.getValueCache().remove(pk); 1168 } catch (SQLException se) { 1169 throw new PersistenceDatabaseException(se); 1170 } 1171 1172 session.removed(pk, false); 1173 } 1174 1175 @Override 1176 public void remove(Session session, Collection<OrderLineDetailPK> pks) 1177 throws PersistenceDatabaseException { 1178 if(pks.size() > 0) { 1179 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1180 int _modifiedEntities = 0; 1181 1182 try { 1183 for(OrderLineDetailPK pk : pks) { 1184 long _entityId = pk.getEntityId(); 1185 1186 _ps.setLong(1, _entityId); 1187 1188 _ps.addBatch(); 1189 _modifiedEntities++; 1190 } 1191 1192 if(_modifiedEntities != 0) { 1193 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1194 int[] _counts = _ps.executeBatch(); 1195 1196 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1197 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1198 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1199 } 1200 } 1201 } else { 1202 _ps.executeBatch(); 1203 } 1204 1205 _ps.clearBatch(); 1206 1207 pks.forEach((pk) -> { 1208 session.getValueCache().remove(pk); 1209 }); 1210 } 1211 } catch (SQLException se) { 1212 throw new PersistenceDatabaseException(se); 1213 } 1214 1215 pks.forEach((pk) -> { 1216 session.removed(pk, true); 1217 }); 1218 } 1219 } 1220 1221 @Override 1222 public void remove(Collection<OrderLineDetailPK> pks) 1223 throws PersistenceDatabaseException { 1224 remove(ThreadSession.currentSession(), pks); 1225 } 1226 1227 @Override 1228 public boolean validPK(Session session, OrderLineDetailPK pk) 1229 throws PersistenceDatabaseException { 1230 boolean valid = false; 1231 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1232 ResultSet _rs = null; 1233 1234 try { 1235 _ps.setLong(1, pk.getEntityId()); 1236 1237 _rs = _ps.executeQuery(); 1238 if(_rs.next()) { 1239 long _count = _rs.getLong(1); 1240 if(_rs.wasNull()) 1241 _count = 0; 1242 1243 if(_count == 1) 1244 valid = true; 1245 } 1246 } catch (SQLException se) { 1247 throw new PersistenceDatabaseException(se); 1248 } finally { 1249 if(_rs != null) { 1250 try { 1251 _rs.close(); 1252 } catch (SQLException se) { 1253 // do nothing 1254 } 1255 } 1256 } 1257 1258 return valid; 1259 } 1260 1261}