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