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