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