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