001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * InvoiceDetailFactory.java 021 */ 022 023package com.echothree.model.data.invoice.server.factory; 024 025import com.echothree.model.data.invoice.common.pk.InvoicePK; 026import com.echothree.model.data.invoice.common.pk.InvoiceTypePK; 027import com.echothree.model.data.payment.common.pk.BillingAccountPK; 028import com.echothree.model.data.accounting.common.pk.GlAccountPK; 029import com.echothree.model.data.term.common.pk.TermPK; 030import com.echothree.model.data.shipment.common.pk.FreeOnBoardPK; 031 032import com.echothree.model.data.invoice.server.entity.Invoice; 033import com.echothree.model.data.invoice.server.entity.InvoiceType; 034import com.echothree.model.data.payment.server.entity.BillingAccount; 035import com.echothree.model.data.accounting.server.entity.GlAccount; 036import com.echothree.model.data.term.server.entity.Term; 037import com.echothree.model.data.shipment.server.entity.FreeOnBoard; 038 039import com.echothree.model.data.invoice.common.InvoiceDetailConstants; 040import com.echothree.model.data.invoice.common.pk.InvoiceDetailPK; 041import com.echothree.model.data.invoice.server.value.InvoiceDetailValue; 042import com.echothree.model.data.invoice.server.entity.InvoiceDetail; 043import com.echothree.util.common.exception.PersistenceDatabaseException; 044import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 045import com.echothree.util.common.exception.PersistenceNotNullException; 046import com.echothree.util.server.persistence.BaseFactory; 047import com.echothree.util.server.persistence.EntityIdGenerator; 048import com.echothree.util.server.persistence.EntityPermission; 049import com.echothree.util.server.persistence.PersistenceDebugFlags; 050import com.echothree.util.server.persistence.Session; 051import com.echothree.util.server.persistence.ThreadSession; 052import java.sql.PreparedStatement; 053import java.sql.ResultSet; 054import java.sql.SQLException; 055import java.sql.Types; 056import java.io.ByteArrayInputStream; 057import java.io.StringReader; 058import java.util.ArrayList; 059import java.util.Collection; 060import java.util.HashSet; 061import java.util.List; 062import java.util.Map; 063import java.util.Set; 064import javax.enterprise.context.ApplicationScoped; 065import javax.enterprise.inject.spi.CDI; 066import org.apache.commons.logging.Log; 067import org.apache.commons.logging.LogFactory; 068 069@ApplicationScoped 070public class InvoiceDetailFactory 071 implements BaseFactory<InvoiceDetailPK, InvoiceDetail> { 072 073 //final private static Log log = LogFactory.getLog(InvoiceDetailFactory.class); 074 075 final private static String SQL_SELECT_READ_ONLY = "SELECT invcdt_invoicedetailid, invcdt_invc_invoiceid, invcdt_invctyp_invoicetypeid, invcdt_invoicename, invcdt_bllact_billingaccountid, invcdt_gla_glaccountid, invcdt_trm_termid, invcdt_fob_freeonboardid, invcdt_reference, invcdt_description, invcdt_fromtime, invcdt_thrutime FROM invoicedetails WHERE invcdt_invoicedetailid = ?"; 076 final private static String SQL_SELECT_READ_WRITE = "SELECT invcdt_invoicedetailid, invcdt_invc_invoiceid, invcdt_invctyp_invoicetypeid, invcdt_invoicename, invcdt_bllact_billingaccountid, invcdt_gla_glaccountid, invcdt_trm_termid, invcdt_fob_freeonboardid, invcdt_reference, invcdt_description, invcdt_fromtime, invcdt_thrutime FROM invoicedetails WHERE invcdt_invoicedetailid = ? FOR UPDATE"; 077 final private static String SQL_INSERT = "INSERT INTO invoicedetails (invcdt_invoicedetailid, invcdt_invc_invoiceid, invcdt_invctyp_invoicetypeid, invcdt_invoicename, invcdt_bllact_billingaccountid, invcdt_gla_glaccountid, invcdt_trm_termid, invcdt_fob_freeonboardid, invcdt_reference, invcdt_description, invcdt_fromtime, invcdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 078 final private static String SQL_UPDATE = "UPDATE invoicedetails SET invcdt_invc_invoiceid = ?, invcdt_invctyp_invoicetypeid = ?, invcdt_invoicename = ?, invcdt_bllact_billingaccountid = ?, invcdt_gla_glaccountid = ?, invcdt_trm_termid = ?, invcdt_fob_freeonboardid = ?, invcdt_reference = ?, invcdt_description = ?, invcdt_fromtime = ?, invcdt_thrutime = ? WHERE invcdt_invoicedetailid = ?"; 079 final private static String SQL_DELETE = "DELETE FROM invoicedetails WHERE invcdt_invoicedetailid = ?"; 080 final private static String SQL_VALID = "SELECT COUNT(*) FROM invoicedetails WHERE invcdt_invoicedetailid = ?"; 081 082 final private static String PK_COLUMN = "invcdt_invoicedetailid"; 083 final private static String ALL_COLUMNS = "invcdt_invoicedetailid, invcdt_invc_invoiceid, invcdt_invctyp_invoicetypeid, invcdt_invoicename, invcdt_bllact_billingaccountid, invcdt_gla_glaccountid, invcdt_trm_termid, invcdt_fob_freeonboardid, invcdt_reference, invcdt_description, invcdt_fromtime, invcdt_thrutime"; 084 final public static String TABLE_NAME = "invoicedetails"; 085 086 final public static String INVCDT_INVOICEDETAILID = "invcdt_invoicedetailid"; 087 final public static String INVCDT_INVC_INVOICEID = "invcdt_invc_invoiceid"; 088 final public static String INVCDT_INVCTYP_INVOICETYPEID = "invcdt_invctyp_invoicetypeid"; 089 final public static String INVCDT_INVOICENAME = "invcdt_invoicename"; 090 final public static String INVCDT_BLLACT_BILLINGACCOUNTID = "invcdt_bllact_billingaccountid"; 091 final public static String INVCDT_GLA_GLACCOUNTID = "invcdt_gla_glaccountid"; 092 final public static String INVCDT_TRM_TERMID = "invcdt_trm_termid"; 093 final public static String INVCDT_FOB_FREEONBOARDID = "invcdt_fob_freeonboardid"; 094 final public static String INVCDT_REFERENCE = "invcdt_reference"; 095 final public static String INVCDT_DESCRIPTION = "invcdt_description"; 096 final public static String INVCDT_FROMTIME = "invcdt_fromtime"; 097 final public static String INVCDT_THRUTIME = "invcdt_thrutime"; 098 099 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(InvoiceDetailConstants.COMPONENT_VENDOR_NAME, InvoiceDetailConstants.ENTITY_TYPE_NAME); 100 101 /** Creates a new instance of InvoiceDetailFactory */ 102 protected InvoiceDetailFactory() { 103 super(); 104 } 105 106 public static InvoiceDetailFactory getInstance() { 107 return CDI.current().select(InvoiceDetailFactory.class).get(); 108 } 109 110 @Override 111 public String getPKColumn() { 112 return PK_COLUMN; 113 } 114 115 @Override 116 public String getAllColumns() { 117 return ALL_COLUMNS; 118 } 119 120 @Override 121 public String getTableName() { 122 return TABLE_NAME; 123 } 124 125 @Override 126 public String getComponentVendorName() { 127 return InvoiceDetailConstants.COMPONENT_VENDOR_NAME; 128 } 129 130 @Override 131 public String getEntityTypeName() { 132 return InvoiceDetailConstants.ENTITY_TYPE_NAME; 133 } 134 135 public PreparedStatement prepareStatement(String query) { 136 return ThreadSession.currentSession().prepareStatement(InvoiceDetailFactory.class, query); 137 } 138 139 public InvoiceDetailPK getNextPK() { 140 return new InvoiceDetailPK(entityIdGenerator.getNextEntityId()); 141 } 142 143 public Set<InvoiceDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 144 throws PersistenceDatabaseException { 145 Set<InvoiceDetailPK> _result = new HashSet<>(); 146 147 try { 148 while(rs.next()) { 149 _result.add(getPKFromResultSet(rs)); 150 } 151 } catch (SQLException se) { 152 throw new PersistenceDatabaseException(se); 153 } 154 155 return _result; 156 } 157 158 public java.util.List<InvoiceDetailPK> getPKsFromResultSetAsList(ResultSet rs) 159 throws PersistenceDatabaseException { 160 java.util.List<InvoiceDetailPK> _result = new ArrayList<>(); 161 162 try { 163 while(rs.next()) { 164 _result.add(getPKFromResultSet(rs)); 165 } 166 } catch (SQLException se) { 167 throw new PersistenceDatabaseException(se); 168 } 169 170 return _result; 171 } 172 173 public InvoiceDetailPK getPKFromResultSet(ResultSet rs) 174 throws PersistenceDatabaseException { 175 InvoiceDetailPK _result; 176 177 try { 178 long invcdt_invoicedetailid = rs.getLong(INVCDT_INVOICEDETAILID); 179 Long _entityId = rs.wasNull() ? null : invcdt_invoicedetailid; 180 181 _result = new InvoiceDetailPK(_entityId); 182 } catch (SQLException se) { 183 throw new PersistenceDatabaseException(se); 184 } 185 186 return _result; 187 } 188 189 public java.util.List<InvoiceDetailValue> getValuesFromPKs(Session session, Collection<InvoiceDetailPK> pks) 190 throws PersistenceDatabaseException { 191 java.util.List<InvoiceDetailValue> _values = new ArrayList<>(pks.size()); 192 193 for(InvoiceDetailPK _pk: pks) { 194 _values.add(getValueFromPK(session, _pk)); 195 } 196 197 return _values; 198 } 199 200 public InvoiceDetailValue getValueFromPK(Session session, InvoiceDetailPK pk) 201 throws PersistenceDatabaseException { 202 InvoiceDetailValue _value; 203 204 // See if we already have the entity in the session cache 205 InvoiceDetail _entity = (InvoiceDetail)session.getEntity(pk); 206 if(_entity == null) 207 _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getInvoiceDetailValue(); 208 else 209 _value = _entity.getInvoiceDetailValue(); 210 211 return _value; 212 } 213 214 public java.util.List<InvoiceDetailValue> getValuesFromResultSet(Session session, ResultSet rs) 215 throws PersistenceDatabaseException { 216 java.util.List<InvoiceDetailValue> _result = new ArrayList<>(); 217 218 try { 219 while(rs.next()) { 220 _result.add(getValueFromResultSet(session, rs)); 221 } 222 } catch (SQLException se) { 223 throw new PersistenceDatabaseException(se); 224 } 225 226 return _result; 227 } 228 229 public InvoiceDetailValue getValueFromResultSet(Session session, ResultSet rs) 230 throws PersistenceDatabaseException { 231 InvoiceDetailValue _value; 232 233 try { 234 Long invcdt_invoicedetailid = rs.getLong(INVCDT_INVOICEDETAILID); 235 InvoiceDetailPK _pk = new InvoiceDetailPK(invcdt_invoicedetailid); 236 237 // See if we already have the entity in the session cache 238 InvoiceDetail _entity = (InvoiceDetail)session.getEntity(_pk); 239 240 if(_entity == null) { 241 Long invcdt_invc_invoiceid = rs.getLong(INVCDT_INVC_INVOICEID); 242 if(rs.wasNull()) 243 invcdt_invc_invoiceid = null; 244 245 Long invcdt_invctyp_invoicetypeid = rs.getLong(INVCDT_INVCTYP_INVOICETYPEID); 246 if(rs.wasNull()) 247 invcdt_invctyp_invoicetypeid = null; 248 249 String invcdt_invoicename = rs.getString(INVCDT_INVOICENAME); 250 if(rs.wasNull()) 251 invcdt_invoicename = null; 252 253 Long invcdt_bllact_billingaccountid = rs.getLong(INVCDT_BLLACT_BILLINGACCOUNTID); 254 if(rs.wasNull()) 255 invcdt_bllact_billingaccountid = null; 256 257 Long invcdt_gla_glaccountid = rs.getLong(INVCDT_GLA_GLACCOUNTID); 258 if(rs.wasNull()) 259 invcdt_gla_glaccountid = null; 260 261 Long invcdt_trm_termid = rs.getLong(INVCDT_TRM_TERMID); 262 if(rs.wasNull()) 263 invcdt_trm_termid = null; 264 265 Long invcdt_fob_freeonboardid = rs.getLong(INVCDT_FOB_FREEONBOARDID); 266 if(rs.wasNull()) 267 invcdt_fob_freeonboardid = null; 268 269 String invcdt_reference = rs.getString(INVCDT_REFERENCE); 270 if(rs.wasNull()) 271 invcdt_reference = null; 272 273 String invcdt_description = rs.getString(INVCDT_DESCRIPTION); 274 if(rs.wasNull()) 275 invcdt_description = null; 276 277 Long invcdt_fromtime = rs.getLong(INVCDT_FROMTIME); 278 if(rs.wasNull()) 279 invcdt_fromtime = null; 280 281 Long invcdt_thrutime = rs.getLong(INVCDT_THRUTIME); 282 if(rs.wasNull()) 283 invcdt_thrutime = null; 284 285 _value = new InvoiceDetailValue(_pk, new InvoicePK(invcdt_invc_invoiceid), new InvoiceTypePK(invcdt_invctyp_invoicetypeid), invcdt_invoicename, new BillingAccountPK(invcdt_bllact_billingaccountid), new GlAccountPK(invcdt_gla_glaccountid), new TermPK(invcdt_trm_termid), new FreeOnBoardPK(invcdt_fob_freeonboardid), invcdt_reference, invcdt_description, invcdt_fromtime, invcdt_thrutime); 286 } else 287 _value = _entity.getInvoiceDetailValue(); 288 } catch (SQLException se) { 289 throw new PersistenceDatabaseException(se); 290 } 291 292 return _value; 293 } 294 295 public java.util.List<InvoiceDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<InvoiceDetailPK> pks) 296 throws PersistenceDatabaseException { 297 return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks); 298 } 299 300 public java.util.List<InvoiceDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<InvoiceDetailPK> pks) 301 throws PersistenceDatabaseException { 302 java.util.List<InvoiceDetail> _entities = new ArrayList<>(pks.size()); 303 304 for(InvoiceDetailPK _pk: pks) { 305 _entities.add(getEntityFromPK(session, entityPermission, _pk)); 306 } 307 308 return _entities; 309 } 310 311 public InvoiceDetail getEntityFromValue(EntityPermission entityPermission, InvoiceDetailValue value) { 312 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey()); 313 } 314 315 public InvoiceDetail getEntityFromValue(Session session, EntityPermission entityPermission, InvoiceDetailValue value) { 316 return getEntityFromPK(session, entityPermission, value.getPrimaryKey()); 317 } 318 319 public InvoiceDetail getEntityFromPK(EntityPermission entityPermission, InvoiceDetailPK pk) 320 throws PersistenceDatabaseException { 321 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk); 322 } 323 324 public InvoiceDetail getEntityFromCache(Session session, InvoiceDetailPK pk) { 325 InvoiceDetailValue _value = (InvoiceDetailValue)session.getValueCache().get(pk); 326 327 return _value == null ? null : new InvoiceDetail(_value, EntityPermission.READ_ONLY); 328 } 329 330 public InvoiceDetail getEntityFromPK(Session session, EntityPermission entityPermission, InvoiceDetailPK pk) 331 throws PersistenceDatabaseException { 332 InvoiceDetail _entity; 333 334 // See if we already have the entity in the session cache 335 _entity = (InvoiceDetail)session.getEntity(pk); 336 if(_entity != null) { 337 // If the requested permission is READ_WRITE, and the cached permission is 338 // READ_ONLY, then pretend that the cached object wasn't found, and create 339 // a new entity that is READ_WRITE. 340 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 341 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 342 _entity = null; 343 } 344 } 345 346 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 347 _entity = getEntityFromCache(session, pk); 348 } 349 350 if(_entity == null) { 351 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 352 long _entityId = pk.getEntityId(); 353 ResultSet _rs = null; 354 355 try { 356 _ps.setLong(1, _entityId); 357 _rs = _ps.executeQuery(); 358 if(_rs.next()) { 359 _entity = getEntityFromResultSet(session, entityPermission, _rs); 360 } 361 } catch (SQLException se) { 362 throw new PersistenceDatabaseException(se); 363 } finally { 364 if(_rs != null) { 365 try { 366 _rs.close(); 367 } catch (SQLException se) { 368 // do nothing 369 } 370 } 371 } 372 } 373 374 return _entity; 375 } 376 377 public Set<InvoiceDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 378 throws PersistenceDatabaseException { 379 Set<InvoiceDetailPK> _pks; 380 ResultSet _rs = null; 381 382 try { 383 if(params.length != 0) { 384 Session.setQueryParams(ps, params); 385 } 386 387 _rs = ps.executeQuery(); 388 _pks = getPKsFromResultSetAsSet(_rs); 389 _rs.close(); 390 } catch (SQLException se) { 391 throw new PersistenceDatabaseException(se); 392 } finally { 393 if(_rs != null) { 394 try { 395 _rs.close(); 396 } catch (SQLException se) { 397 // do nothing 398 } 399 } 400 } 401 402 return _pks; 403 } 404 405 public java.util.List<InvoiceDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 406 throws PersistenceDatabaseException { 407 java.util.List<InvoiceDetailPK> _pks; 408 ResultSet _rs = null; 409 410 try { 411 if(params.length != 0) { 412 Session.setQueryParams(ps, params); 413 } 414 415 _rs = ps.executeQuery(); 416 _pks = getPKsFromResultSetAsList(_rs); 417 _rs.close(); 418 } catch (SQLException se) { 419 throw new PersistenceDatabaseException(se); 420 } finally { 421 if(_rs != null) { 422 try { 423 _rs.close(); 424 } catch (SQLException se) { 425 // do nothing 426 } 427 } 428 } 429 430 return _pks; 431 } 432 433 public InvoiceDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 434 throws PersistenceDatabaseException { 435 InvoiceDetailPK _pk = null; 436 ResultSet _rs = null; 437 438 try { 439 if(params.length != 0) { 440 Session.setQueryParams(ps, params); 441 } 442 443 _rs = ps.executeQuery(); 444 if(_rs.next()) { 445 _pk = getPKFromResultSet(_rs); 446 } 447 _rs.close(); 448 } catch (SQLException se) { 449 throw new PersistenceDatabaseException(se); 450 } finally { 451 if(_rs != null) { 452 try { 453 _rs.close(); 454 } catch (SQLException se) { 455 // do nothing 456 } 457 } 458 } 459 460 return _pk; 461 } 462 463 public java.util.List<InvoiceDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 464 throws PersistenceDatabaseException { 465 PreparedStatement ps = session.prepareStatement(InvoiceDetailFactory.class, queryMap.get(entityPermission)); 466 467 return getEntitiesFromQuery(session, entityPermission, ps, params); 468 } 469 470 public java.util.List<InvoiceDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 471 throws PersistenceDatabaseException { 472 Session session = ThreadSession.currentSession(); 473 PreparedStatement ps = session.prepareStatement(InvoiceDetailFactory.class, queryMap.get(entityPermission)); 474 475 return getEntitiesFromQuery(session, entityPermission, ps, params); 476 } 477 478 public java.util.List<InvoiceDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 479 throws PersistenceDatabaseException { 480 PreparedStatement ps = session.prepareStatement(InvoiceDetailFactory.class, queryMap.get(entityPermission)); 481 482 return getEntitiesFromQuery(session, entityPermission, ps); 483 } 484 485 public java.util.List<InvoiceDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 486 throws PersistenceDatabaseException { 487 Session session = ThreadSession.currentSession(); 488 PreparedStatement ps = session.prepareStatement(InvoiceDetailFactory.class, queryMap.get(entityPermission)); 489 490 return getEntitiesFromQuery(session, entityPermission, ps); 491 } 492 493 public java.util.List<InvoiceDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps) 494 throws PersistenceDatabaseException { 495 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps); 496 } 497 498 public java.util.List<InvoiceDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 499 throws PersistenceDatabaseException { 500 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 501 } 502 503 public java.util.List<InvoiceDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 504 throws PersistenceDatabaseException { 505 java.util.List<InvoiceDetail> _entities; 506 ResultSet _rs = null; 507 508 try { 509 if(params.length != 0) { 510 Session.setQueryParams(ps, params); 511 } 512 513 _rs = ps.executeQuery(); 514 _entities = getEntitiesFromResultSet(session, entityPermission, _rs); 515 _rs.close(); 516 } catch (SQLException se) { 517 throw new PersistenceDatabaseException(se); 518 } finally { 519 if(_rs != null) { 520 try { 521 _rs.close(); 522 } catch (SQLException se) { 523 // do nothing 524 } 525 } 526 } 527 528 return _entities; 529 } 530 531 public InvoiceDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 532 throws PersistenceDatabaseException { 533 PreparedStatement ps = session.prepareStatement(InvoiceDetailFactory.class, queryMap.get(entityPermission)); 534 535 return getEntityFromQuery(session, entityPermission, ps, params); 536 } 537 538 public InvoiceDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 539 throws PersistenceDatabaseException { 540 Session session = ThreadSession.currentSession(); 541 PreparedStatement ps = session.prepareStatement(InvoiceDetailFactory.class, queryMap.get(entityPermission)); 542 543 return getEntityFromQuery(session, entityPermission, ps, params); 544 } 545 546 public InvoiceDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 547 throws PersistenceDatabaseException { 548 PreparedStatement ps = session.prepareStatement(InvoiceDetailFactory.class, queryMap.get(entityPermission)); 549 550 return getEntityFromQuery(session, entityPermission, ps); 551 } 552 553 public InvoiceDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 554 throws PersistenceDatabaseException { 555 Session session = ThreadSession.currentSession(); 556 PreparedStatement ps = session.prepareStatement(InvoiceDetailFactory.class, queryMap.get(entityPermission)); 557 558 return getEntityFromQuery(session, entityPermission, ps); 559 } 560 561 public InvoiceDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps) 562 throws PersistenceDatabaseException { 563 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps); 564 } 565 566 public InvoiceDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 567 throws PersistenceDatabaseException { 568 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 569 } 570 571 public InvoiceDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 572 throws PersistenceDatabaseException { 573 InvoiceDetail _entity = null; 574 ResultSet _rs = null; 575 576 try { 577 if(params.length != 0) { 578 Session.setQueryParams(ps, params); 579 } 580 581 _rs = ps.executeQuery(); 582 if(_rs.next()) { 583 _entity = getEntityFromResultSet(session, entityPermission, _rs); 584 } 585 _rs.close(); 586 } catch (SQLException se) { 587 throw new PersistenceDatabaseException(se); 588 } finally { 589 if(_rs != null) { 590 try { 591 _rs.close(); 592 } catch (SQLException se) { 593 // do nothing 594 } 595 } 596 } 597 598 return _entity; 599 } 600 601 public java.util.List<InvoiceDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 602 throws PersistenceDatabaseException { 603 return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 604 } 605 606 public java.util.List<InvoiceDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 607 throws PersistenceDatabaseException { 608 java.util.List<InvoiceDetail> _result = new ArrayList<>(); 609 610 try { 611 while(rs.next()) { 612 _result.add(getEntityFromResultSet(session, entityPermission, rs)); 613 } 614 } catch (SQLException se) { 615 throw new PersistenceDatabaseException(se); 616 } 617 618 return _result; 619 } 620 621 public InvoiceDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 622 throws PersistenceDatabaseException { 623 return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 624 } 625 626 public InvoiceDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 627 throws PersistenceDatabaseException { 628 InvoiceDetail _entity; 629 630 try { 631 Long invcdt_invoicedetailid = rs.getLong(INVCDT_INVOICEDETAILID); 632 InvoiceDetailPK _pk = new InvoiceDetailPK(invcdt_invoicedetailid); 633 634 // See if we already have the entity in the session cache 635 _entity = (InvoiceDetail)session.getEntity(_pk); 636 if(_entity != null) { 637 // If the requested permission is READ_WRITE, and the cached permission is 638 // READ_ONLY, then pretend that the cached object wasn't found, and create 639 // a new entity that is READ_WRITE. 640 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 641 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 642 _entity = null; 643 } 644 } 645 boolean foundInSessionCache = _entity != null; 646 647 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 648 _entity = getEntityFromCache(session, _pk); 649 } 650 651 if(_entity == null) { 652 Long invcdt_invc_invoiceid = rs.getLong(INVCDT_INVC_INVOICEID); 653 if(rs.wasNull()) 654 invcdt_invc_invoiceid = null; 655 656 Long invcdt_invctyp_invoicetypeid = rs.getLong(INVCDT_INVCTYP_INVOICETYPEID); 657 if(rs.wasNull()) 658 invcdt_invctyp_invoicetypeid = null; 659 660 String invcdt_invoicename = rs.getString(INVCDT_INVOICENAME); 661 if(rs.wasNull()) 662 invcdt_invoicename = null; 663 664 Long invcdt_bllact_billingaccountid = rs.getLong(INVCDT_BLLACT_BILLINGACCOUNTID); 665 if(rs.wasNull()) 666 invcdt_bllact_billingaccountid = null; 667 668 Long invcdt_gla_glaccountid = rs.getLong(INVCDT_GLA_GLACCOUNTID); 669 if(rs.wasNull()) 670 invcdt_gla_glaccountid = null; 671 672 Long invcdt_trm_termid = rs.getLong(INVCDT_TRM_TERMID); 673 if(rs.wasNull()) 674 invcdt_trm_termid = null; 675 676 Long invcdt_fob_freeonboardid = rs.getLong(INVCDT_FOB_FREEONBOARDID); 677 if(rs.wasNull()) 678 invcdt_fob_freeonboardid = null; 679 680 String invcdt_reference = rs.getString(INVCDT_REFERENCE); 681 if(rs.wasNull()) 682 invcdt_reference = null; 683 684 String invcdt_description = rs.getString(INVCDT_DESCRIPTION); 685 if(rs.wasNull()) 686 invcdt_description = null; 687 688 Long invcdt_fromtime = rs.getLong(INVCDT_FROMTIME); 689 if(rs.wasNull()) 690 invcdt_fromtime = null; 691 692 Long invcdt_thrutime = rs.getLong(INVCDT_THRUTIME); 693 if(rs.wasNull()) 694 invcdt_thrutime = null; 695 696 InvoiceDetailValue _value = new InvoiceDetailValue(_pk, invcdt_invc_invoiceid == null? null: new InvoicePK(invcdt_invc_invoiceid), invcdt_invctyp_invoicetypeid == null? null: new InvoiceTypePK(invcdt_invctyp_invoicetypeid), invcdt_invoicename, invcdt_bllact_billingaccountid == null? null: new BillingAccountPK(invcdt_bllact_billingaccountid), invcdt_gla_glaccountid == null? null: new GlAccountPK(invcdt_gla_glaccountid), invcdt_trm_termid == null? null: new TermPK(invcdt_trm_termid), invcdt_fob_freeonboardid == null? null: new FreeOnBoardPK(invcdt_fob_freeonboardid), invcdt_reference, invcdt_description, invcdt_fromtime, invcdt_thrutime); 697 _entity = new InvoiceDetail(_value, entityPermission); 698 } 699 700 if(!foundInSessionCache) { 701 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 702 session.putReadOnlyEntity(_pk, _entity); 703 session.getValueCache().put(_entity.getInvoiceDetailValue()); 704 } else { 705 session.putReadWriteEntity(_pk, _entity); 706 } 707 } 708 } catch (SQLException se) { 709 throw new PersistenceDatabaseException(se); 710 } 711 712 return _entity; 713 } 714 715 public InvoiceDetail create(Session session, Invoice invoice, InvoiceType invoiceType, String invoiceName, BillingAccount billingAccount, GlAccount glAccount, Term term, FreeOnBoard freeOnBoard, String reference, String description, Long fromTime, Long thruTime) 716 throws PersistenceDatabaseException, PersistenceNotNullException { 717 return create(session, invoice == null ? null : invoice.getPrimaryKey(), invoiceType == null ? null : invoiceType.getPrimaryKey(), invoiceName, billingAccount == null ? null : billingAccount.getPrimaryKey(), glAccount == null ? null : glAccount.getPrimaryKey(), term == null ? null : term.getPrimaryKey(), freeOnBoard == null ? null : freeOnBoard.getPrimaryKey(), reference, description, fromTime, thruTime); 718 } 719 720 public InvoiceDetail create(Invoice invoice, InvoiceType invoiceType, String invoiceName, BillingAccount billingAccount, GlAccount glAccount, Term term, FreeOnBoard freeOnBoard, String reference, String description, Long fromTime, Long thruTime) 721 throws PersistenceDatabaseException, PersistenceNotNullException { 722 return create(ThreadSession.currentSession(), invoice == null ? null : invoice.getPrimaryKey(), invoiceType == null ? null : invoiceType.getPrimaryKey(), invoiceName, billingAccount == null ? null : billingAccount.getPrimaryKey(), glAccount == null ? null : glAccount.getPrimaryKey(), term == null ? null : term.getPrimaryKey(), freeOnBoard == null ? null : freeOnBoard.getPrimaryKey(), reference, description, fromTime, thruTime); 723 } 724 725 private void bindForCreate(PreparedStatement _ps, InvoiceDetailValue _value) 726 throws SQLException { 727 _ps.setLong(1, _value.getEntityId()); 728 729 InvoicePK invcdt_invc_invoiceid = _value.getInvoicePK(); 730 if(invcdt_invc_invoiceid == null) 731 _ps.setNull(2, Types.BIGINT); 732 else 733 _ps.setLong(2, invcdt_invc_invoiceid.getEntityId()); 734 735 InvoiceTypePK invcdt_invctyp_invoicetypeid = _value.getInvoiceTypePK(); 736 if(invcdt_invctyp_invoicetypeid == null) 737 _ps.setNull(3, Types.BIGINT); 738 else 739 _ps.setLong(3, invcdt_invctyp_invoicetypeid.getEntityId()); 740 741 String invcdt_invoicename = _value.getInvoiceName(); 742 if(invcdt_invoicename == null) 743 _ps.setNull(4, Types.VARCHAR); 744 else 745 _ps.setString(4, invcdt_invoicename); 746 747 BillingAccountPK invcdt_bllact_billingaccountid = _value.getBillingAccountPK(); 748 if(invcdt_bllact_billingaccountid == null) 749 _ps.setNull(5, Types.BIGINT); 750 else 751 _ps.setLong(5, invcdt_bllact_billingaccountid.getEntityId()); 752 753 GlAccountPK invcdt_gla_glaccountid = _value.getGlAccountPK(); 754 if(invcdt_gla_glaccountid == null) 755 _ps.setNull(6, Types.BIGINT); 756 else 757 _ps.setLong(6, invcdt_gla_glaccountid.getEntityId()); 758 759 TermPK invcdt_trm_termid = _value.getTermPK(); 760 if(invcdt_trm_termid == null) 761 _ps.setNull(7, Types.BIGINT); 762 else 763 _ps.setLong(7, invcdt_trm_termid.getEntityId()); 764 765 FreeOnBoardPK invcdt_fob_freeonboardid = _value.getFreeOnBoardPK(); 766 if(invcdt_fob_freeonboardid == null) 767 _ps.setNull(8, Types.BIGINT); 768 else 769 _ps.setLong(8, invcdt_fob_freeonboardid.getEntityId()); 770 771 String invcdt_reference = _value.getReference(); 772 if(invcdt_reference == null) 773 _ps.setNull(9, Types.VARCHAR); 774 else 775 _ps.setString(9, invcdt_reference); 776 777 String invcdt_description = _value.getDescription(); 778 if(invcdt_description == null) 779 _ps.setNull(10, Types.VARCHAR); 780 else 781 _ps.setString(10, invcdt_description); 782 783 Long invcdt_fromtime = _value.getFromTime(); 784 if(invcdt_fromtime == null) 785 _ps.setNull(11, Types.BIGINT); 786 else 787 _ps.setLong(11, invcdt_fromtime); 788 789 Long invcdt_thrutime = _value.getThruTime(); 790 if(invcdt_thrutime == null) 791 _ps.setNull(12, Types.BIGINT); 792 else 793 _ps.setLong(12, invcdt_thrutime); 794 795 } 796 797 public InvoiceDetail create(Session session, InvoicePK invoicePK, InvoiceTypePK invoiceTypePK, String invoiceName, BillingAccountPK billingAccountPK, GlAccountPK glAccountPK, TermPK termPK, FreeOnBoardPK freeOnBoardPK, String reference, String description, Long fromTime, Long thruTime) 798 throws PersistenceDatabaseException, PersistenceNotNullException { 799 InvoiceDetailPK _pk = getNextPK(); 800 InvoiceDetailValue _value = new InvoiceDetailValue(_pk, invoicePK, invoiceTypePK, invoiceName, billingAccountPK, glAccountPK, termPK, freeOnBoardPK, reference, description, fromTime, thruTime); 801 802 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 803 804 try { 805 bindForCreate(_ps, _value); 806 807 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 808 int _count = _ps.executeUpdate(); 809 810 if(_count != 1) { 811 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 812 } 813 } else { 814 _ps.executeUpdate(); 815 } 816 817 session.getValueCache().put(_value); 818 } catch (SQLException se) { 819 throw new PersistenceDatabaseException(se); 820 } 821 822 InvoiceDetail _entity = new InvoiceDetail(_value, EntityPermission.READ_ONLY); 823 session.putReadOnlyEntity(_pk, _entity); 824 825 return _entity; 826 } 827 828 public InvoiceDetail create(InvoicePK invoicePK, InvoiceTypePK invoiceTypePK, String invoiceName, BillingAccountPK billingAccountPK, GlAccountPK glAccountPK, TermPK termPK, FreeOnBoardPK freeOnBoardPK, String reference, String description, Long fromTime, Long thruTime) 829 throws PersistenceDatabaseException, PersistenceNotNullException { 830 return create(ThreadSession.currentSession(), invoicePK, invoiceTypePK, invoiceName, billingAccountPK, glAccountPK, termPK, freeOnBoardPK, reference, description, fromTime, thruTime); 831 } 832 833 public void create(Session session, Collection<InvoiceDetailValue> _values) 834 throws PersistenceDatabaseException, PersistenceNotNullException { 835 int _size = _values.size(); 836 837 if(_size > 0) { 838 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 839 List<InvoiceDetailValue> _cacheValues = new ArrayList<>(_size); 840 841 try { 842 for(InvoiceDetailValue _value : _values) { 843 _value.setEntityId(entityIdGenerator.getNextEntityId()); 844 bindForCreate(_ps, _value); 845 846 _ps.addBatch(); 847 848 _cacheValues.add(_value); 849 } 850 851 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 852 int[] _counts = _ps.executeBatch(); 853 854 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 855 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 856 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 857 } 858 } 859 } else { 860 _ps.executeBatch(); 861 } 862 863 _ps.clearBatch(); 864 } catch (SQLException se) { 865 throw new PersistenceDatabaseException(se); 866 } 867 868 _cacheValues.forEach((_cacheValue) -> { 869 InvoiceDetail _cacheEntity = new InvoiceDetail(_cacheValue, EntityPermission.READ_ONLY); 870 871 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 872 }); 873 } 874 } 875 876 public void create(Collection<InvoiceDetailValue> _values) 877 throws PersistenceDatabaseException, PersistenceNotNullException { 878 create(ThreadSession.currentSession(), _values); 879 } 880 881 private boolean bindForStore(PreparedStatement _ps, InvoiceDetailValue _value) 882 throws SQLException { 883 boolean _hasBeenModified = _value.hasBeenModified(); 884 885 if(_hasBeenModified) { 886 InvoicePK invcdt_invc_invoiceid = _value.getInvoicePK(); 887 if(invcdt_invc_invoiceid == null) 888 _ps.setNull(1, Types.BIGINT); 889 else 890 _ps.setLong(1, invcdt_invc_invoiceid.getEntityId()); 891 892 InvoiceTypePK invcdt_invctyp_invoicetypeid = _value.getInvoiceTypePK(); 893 if(invcdt_invctyp_invoicetypeid == null) 894 _ps.setNull(2, Types.BIGINT); 895 else 896 _ps.setLong(2, invcdt_invctyp_invoicetypeid.getEntityId()); 897 898 String invcdt_invoicename = _value.getInvoiceName(); 899 if(invcdt_invoicename == null) 900 _ps.setNull(3, Types.VARCHAR); 901 else 902 _ps.setString(3, invcdt_invoicename); 903 904 BillingAccountPK invcdt_bllact_billingaccountid = _value.getBillingAccountPK(); 905 if(invcdt_bllact_billingaccountid == null) 906 _ps.setNull(4, Types.BIGINT); 907 else 908 _ps.setLong(4, invcdt_bllact_billingaccountid.getEntityId()); 909 910 GlAccountPK invcdt_gla_glaccountid = _value.getGlAccountPK(); 911 if(invcdt_gla_glaccountid == null) 912 _ps.setNull(5, Types.BIGINT); 913 else 914 _ps.setLong(5, invcdt_gla_glaccountid.getEntityId()); 915 916 TermPK invcdt_trm_termid = _value.getTermPK(); 917 if(invcdt_trm_termid == null) 918 _ps.setNull(6, Types.BIGINT); 919 else 920 _ps.setLong(6, invcdt_trm_termid.getEntityId()); 921 922 FreeOnBoardPK invcdt_fob_freeonboardid = _value.getFreeOnBoardPK(); 923 if(invcdt_fob_freeonboardid == null) 924 _ps.setNull(7, Types.BIGINT); 925 else 926 _ps.setLong(7, invcdt_fob_freeonboardid.getEntityId()); 927 928 String invcdt_reference = _value.getReference(); 929 if(invcdt_reference == null) 930 _ps.setNull(8, Types.VARCHAR); 931 else 932 _ps.setString(8, invcdt_reference); 933 934 String invcdt_description = _value.getDescription(); 935 if(invcdt_description == null) 936 _ps.setNull(9, Types.VARCHAR); 937 else 938 _ps.setString(9, invcdt_description); 939 940 Long invcdt_fromtime = _value.getFromTime(); 941 if(invcdt_fromtime == null) 942 _ps.setNull(10, Types.BIGINT); 943 else 944 _ps.setLong(10, invcdt_fromtime); 945 946 Long invcdt_thrutime = _value.getThruTime(); 947 if(invcdt_thrutime == null) 948 _ps.setNull(11, Types.BIGINT); 949 else 950 _ps.setLong(11, invcdt_thrutime); 951 952 _ps.setLong(12, _value.getPrimaryKey().getEntityId()); 953 954 _value.clearHasBeenModified(); 955 } 956 957 return _hasBeenModified; 958 } 959 960 @Override 961 public void store(Session session, InvoiceDetail entity) 962 throws PersistenceDatabaseException { 963 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 964 965 try { 966 InvoiceDetailValue _value = entity.getInvoiceDetailValue(); 967 968 if(bindForStore(_ps, _value)) { 969 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 970 int _count = _ps.executeUpdate(); 971 972 if(_count != 1) { 973 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 974 } 975 } else { 976 _ps.executeUpdate(); 977 } 978 979 session.getValueCache().put(_value); 980 } 981 } catch (SQLException se) { 982 throw new PersistenceDatabaseException(se); 983 } 984 } 985 986 @Override 987 public void store(Session session, Collection<InvoiceDetail> entities) 988 throws PersistenceDatabaseException { 989 if(entities.size() > 0) { 990 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 991 int _modifiedEntities = 0; 992 993 try { 994 for(InvoiceDetail entity : entities) { 995 if(bindForStore(_ps, entity.getInvoiceDetailValue())) { 996 _ps.addBatch(); 997 _modifiedEntities++; 998 } 999 } 1000 1001 if(_modifiedEntities != 0) { 1002 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 1003 int[] _counts = _ps.executeBatch(); 1004 1005 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1006 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1007 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1008 } 1009 } 1010 } else { 1011 _ps.executeBatch(); 1012 } 1013 1014 _ps.clearBatch(); 1015 1016 entities.forEach((entity) -> { 1017 session.getValueCache().put(entity.getInvoiceDetailValue()); 1018 }); 1019 } 1020 } catch (SQLException se) { 1021 throw new PersistenceDatabaseException(se); 1022 } 1023 } 1024 } 1025 1026 @Override 1027 public void store(Collection<InvoiceDetail> entities) 1028 throws PersistenceDatabaseException { 1029 store(ThreadSession.currentSession(), entities); 1030 } 1031 1032 @Override 1033 public void remove(Session session, InvoiceDetail entity) 1034 throws PersistenceDatabaseException { 1035 remove(session, entity.getPrimaryKey()); 1036 } 1037 1038 @Override 1039 public void remove(Session session, InvoiceDetailPK pk) 1040 throws PersistenceDatabaseException { 1041 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1042 long _entityId = pk.getEntityId(); 1043 1044 try { 1045 _ps.setLong(1, _entityId); 1046 1047 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1048 int _count = _ps.executeUpdate(); 1049 1050 if(_count != 1) { 1051 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 1052 } 1053 } else { 1054 _ps.executeUpdate(); 1055 } 1056 1057 session.getValueCache().remove(pk); 1058 } catch (SQLException se) { 1059 throw new PersistenceDatabaseException(se); 1060 } 1061 1062 session.removed(pk, false); 1063 } 1064 1065 @Override 1066 public void remove(Session session, Collection<InvoiceDetailPK> pks) 1067 throws PersistenceDatabaseException { 1068 if(pks.size() > 0) { 1069 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1070 int _modifiedEntities = 0; 1071 1072 try { 1073 for(InvoiceDetailPK pk : pks) { 1074 long _entityId = pk.getEntityId(); 1075 1076 _ps.setLong(1, _entityId); 1077 1078 _ps.addBatch(); 1079 _modifiedEntities++; 1080 } 1081 1082 if(_modifiedEntities != 0) { 1083 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1084 int[] _counts = _ps.executeBatch(); 1085 1086 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1087 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1088 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1089 } 1090 } 1091 } else { 1092 _ps.executeBatch(); 1093 } 1094 1095 _ps.clearBatch(); 1096 1097 pks.forEach((pk) -> { 1098 session.getValueCache().remove(pk); 1099 }); 1100 } 1101 } catch (SQLException se) { 1102 throw new PersistenceDatabaseException(se); 1103 } 1104 1105 pks.forEach((pk) -> { 1106 session.removed(pk, true); 1107 }); 1108 } 1109 } 1110 1111 @Override 1112 public void remove(Collection<InvoiceDetailPK> pks) 1113 throws PersistenceDatabaseException { 1114 remove(ThreadSession.currentSession(), pks); 1115 } 1116 1117 @Override 1118 public boolean validPK(Session session, InvoiceDetailPK pk) 1119 throws PersistenceDatabaseException { 1120 boolean valid = false; 1121 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1122 ResultSet _rs = null; 1123 1124 try { 1125 _ps.setLong(1, pk.getEntityId()); 1126 1127 _rs = _ps.executeQuery(); 1128 if(_rs.next()) { 1129 long _count = _rs.getLong(1); 1130 if(_rs.wasNull()) 1131 _count = 0; 1132 1133 if(_count == 1) 1134 valid = true; 1135 } 1136 } catch (SQLException se) { 1137 throw new PersistenceDatabaseException(se); 1138 } finally { 1139 if(_rs != null) { 1140 try { 1141 _rs.close(); 1142 } catch (SQLException se) { 1143 // do nothing 1144 } 1145 } 1146 } 1147 1148 return valid; 1149 } 1150 1151}