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