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