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