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