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