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 * InvoiceLineItemFactory.java 021 */ 022 023package com.echothree.model.data.invoice.server.factory; 024 025import com.echothree.model.data.invoice.common.pk.InvoiceLinePK; 026import com.echothree.model.data.item.common.pk.ItemPK; 027import com.echothree.model.data.inventory.common.pk.InventoryConditionPK; 028import com.echothree.model.data.uom.common.pk.UnitOfMeasureTypePK; 029 030import com.echothree.model.data.invoice.server.entity.InvoiceLine; 031import com.echothree.model.data.item.server.entity.Item; 032import com.echothree.model.data.inventory.server.entity.InventoryCondition; 033import com.echothree.model.data.uom.server.entity.UnitOfMeasureType; 034 035import com.echothree.model.data.invoice.common.InvoiceLineItemConstants; 036import com.echothree.model.data.invoice.common.pk.InvoiceLineItemPK; 037import com.echothree.model.data.invoice.server.value.InvoiceLineItemValue; 038import com.echothree.model.data.invoice.server.entity.InvoiceLineItem; 039import com.echothree.util.common.exception.PersistenceDatabaseException; 040import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 041import com.echothree.util.common.exception.PersistenceNotNullException; 042import com.echothree.util.server.persistence.BaseFactory; 043import com.echothree.util.server.persistence.EntityIdGenerator; 044import com.echothree.util.server.persistence.EntityPermission; 045import com.echothree.util.server.persistence.PersistenceDebugFlags; 046import com.echothree.util.server.persistence.Session; 047import java.sql.PreparedStatement; 048import java.sql.ResultSet; 049import java.sql.SQLException; 050import java.sql.Types; 051import java.io.ByteArrayInputStream; 052import java.io.StringReader; 053import java.util.ArrayList; 054import java.util.Collection; 055import java.util.HashSet; 056import java.util.List; 057import java.util.Map; 058import java.util.Set; 059import javax.enterprise.context.ApplicationScoped; 060import javax.enterprise.inject.spi.CDI; 061import javax.inject.Inject; 062import org.jooq.ResultQuery; 063import org.slf4j.Logger; 064import org.slf4j.LoggerFactory; 065 066@ApplicationScoped 067public class InvoiceLineItemFactory 068 implements BaseFactory<InvoiceLineItemPK, InvoiceLineItem> { 069 070 @Inject 071 Session session; 072 073 //private static final Logger log = LoggerFactory.getLogger(InvoiceLineItemFactory.class); 074 075 final private static String SQL_SELECT_READ_ONLY = "SELECT invclitm_invoicelineitemid, invclitm_invcl_invoicelineid, invclitm_itm_itemid, invclitm_invcon_inventoryconditionid, invclitm_uomt_unitofmeasuretypeid, invclitm_quantity, invclitm_fromtime, invclitm_thrutime FROM invoicelineitems WHERE invclitm_invoicelineitemid = ?"; 076 final private static String SQL_SELECT_READ_WRITE = "SELECT invclitm_invoicelineitemid, invclitm_invcl_invoicelineid, invclitm_itm_itemid, invclitm_invcon_inventoryconditionid, invclitm_uomt_unitofmeasuretypeid, invclitm_quantity, invclitm_fromtime, invclitm_thrutime FROM invoicelineitems WHERE invclitm_invoicelineitemid = ? FOR UPDATE"; 077 final private static String SQL_INSERT = "INSERT INTO invoicelineitems (invclitm_invoicelineitemid, invclitm_invcl_invoicelineid, invclitm_itm_itemid, invclitm_invcon_inventoryconditionid, invclitm_uomt_unitofmeasuretypeid, invclitm_quantity, invclitm_fromtime, invclitm_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; 078 final private static String SQL_UPDATE = "UPDATE invoicelineitems SET invclitm_invcl_invoicelineid = ?, invclitm_itm_itemid = ?, invclitm_invcon_inventoryconditionid = ?, invclitm_uomt_unitofmeasuretypeid = ?, invclitm_quantity = ?, invclitm_fromtime = ?, invclitm_thrutime = ? WHERE invclitm_invoicelineitemid = ?"; 079 final private static String SQL_DELETE = "DELETE FROM invoicelineitems WHERE invclitm_invoicelineitemid = ?"; 080 final private static String SQL_VALID = "SELECT COUNT(*) FROM invoicelineitems WHERE invclitm_invoicelineitemid = ?"; 081 082 final public static String INVCLITM_INVOICELINEITEMID = "invclitm_invoicelineitemid"; 083 final public static String INVCLITM_INVCL_INVOICELINEID = "invclitm_invcl_invoicelineid"; 084 final public static String INVCLITM_ITM_ITEMID = "invclitm_itm_itemid"; 085 final public static String INVCLITM_INVCON_INVENTORYCONDITIONID = "invclitm_invcon_inventoryconditionid"; 086 final public static String INVCLITM_UOMT_UNITOFMEASURETYPEID = "invclitm_uomt_unitofmeasuretypeid"; 087 final public static String INVCLITM_QUANTITY = "invclitm_quantity"; 088 final public static String INVCLITM_FROMTIME = "invclitm_fromtime"; 089 final public static String INVCLITM_THRUTIME = "invclitm_thrutime"; 090 091 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(InvoiceLineItemConstants.COMPONENT_VENDOR_NAME, InvoiceLineItemConstants.ENTITY_TYPE_NAME); 092 093 /** Creates a new instance of InvoiceLineItemFactory */ 094 protected InvoiceLineItemFactory() { 095 super(); 096 } 097 098 public static InvoiceLineItemFactory getInstance() { 099 return CDI.current().select(InvoiceLineItemFactory.class).get(); 100 } 101 102 @Override 103 public String getComponentVendorName() { 104 return InvoiceLineItemConstants.COMPONENT_VENDOR_NAME; 105 } 106 107 @Override 108 public String getEntityTypeName() { 109 return InvoiceLineItemConstants.ENTITY_TYPE_NAME; 110 } 111 112 public PreparedStatement prepareStatement(String query) { 113 return session.prepareStatement(query); 114 } 115 116 public InvoiceLineItemPK getNextPK() { 117 return new InvoiceLineItemPK(entityIdGenerator.getNextEntityId()); 118 } 119 120 public Set<InvoiceLineItemPK> getPKsFromResultSetAsSet(ResultSet rs) 121 throws PersistenceDatabaseException { 122 Set<InvoiceLineItemPK> _result = new HashSet<>(); 123 124 try { 125 while(rs.next()) { 126 _result.add(getPKFromResultSet(rs)); 127 } 128 } catch (SQLException se) { 129 throw new PersistenceDatabaseException(se); 130 } 131 132 return _result; 133 } 134 135 public java.util.List<InvoiceLineItemPK> getPKsFromResultSetAsList(ResultSet rs) 136 throws PersistenceDatabaseException { 137 java.util.List<InvoiceLineItemPK> _result = new ArrayList<>(); 138 139 try { 140 while(rs.next()) { 141 _result.add(getPKFromResultSet(rs)); 142 } 143 } catch (SQLException se) { 144 throw new PersistenceDatabaseException(se); 145 } 146 147 return _result; 148 } 149 150 public InvoiceLineItemPK getPKFromResultSet(ResultSet rs) 151 throws PersistenceDatabaseException { 152 InvoiceLineItemPK _result; 153 154 try { 155 long invclitm_invoicelineitemid = rs.getLong(INVCLITM_INVOICELINEITEMID); 156 Long _entityId = rs.wasNull() ? null : invclitm_invoicelineitemid; 157 158 _result = new InvoiceLineItemPK(_entityId); 159 } catch (SQLException se) { 160 throw new PersistenceDatabaseException(se); 161 } 162 163 return _result; 164 } 165 166 public java.util.List<InvoiceLineItemValue> getValuesFromPKs(Collection<InvoiceLineItemPK> pks) 167 throws PersistenceDatabaseException { 168 java.util.List<InvoiceLineItemValue> _values = new ArrayList<>(pks.size()); 169 170 for(InvoiceLineItemPK _pk: pks) { 171 _values.add(getValueFromPK(_pk)); 172 } 173 174 return _values; 175 } 176 177 public InvoiceLineItemValue getValueFromPK(InvoiceLineItemPK pk) 178 throws PersistenceDatabaseException { 179 InvoiceLineItemValue _value; 180 181 // See if we already have the entity in the session cache 182 InvoiceLineItem _entity = (InvoiceLineItem)session.getEntity(pk); 183 if(_entity == null) 184 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getInvoiceLineItemValue(); 185 else 186 _value = _entity.getInvoiceLineItemValue(); 187 188 return _value; 189 } 190 191 public java.util.List<InvoiceLineItemValue> getValuesFromResultSet(ResultSet rs) 192 throws PersistenceDatabaseException { 193 java.util.List<InvoiceLineItemValue> _result = new ArrayList<>(); 194 195 try { 196 while(rs.next()) { 197 _result.add(getValueFromResultSet(rs)); 198 } 199 } catch (SQLException se) { 200 throw new PersistenceDatabaseException(se); 201 } 202 203 return _result; 204 } 205 206 public InvoiceLineItemValue getValueFromResultSet(ResultSet rs) 207 throws PersistenceDatabaseException { 208 InvoiceLineItemValue _value; 209 210 try { 211 Long invclitm_invoicelineitemid = rs.getLong(INVCLITM_INVOICELINEITEMID); 212 InvoiceLineItemPK _pk = new InvoiceLineItemPK(invclitm_invoicelineitemid); 213 214 // See if we already have the entity in the session cache 215 InvoiceLineItem _entity = (InvoiceLineItem)session.getEntity(_pk); 216 217 if(_entity == null) { 218 Long invclitm_invcl_invoicelineid = rs.getLong(INVCLITM_INVCL_INVOICELINEID); 219 if(rs.wasNull()) 220 invclitm_invcl_invoicelineid = null; 221 222 Long invclitm_itm_itemid = rs.getLong(INVCLITM_ITM_ITEMID); 223 if(rs.wasNull()) 224 invclitm_itm_itemid = null; 225 226 Long invclitm_invcon_inventoryconditionid = rs.getLong(INVCLITM_INVCON_INVENTORYCONDITIONID); 227 if(rs.wasNull()) 228 invclitm_invcon_inventoryconditionid = null; 229 230 Long invclitm_uomt_unitofmeasuretypeid = rs.getLong(INVCLITM_UOMT_UNITOFMEASURETYPEID); 231 if(rs.wasNull()) 232 invclitm_uomt_unitofmeasuretypeid = null; 233 234 Integer invclitm_quantity = rs.getInt(INVCLITM_QUANTITY); 235 if(rs.wasNull()) 236 invclitm_quantity = null; 237 238 Long invclitm_fromtime = rs.getLong(INVCLITM_FROMTIME); 239 if(rs.wasNull()) 240 invclitm_fromtime = null; 241 242 Long invclitm_thrutime = rs.getLong(INVCLITM_THRUTIME); 243 if(rs.wasNull()) 244 invclitm_thrutime = null; 245 246 _value = new InvoiceLineItemValue(_pk, new InvoiceLinePK(invclitm_invcl_invoicelineid), new ItemPK(invclitm_itm_itemid), new InventoryConditionPK(invclitm_invcon_inventoryconditionid), new UnitOfMeasureTypePK(invclitm_uomt_unitofmeasuretypeid), invclitm_quantity, invclitm_fromtime, invclitm_thrutime); 247 } else 248 _value = _entity.getInvoiceLineItemValue(); 249 } catch (SQLException se) { 250 throw new PersistenceDatabaseException(se); 251 } 252 253 return _value; 254 } 255 256 public java.util.List<InvoiceLineItem> getEntitiesFromPKs(EntityPermission entityPermission, Collection<InvoiceLineItemPK> pks) 257 throws PersistenceDatabaseException { 258 java.util.List<InvoiceLineItem> _entities = new ArrayList<>(pks.size()); 259 260 for(InvoiceLineItemPK _pk: pks) { 261 _entities.add(getEntityFromPK(entityPermission, _pk)); 262 } 263 264 return _entities; 265 } 266 267 public InvoiceLineItem getEntityFromValue(EntityPermission entityPermission, InvoiceLineItemValue value) { 268 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 269 } 270 271 public InvoiceLineItem getEntityFromCache(InvoiceLineItemPK pk) { 272 InvoiceLineItemValue _value = (InvoiceLineItemValue)session.getValueCache().get(pk); 273 274 return _value == null ? null : new InvoiceLineItem(_value, EntityPermission.READ_ONLY); 275 } 276 277 public InvoiceLineItem getEntityFromPK(EntityPermission entityPermission, InvoiceLineItemPK pk) 278 throws PersistenceDatabaseException { 279 InvoiceLineItem _entity; 280 281 // See if we already have the entity in the session cache 282 _entity = (InvoiceLineItem)session.getEntity(pk); 283 if(_entity != null) { 284 // If the requested permission is READ_WRITE, and the cached permission is 285 // READ_ONLY, then pretend that the cached object wasn't found, and create 286 // a new entity that is READ_WRITE. 287 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 288 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 289 _entity = null; 290 } 291 } 292 293 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 294 _entity = getEntityFromCache(pk); 295 } 296 297 if(_entity == null) { 298 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 299 long _entityId = pk.getEntityId(); 300 ResultSet _rs = null; 301 302 try { 303 _ps.setLong(1, _entityId); 304 _rs = _ps.executeQuery(); 305 if(_rs.next()) { 306 _entity = getEntityFromResultSet(entityPermission, _rs); 307 } 308 } catch (SQLException se) { 309 throw new PersistenceDatabaseException(se); 310 } finally { 311 if(_rs != null) { 312 try { 313 _rs.close(); 314 } catch (SQLException se) { 315 // do nothing 316 } 317 } 318 } 319 } 320 321 return _entity; 322 } 323 324 public Set<InvoiceLineItemPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 325 throws PersistenceDatabaseException { 326 Set<InvoiceLineItemPK> _pks; 327 ResultSet _rs = null; 328 329 try { 330 if(params.length != 0) { 331 Session.setQueryParams(ps, params); 332 } 333 334 _rs = ps.executeQuery(); 335 _pks = getPKsFromResultSetAsSet(_rs); 336 _rs.close(); 337 } catch (SQLException se) { 338 throw new PersistenceDatabaseException(se); 339 } finally { 340 if(_rs != null) { 341 try { 342 _rs.close(); 343 } catch (SQLException se) { 344 // do nothing 345 } 346 } 347 } 348 349 return _pks; 350 } 351 352 public java.util.List<InvoiceLineItemPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 353 throws PersistenceDatabaseException { 354 java.util.List<InvoiceLineItemPK> _pks; 355 ResultSet _rs = null; 356 357 try { 358 if(params.length != 0) { 359 Session.setQueryParams(ps, params); 360 } 361 362 _rs = ps.executeQuery(); 363 _pks = getPKsFromResultSetAsList(_rs); 364 _rs.close(); 365 } catch (SQLException se) { 366 throw new PersistenceDatabaseException(se); 367 } finally { 368 if(_rs != null) { 369 try { 370 _rs.close(); 371 } catch (SQLException se) { 372 // do nothing 373 } 374 } 375 } 376 377 return _pks; 378 } 379 380 public InvoiceLineItemPK getPKFromQuery(PreparedStatement ps, final Object... params) 381 throws PersistenceDatabaseException { 382 InvoiceLineItemPK _pk = null; 383 ResultSet _rs = null; 384 385 try { 386 if(params.length != 0) { 387 Session.setQueryParams(ps, params); 388 } 389 390 _rs = ps.executeQuery(); 391 if(_rs.next()) { 392 _pk = getPKFromResultSet(_rs); 393 } 394 _rs.close(); 395 } catch (SQLException se) { 396 throw new PersistenceDatabaseException(se); 397 } finally { 398 if(_rs != null) { 399 try { 400 _rs.close(); 401 } catch (SQLException se) { 402 // do nothing 403 } 404 } 405 } 406 407 return _pk; 408 } 409 410 public java.util.List<InvoiceLineItem> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 411 throws PersistenceDatabaseException { 412 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 413 414 return getEntitiesFromQuery(entityPermission, ps, params); 415 } 416 417 public java.util.List<InvoiceLineItem> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 418 throws PersistenceDatabaseException { 419 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 420 421 return getEntitiesFromQuery(entityPermission, ps); 422 } 423 424 public java.util.List<InvoiceLineItem> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 425 throws PersistenceDatabaseException { 426 PreparedStatement ps = session.prepareStatement(query.getSQL()); 427 428 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 429 } 430 431 public java.util.List<InvoiceLineItem> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 432 throws PersistenceDatabaseException { 433 java.util.List<InvoiceLineItem> _entities; 434 ResultSet _rs = null; 435 436 try { 437 if(params.length != 0) { 438 Session.setQueryParams(ps, params); 439 } 440 441 _rs = ps.executeQuery(); 442 _entities = getEntitiesFromResultSet(entityPermission, _rs); 443 _rs.close(); 444 } catch (SQLException se) { 445 throw new PersistenceDatabaseException(se); 446 } finally { 447 if(_rs != null) { 448 try { 449 _rs.close(); 450 } catch (SQLException se) { 451 // do nothing 452 } 453 } 454 } 455 456 return _entities; 457 } 458 459 public InvoiceLineItem getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 460 throws PersistenceDatabaseException { 461 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 462 463 return getEntityFromQuery(entityPermission, ps, params); 464 } 465 466 public InvoiceLineItem getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 467 throws PersistenceDatabaseException { 468 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 469 470 return getEntityFromQuery(entityPermission, ps); 471 } 472 473 public InvoiceLineItem getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 474 throws PersistenceDatabaseException { 475 PreparedStatement ps = session.prepareStatement(query.getSQL()); 476 477 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 478 } 479 480 public InvoiceLineItem getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 481 throws PersistenceDatabaseException { 482 InvoiceLineItem _entity = null; 483 ResultSet _rs = null; 484 485 try { 486 if(params.length != 0) { 487 Session.setQueryParams(ps, params); 488 } 489 490 _rs = ps.executeQuery(); 491 if(_rs.next()) { 492 _entity = getEntityFromResultSet(entityPermission, _rs); 493 } 494 _rs.close(); 495 } catch (SQLException se) { 496 throw new PersistenceDatabaseException(se); 497 } finally { 498 if(_rs != null) { 499 try { 500 _rs.close(); 501 } catch (SQLException se) { 502 // do nothing 503 } 504 } 505 } 506 507 return _entity; 508 } 509 510 public java.util.List<InvoiceLineItem> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 511 throws PersistenceDatabaseException { 512 java.util.List<InvoiceLineItem> _result = new ArrayList<>(); 513 514 try { 515 while(rs.next()) { 516 _result.add(getEntityFromResultSet(entityPermission, rs)); 517 } 518 } catch (SQLException se) { 519 throw new PersistenceDatabaseException(se); 520 } 521 522 return _result; 523 } 524 525 public InvoiceLineItem getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 526 throws PersistenceDatabaseException { 527 InvoiceLineItem _entity; 528 529 try { 530 Long invclitm_invoicelineitemid = rs.getLong(INVCLITM_INVOICELINEITEMID); 531 InvoiceLineItemPK _pk = new InvoiceLineItemPK(invclitm_invoicelineitemid); 532 533 // See if we already have the entity in the session cache 534 _entity = (InvoiceLineItem)session.getEntity(_pk); 535 if(_entity != null) { 536 // If the requested permission is READ_WRITE, and the cached permission is 537 // READ_ONLY, then pretend that the cached object wasn't found, and create 538 // a new entity that is READ_WRITE. 539 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 540 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 541 _entity = null; 542 } 543 } 544 boolean foundInSessionCache = _entity != null; 545 546 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 547 _entity = getEntityFromCache(_pk); 548 } 549 550 if(_entity == null) { 551 Long invclitm_invcl_invoicelineid = rs.getLong(INVCLITM_INVCL_INVOICELINEID); 552 if(rs.wasNull()) 553 invclitm_invcl_invoicelineid = null; 554 555 Long invclitm_itm_itemid = rs.getLong(INVCLITM_ITM_ITEMID); 556 if(rs.wasNull()) 557 invclitm_itm_itemid = null; 558 559 Long invclitm_invcon_inventoryconditionid = rs.getLong(INVCLITM_INVCON_INVENTORYCONDITIONID); 560 if(rs.wasNull()) 561 invclitm_invcon_inventoryconditionid = null; 562 563 Long invclitm_uomt_unitofmeasuretypeid = rs.getLong(INVCLITM_UOMT_UNITOFMEASURETYPEID); 564 if(rs.wasNull()) 565 invclitm_uomt_unitofmeasuretypeid = null; 566 567 Integer invclitm_quantity = rs.getInt(INVCLITM_QUANTITY); 568 if(rs.wasNull()) 569 invclitm_quantity = null; 570 571 Long invclitm_fromtime = rs.getLong(INVCLITM_FROMTIME); 572 if(rs.wasNull()) 573 invclitm_fromtime = null; 574 575 Long invclitm_thrutime = rs.getLong(INVCLITM_THRUTIME); 576 if(rs.wasNull()) 577 invclitm_thrutime = null; 578 579 InvoiceLineItemValue _value = new InvoiceLineItemValue(_pk, invclitm_invcl_invoicelineid == null? null: new InvoiceLinePK(invclitm_invcl_invoicelineid), invclitm_itm_itemid == null? null: new ItemPK(invclitm_itm_itemid), invclitm_invcon_inventoryconditionid == null? null: new InventoryConditionPK(invclitm_invcon_inventoryconditionid), invclitm_uomt_unitofmeasuretypeid == null? null: new UnitOfMeasureTypePK(invclitm_uomt_unitofmeasuretypeid), invclitm_quantity, invclitm_fromtime, invclitm_thrutime); 580 _entity = new InvoiceLineItem(_value, entityPermission); 581 } 582 583 if(!foundInSessionCache) { 584 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 585 session.putReadOnlyEntity(_pk, _entity); 586 session.getValueCache().put(_entity.getInvoiceLineItemValue()); 587 } else { 588 session.putReadWriteEntity(_pk, _entity); 589 } 590 } 591 } catch (SQLException se) { 592 throw new PersistenceDatabaseException(se); 593 } 594 595 return _entity; 596 } 597 598 public InvoiceLineItem create(InvoiceLine invoiceLine, Item item, InventoryCondition inventoryCondition, UnitOfMeasureType unitOfMeasureType, Integer quantity, Long fromTime, Long thruTime) 599 throws PersistenceDatabaseException, PersistenceNotNullException { 600 return create(invoiceLine == null ? null : invoiceLine.getPrimaryKey(), item == null ? null : item.getPrimaryKey(), inventoryCondition == null ? null : inventoryCondition.getPrimaryKey(), unitOfMeasureType == null ? null : unitOfMeasureType.getPrimaryKey(), quantity, fromTime, thruTime); 601 } 602 603 private void bindForCreate(PreparedStatement _ps, InvoiceLineItemValue _value) 604 throws SQLException { 605 _ps.setLong(1, _value.getEntityId()); 606 607 InvoiceLinePK invclitm_invcl_invoicelineid = _value.getInvoiceLinePK(); 608 if(invclitm_invcl_invoicelineid == null) 609 _ps.setNull(2, Types.BIGINT); 610 else 611 _ps.setLong(2, invclitm_invcl_invoicelineid.getEntityId()); 612 613 ItemPK invclitm_itm_itemid = _value.getItemPK(); 614 if(invclitm_itm_itemid == null) 615 _ps.setNull(3, Types.BIGINT); 616 else 617 _ps.setLong(3, invclitm_itm_itemid.getEntityId()); 618 619 InventoryConditionPK invclitm_invcon_inventoryconditionid = _value.getInventoryConditionPK(); 620 if(invclitm_invcon_inventoryconditionid == null) 621 _ps.setNull(4, Types.BIGINT); 622 else 623 _ps.setLong(4, invclitm_invcon_inventoryconditionid.getEntityId()); 624 625 UnitOfMeasureTypePK invclitm_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK(); 626 if(invclitm_uomt_unitofmeasuretypeid == null) 627 _ps.setNull(5, Types.BIGINT); 628 else 629 _ps.setLong(5, invclitm_uomt_unitofmeasuretypeid.getEntityId()); 630 631 Integer invclitm_quantity = _value.getQuantity(); 632 if(invclitm_quantity == null) 633 _ps.setNull(6, Types.INTEGER); 634 else 635 _ps.setInt(6, invclitm_quantity); 636 637 Long invclitm_fromtime = _value.getFromTime(); 638 if(invclitm_fromtime == null) 639 _ps.setNull(7, Types.BIGINT); 640 else 641 _ps.setLong(7, invclitm_fromtime); 642 643 Long invclitm_thrutime = _value.getThruTime(); 644 if(invclitm_thrutime == null) 645 _ps.setNull(8, Types.BIGINT); 646 else 647 _ps.setLong(8, invclitm_thrutime); 648 649 } 650 651 public InvoiceLineItem create(InvoiceLinePK invoiceLinePK, ItemPK itemPK, InventoryConditionPK inventoryConditionPK, UnitOfMeasureTypePK unitOfMeasureTypePK, Integer quantity, Long fromTime, Long thruTime) 652 throws PersistenceDatabaseException, PersistenceNotNullException { 653 InvoiceLineItemPK _pk = getNextPK(); 654 InvoiceLineItemValue _value = new InvoiceLineItemValue(_pk, invoiceLinePK, itemPK, inventoryConditionPK, unitOfMeasureTypePK, quantity, fromTime, thruTime); 655 656 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 657 658 try { 659 bindForCreate(_ps, _value); 660 661 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 662 int _count = _ps.executeUpdate(); 663 664 if(_count != 1) { 665 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 666 } 667 } else { 668 _ps.executeUpdate(); 669 } 670 671 session.getValueCache().put(_value); 672 } catch (SQLException se) { 673 throw new PersistenceDatabaseException(se); 674 } 675 676 InvoiceLineItem _entity = new InvoiceLineItem(_value, EntityPermission.READ_ONLY); 677 session.putReadOnlyEntity(_pk, _entity); 678 679 return _entity; 680 } 681 682 public void create(Collection<InvoiceLineItemValue> _values) 683 throws PersistenceDatabaseException, PersistenceNotNullException { 684 int _size = _values.size(); 685 686 if(_size > 0) { 687 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 688 List<InvoiceLineItemValue> _cacheValues = new ArrayList<>(_size); 689 690 try { 691 for(InvoiceLineItemValue _value : _values) { 692 _value.setEntityId(entityIdGenerator.getNextEntityId()); 693 bindForCreate(_ps, _value); 694 695 _ps.addBatch(); 696 697 _cacheValues.add(_value); 698 } 699 700 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 701 int[] _counts = _ps.executeBatch(); 702 703 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 704 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 705 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 706 } 707 } 708 } else { 709 _ps.executeBatch(); 710 } 711 712 _ps.clearBatch(); 713 } catch (SQLException se) { 714 throw new PersistenceDatabaseException(se); 715 } 716 717 _cacheValues.forEach((_cacheValue) -> { 718 InvoiceLineItem _cacheEntity = new InvoiceLineItem(_cacheValue, EntityPermission.READ_ONLY); 719 720 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 721 }); 722 } 723 } 724 725 private boolean bindForStore(PreparedStatement _ps, InvoiceLineItemValue _value) 726 throws SQLException { 727 boolean _hasBeenModified = _value.hasBeenModified(); 728 729 if(_hasBeenModified) { 730 InvoiceLinePK invclitm_invcl_invoicelineid = _value.getInvoiceLinePK(); 731 if(invclitm_invcl_invoicelineid == null) 732 _ps.setNull(1, Types.BIGINT); 733 else 734 _ps.setLong(1, invclitm_invcl_invoicelineid.getEntityId()); 735 736 ItemPK invclitm_itm_itemid = _value.getItemPK(); 737 if(invclitm_itm_itemid == null) 738 _ps.setNull(2, Types.BIGINT); 739 else 740 _ps.setLong(2, invclitm_itm_itemid.getEntityId()); 741 742 InventoryConditionPK invclitm_invcon_inventoryconditionid = _value.getInventoryConditionPK(); 743 if(invclitm_invcon_inventoryconditionid == null) 744 _ps.setNull(3, Types.BIGINT); 745 else 746 _ps.setLong(3, invclitm_invcon_inventoryconditionid.getEntityId()); 747 748 UnitOfMeasureTypePK invclitm_uomt_unitofmeasuretypeid = _value.getUnitOfMeasureTypePK(); 749 if(invclitm_uomt_unitofmeasuretypeid == null) 750 _ps.setNull(4, Types.BIGINT); 751 else 752 _ps.setLong(4, invclitm_uomt_unitofmeasuretypeid.getEntityId()); 753 754 Integer invclitm_quantity = _value.getQuantity(); 755 if(invclitm_quantity == null) 756 _ps.setNull(5, Types.INTEGER); 757 else 758 _ps.setInt(5, invclitm_quantity); 759 760 Long invclitm_fromtime = _value.getFromTime(); 761 if(invclitm_fromtime == null) 762 _ps.setNull(6, Types.BIGINT); 763 else 764 _ps.setLong(6, invclitm_fromtime); 765 766 Long invclitm_thrutime = _value.getThruTime(); 767 if(invclitm_thrutime == null) 768 _ps.setNull(7, Types.BIGINT); 769 else 770 _ps.setLong(7, invclitm_thrutime); 771 772 _ps.setLong(8, _value.getPrimaryKey().getEntityId()); 773 774 _value.clearHasBeenModified(); 775 } 776 777 return _hasBeenModified; 778 } 779 780 @Override 781 public void store(InvoiceLineItem entity) 782 throws PersistenceDatabaseException { 783 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 784 785 try { 786 InvoiceLineItemValue _value = entity.getInvoiceLineItemValue(); 787 788 if(bindForStore(_ps, _value)) { 789 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 790 int _count = _ps.executeUpdate(); 791 792 if(_count != 1) { 793 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 794 } 795 } else { 796 _ps.executeUpdate(); 797 } 798 799 session.getValueCache().put(_value); 800 } 801 } catch (SQLException se) { 802 throw new PersistenceDatabaseException(se); 803 } 804 } 805 806 @Override 807 public void store(Collection<InvoiceLineItem> entities) 808 throws PersistenceDatabaseException { 809 if(entities.size() > 0) { 810 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 811 int _modifiedEntities = 0; 812 813 try { 814 for(InvoiceLineItem entity : entities) { 815 if(bindForStore(_ps, entity.getInvoiceLineItemValue())) { 816 _ps.addBatch(); 817 _modifiedEntities++; 818 } 819 } 820 821 if(_modifiedEntities != 0) { 822 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 823 int[] _counts = _ps.executeBatch(); 824 825 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 826 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 827 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 828 } 829 } 830 } else { 831 _ps.executeBatch(); 832 } 833 834 _ps.clearBatch(); 835 836 entities.forEach((entity) -> { 837 session.getValueCache().put(entity.getInvoiceLineItemValue()); 838 }); 839 } 840 } catch (SQLException se) { 841 throw new PersistenceDatabaseException(se); 842 } 843 } 844 } 845 846 @Override 847 public void remove(InvoiceLineItem entity) 848 throws PersistenceDatabaseException { 849 remove(entity.getPrimaryKey()); 850 } 851 852 @Override 853 public void remove(InvoiceLineItemPK pk) 854 throws PersistenceDatabaseException { 855 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 856 long _entityId = pk.getEntityId(); 857 858 try { 859 _ps.setLong(1, _entityId); 860 861 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 862 int _count = _ps.executeUpdate(); 863 864 if(_count != 1) { 865 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 866 } 867 } else { 868 _ps.executeUpdate(); 869 } 870 871 session.getValueCache().remove(pk); 872 } catch (SQLException se) { 873 throw new PersistenceDatabaseException(se); 874 } 875 876 session.removed(pk, false); 877 } 878 879 @Override 880 public void remove(Collection<InvoiceLineItemPK> pks) 881 throws PersistenceDatabaseException { 882 if(pks.size() > 0) { 883 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 884 int _modifiedEntities = 0; 885 886 try { 887 for(InvoiceLineItemPK pk : pks) { 888 long _entityId = pk.getEntityId(); 889 890 _ps.setLong(1, _entityId); 891 892 _ps.addBatch(); 893 _modifiedEntities++; 894 } 895 896 if(_modifiedEntities != 0) { 897 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 898 int[] _counts = _ps.executeBatch(); 899 900 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 901 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 902 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 903 } 904 } 905 } else { 906 _ps.executeBatch(); 907 } 908 909 _ps.clearBatch(); 910 911 pks.forEach((pk) -> { 912 session.getValueCache().remove(pk); 913 }); 914 } 915 } catch (SQLException se) { 916 throw new PersistenceDatabaseException(se); 917 } 918 919 pks.forEach((pk) -> { 920 session.removed(pk, true); 921 }); 922 } 923 } 924 925 @Override 926 public boolean validPK(InvoiceLineItemPK pk) 927 throws PersistenceDatabaseException { 928 boolean valid = false; 929 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 930 ResultSet _rs = null; 931 932 try { 933 _ps.setLong(1, pk.getEntityId()); 934 935 _rs = _ps.executeQuery(); 936 if(_rs.next()) { 937 long _count = _rs.getLong(1); 938 if(_rs.wasNull()) 939 _count = 0; 940 941 if(_count == 1) 942 valid = true; 943 } 944 } catch (SQLException se) { 945 throw new PersistenceDatabaseException(se); 946 } finally { 947 if(_rs != null) { 948 try { 949 _rs.close(); 950 } catch (SQLException se) { 951 // do nothing 952 } 953 } 954 } 955 956 return valid; 957 } 958 959}