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 * ProfileFactory.java 021 */ 022 023package com.echothree.model.data.party.server.factory; 024 025import com.echothree.model.data.party.common.pk.PartyPK; 026import com.echothree.model.data.icon.common.pk.IconPK; 027import com.echothree.model.data.party.common.pk.GenderPK; 028import com.echothree.model.data.party.common.pk.BirthdayFormatPK; 029import com.echothree.model.data.core.common.pk.MimeTypePK; 030 031import com.echothree.model.data.party.server.entity.Party; 032import com.echothree.model.data.icon.server.entity.Icon; 033import com.echothree.model.data.party.server.entity.Gender; 034import com.echothree.model.data.party.server.entity.BirthdayFormat; 035import com.echothree.model.data.core.server.entity.MimeType; 036 037import com.echothree.model.data.party.common.ProfileConstants; 038import com.echothree.model.data.party.common.pk.ProfilePK; 039import com.echothree.model.data.party.server.value.ProfileValue; 040import com.echothree.model.data.party.server.entity.Profile; 041import com.echothree.util.common.exception.PersistenceDatabaseException; 042import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 043import com.echothree.util.common.exception.PersistenceNotNullException; 044import com.echothree.util.server.persistence.BaseFactory; 045import com.echothree.util.server.persistence.EntityIdGenerator; 046import com.echothree.util.server.persistence.EntityPermission; 047import com.echothree.util.server.persistence.PersistenceDebugFlags; 048import com.echothree.util.server.persistence.Session; 049import com.echothree.util.server.persistence.ThreadSession; 050import java.sql.PreparedStatement; 051import java.sql.ResultSet; 052import java.sql.SQLException; 053import java.sql.Types; 054import java.io.ByteArrayInputStream; 055import java.io.StringReader; 056import java.util.ArrayList; 057import java.util.Collection; 058import java.util.HashSet; 059import java.util.List; 060import java.util.Map; 061import java.util.Set; 062import org.apache.commons.logging.Log; 063import org.apache.commons.logging.LogFactory; 064 065public class ProfileFactory 066 implements BaseFactory<ProfilePK, Profile> { 067 068 //final private static Log log = LogFactory.getLog(ProfileFactory.class); 069 070 final private static String SQL_SELECT_READ_ONLY = "SELECT prfl_profileid, prfl_par_partyid, prfl_nickname, prfl_icn_iconid, prfl_pronunciation, prfl_gndr_genderid, prfl_pronouns, prfl_birthday, prfl_bdyf_birthdayformatid, prfl_occupation, prfl_hobbies, prfl_location, prfl_biomimetypeid, prfl_bio, prfl_signaturemimetypeid, prfl_signature, prfl_fromtime, prfl_thrutime FROM profiles WHERE prfl_profileid = ?"; 071 final private static String SQL_SELECT_READ_WRITE = "SELECT prfl_profileid, prfl_par_partyid, prfl_nickname, prfl_icn_iconid, prfl_pronunciation, prfl_gndr_genderid, prfl_pronouns, prfl_birthday, prfl_bdyf_birthdayformatid, prfl_occupation, prfl_hobbies, prfl_location, prfl_biomimetypeid, prfl_bio, prfl_signaturemimetypeid, prfl_signature, prfl_fromtime, prfl_thrutime FROM profiles WHERE prfl_profileid = ? FOR UPDATE"; 072 final private static String SQL_INSERT = "INSERT INTO profiles (prfl_profileid, prfl_par_partyid, prfl_nickname, prfl_icn_iconid, prfl_pronunciation, prfl_gndr_genderid, prfl_pronouns, prfl_birthday, prfl_bdyf_birthdayformatid, prfl_occupation, prfl_hobbies, prfl_location, prfl_biomimetypeid, prfl_bio, prfl_signaturemimetypeid, prfl_signature, prfl_fromtime, prfl_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 073 final private static String SQL_UPDATE = "UPDATE profiles SET prfl_par_partyid = ?, prfl_nickname = ?, prfl_icn_iconid = ?, prfl_pronunciation = ?, prfl_gndr_genderid = ?, prfl_pronouns = ?, prfl_birthday = ?, prfl_bdyf_birthdayformatid = ?, prfl_occupation = ?, prfl_hobbies = ?, prfl_location = ?, prfl_biomimetypeid = ?, prfl_bio = ?, prfl_signaturemimetypeid = ?, prfl_signature = ?, prfl_fromtime = ?, prfl_thrutime = ? WHERE prfl_profileid = ?"; 074 final private static String SQL_DELETE = "DELETE FROM profiles WHERE prfl_profileid = ?"; 075 final private static String SQL_VALID = "SELECT COUNT(*) FROM profiles WHERE prfl_profileid = ?"; 076 077 final private static String PK_COLUMN = "prfl_profileid"; 078 final private static String ALL_COLUMNS = "prfl_profileid, prfl_par_partyid, prfl_nickname, prfl_icn_iconid, prfl_pronunciation, prfl_gndr_genderid, prfl_pronouns, prfl_birthday, prfl_bdyf_birthdayformatid, prfl_occupation, prfl_hobbies, prfl_location, prfl_biomimetypeid, prfl_bio, prfl_signaturemimetypeid, prfl_signature, prfl_fromtime, prfl_thrutime"; 079 final public static String TABLE_NAME = "profiles"; 080 081 final public static String PRFL_PROFILEID = "prfl_profileid"; 082 final public static String PRFL_PAR_PARTYID = "prfl_par_partyid"; 083 final public static String PRFL_NICKNAME = "prfl_nickname"; 084 final public static String PRFL_ICN_ICONID = "prfl_icn_iconid"; 085 final public static String PRFL_PRONUNCIATION = "prfl_pronunciation"; 086 final public static String PRFL_GNDR_GENDERID = "prfl_gndr_genderid"; 087 final public static String PRFL_PRONOUNS = "prfl_pronouns"; 088 final public static String PRFL_BIRTHDAY = "prfl_birthday"; 089 final public static String PRFL_BDYF_BIRTHDAYFORMATID = "prfl_bdyf_birthdayformatid"; 090 final public static String PRFL_OCCUPATION = "prfl_occupation"; 091 final public static String PRFL_HOBBIES = "prfl_hobbies"; 092 final public static String PRFL_LOCATION = "prfl_location"; 093 final public static String PRFL_BIOMIMETYPEID = "prfl_biomimetypeid"; 094 final public static String PRFL_BIO = "prfl_bio"; 095 final public static String PRFL_SIGNATUREMIMETYPEID = "prfl_signaturemimetypeid"; 096 final public static String PRFL_SIGNATURE = "prfl_signature"; 097 final public static String PRFL_FROMTIME = "prfl_fromtime"; 098 final public static String PRFL_THRUTIME = "prfl_thrutime"; 099 100 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ProfileConstants.COMPONENT_VENDOR_NAME, ProfileConstants.ENTITY_TYPE_NAME); 101 102 /** Creates a new instance of ProfileFactory */ 103 private ProfileFactory() { 104 super(); 105 } 106 107 private static class ProfileFactoryHolder { 108 static ProfileFactory instance = new ProfileFactory(); 109 } 110 111 public static ProfileFactory getInstance() { 112 return ProfileFactoryHolder.instance; 113 } 114 115 @Override 116 public String getPKColumn() { 117 return PK_COLUMN; 118 } 119 120 @Override 121 public String getAllColumns() { 122 return ALL_COLUMNS; 123 } 124 125 @Override 126 public String getTableName() { 127 return TABLE_NAME; 128 } 129 130 @Override 131 public String getComponentVendorName() { 132 return ProfileConstants.COMPONENT_VENDOR_NAME; 133 } 134 135 @Override 136 public String getEntityTypeName() { 137 return ProfileConstants.ENTITY_TYPE_NAME; 138 } 139 140 public PreparedStatement prepareStatement(String query) { 141 return ThreadSession.currentSession().prepareStatement(ProfileFactory.class, query); 142 } 143 144 public ProfilePK getNextPK() { 145 return new ProfilePK(entityIdGenerator.getNextEntityId()); 146 } 147 148 public Set<ProfilePK> getPKsFromResultSetAsSet(ResultSet rs) 149 throws PersistenceDatabaseException { 150 Set<ProfilePK> _result = new HashSet<>(); 151 152 try { 153 while(rs.next()) { 154 _result.add(getPKFromResultSet(rs)); 155 } 156 } catch (SQLException se) { 157 throw new PersistenceDatabaseException(se); 158 } 159 160 return _result; 161 } 162 163 public java.util.List<ProfilePK> getPKsFromResultSetAsList(ResultSet rs) 164 throws PersistenceDatabaseException { 165 java.util.List<ProfilePK> _result = new ArrayList<>(); 166 167 try { 168 while(rs.next()) { 169 _result.add(getPKFromResultSet(rs)); 170 } 171 } catch (SQLException se) { 172 throw new PersistenceDatabaseException(se); 173 } 174 175 return _result; 176 } 177 178 public ProfilePK getPKFromResultSet(ResultSet rs) 179 throws PersistenceDatabaseException { 180 ProfilePK _result; 181 182 try { 183 long prfl_profileid = rs.getLong(PRFL_PROFILEID); 184 Long _entityId = rs.wasNull() ? null : prfl_profileid; 185 186 _result = new ProfilePK(_entityId); 187 } catch (SQLException se) { 188 throw new PersistenceDatabaseException(se); 189 } 190 191 return _result; 192 } 193 194 public java.util.List<ProfileValue> getValuesFromPKs(Session session, Collection<ProfilePK> pks) 195 throws PersistenceDatabaseException { 196 java.util.List<ProfileValue> _values = new ArrayList<>(pks.size()); 197 198 for(ProfilePK _pk: pks) { 199 _values.add(getValueFromPK(session, _pk)); 200 } 201 202 return _values; 203 } 204 205 public ProfileValue getValueFromPK(Session session, ProfilePK pk) 206 throws PersistenceDatabaseException { 207 ProfileValue _value; 208 209 // See if we already have the entity in the session cache 210 Profile _entity = (Profile)session.getEntity(pk); 211 if(_entity == null) 212 _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getProfileValue(); 213 else 214 _value = _entity.getProfileValue(); 215 216 return _value; 217 } 218 219 public java.util.List<ProfileValue> getValuesFromResultSet(Session session, ResultSet rs) 220 throws PersistenceDatabaseException { 221 java.util.List<ProfileValue> _result = new ArrayList<>(); 222 223 try { 224 while(rs.next()) { 225 _result.add(getValueFromResultSet(session, rs)); 226 } 227 } catch (SQLException se) { 228 throw new PersistenceDatabaseException(se); 229 } 230 231 return _result; 232 } 233 234 public ProfileValue getValueFromResultSet(Session session, ResultSet rs) 235 throws PersistenceDatabaseException { 236 ProfileValue _value; 237 238 try { 239 Long prfl_profileid = rs.getLong(PRFL_PROFILEID); 240 ProfilePK _pk = new ProfilePK(prfl_profileid); 241 242 // See if we already have the entity in the session cache 243 Profile _entity = (Profile)session.getEntity(_pk); 244 245 if(_entity == null) { 246 Long prfl_par_partyid = rs.getLong(PRFL_PAR_PARTYID); 247 if(rs.wasNull()) 248 prfl_par_partyid = null; 249 250 String prfl_nickname = rs.getString(PRFL_NICKNAME); 251 if(rs.wasNull()) 252 prfl_nickname = null; 253 254 Long prfl_icn_iconid = rs.getLong(PRFL_ICN_ICONID); 255 if(rs.wasNull()) 256 prfl_icn_iconid = null; 257 258 String prfl_pronunciation = rs.getString(PRFL_PRONUNCIATION); 259 if(rs.wasNull()) 260 prfl_pronunciation = null; 261 262 Long prfl_gndr_genderid = rs.getLong(PRFL_GNDR_GENDERID); 263 if(rs.wasNull()) 264 prfl_gndr_genderid = null; 265 266 String prfl_pronouns = rs.getString(PRFL_PRONOUNS); 267 if(rs.wasNull()) 268 prfl_pronouns = null; 269 270 Integer prfl_birthday = rs.getInt(PRFL_BIRTHDAY); 271 if(rs.wasNull()) 272 prfl_birthday = null; 273 274 Long prfl_bdyf_birthdayformatid = rs.getLong(PRFL_BDYF_BIRTHDAYFORMATID); 275 if(rs.wasNull()) 276 prfl_bdyf_birthdayformatid = null; 277 278 String prfl_occupation = rs.getString(PRFL_OCCUPATION); 279 if(rs.wasNull()) 280 prfl_occupation = null; 281 282 String prfl_hobbies = rs.getString(PRFL_HOBBIES); 283 if(rs.wasNull()) 284 prfl_hobbies = null; 285 286 String prfl_location = rs.getString(PRFL_LOCATION); 287 if(rs.wasNull()) 288 prfl_location = null; 289 290 Long prfl_biomimetypeid = rs.getLong(PRFL_BIOMIMETYPEID); 291 if(rs.wasNull()) 292 prfl_biomimetypeid = null; 293 294 String prfl_bio = rs.getString(PRFL_BIO); 295 if(rs.wasNull()) 296 prfl_bio = null; 297 298 Long prfl_signaturemimetypeid = rs.getLong(PRFL_SIGNATUREMIMETYPEID); 299 if(rs.wasNull()) 300 prfl_signaturemimetypeid = null; 301 302 String prfl_signature = rs.getString(PRFL_SIGNATURE); 303 if(rs.wasNull()) 304 prfl_signature = null; 305 306 Long prfl_fromtime = rs.getLong(PRFL_FROMTIME); 307 if(rs.wasNull()) 308 prfl_fromtime = null; 309 310 Long prfl_thrutime = rs.getLong(PRFL_THRUTIME); 311 if(rs.wasNull()) 312 prfl_thrutime = null; 313 314 _value = new ProfileValue(_pk, new PartyPK(prfl_par_partyid), prfl_nickname, new IconPK(prfl_icn_iconid), prfl_pronunciation, new GenderPK(prfl_gndr_genderid), prfl_pronouns, prfl_birthday, new BirthdayFormatPK(prfl_bdyf_birthdayformatid), prfl_occupation, prfl_hobbies, prfl_location, new MimeTypePK(prfl_biomimetypeid), prfl_bio, new MimeTypePK(prfl_signaturemimetypeid), prfl_signature, prfl_fromtime, prfl_thrutime); 315 } else 316 _value = _entity.getProfileValue(); 317 } catch (SQLException se) { 318 throw new PersistenceDatabaseException(se); 319 } 320 321 return _value; 322 } 323 324 public java.util.List<Profile> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ProfilePK> pks) 325 throws PersistenceDatabaseException { 326 return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks); 327 } 328 329 public java.util.List<Profile> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<ProfilePK> pks) 330 throws PersistenceDatabaseException { 331 java.util.List<Profile> _entities = new ArrayList<>(pks.size()); 332 333 for(ProfilePK _pk: pks) { 334 _entities.add(getEntityFromPK(session, entityPermission, _pk)); 335 } 336 337 return _entities; 338 } 339 340 public Profile getEntityFromValue(EntityPermission entityPermission, ProfileValue value) { 341 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey()); 342 } 343 344 public Profile getEntityFromValue(Session session, EntityPermission entityPermission, ProfileValue value) { 345 return getEntityFromPK(session, entityPermission, value.getPrimaryKey()); 346 } 347 348 public Profile getEntityFromPK(EntityPermission entityPermission, ProfilePK pk) 349 throws PersistenceDatabaseException { 350 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk); 351 } 352 353 public Profile getEntityFromCache(Session session, ProfilePK pk) { 354 ProfileValue _value = (ProfileValue)session.getValueCache().get(pk); 355 356 return _value == null ? null : new Profile(_value, EntityPermission.READ_ONLY); 357 } 358 359 public Profile getEntityFromPK(Session session, EntityPermission entityPermission, ProfilePK pk) 360 throws PersistenceDatabaseException { 361 Profile _entity; 362 363 // See if we already have the entity in the session cache 364 _entity = (Profile)session.getEntity(pk); 365 if(_entity != null) { 366 // If the requested permission is READ_WRITE, and the cached permission is 367 // READ_ONLY, then pretend that the cached object wasn't found, and create 368 // a new entity that is READ_WRITE. 369 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 370 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 371 _entity = null; 372 } 373 } 374 375 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 376 _entity = getEntityFromCache(session, pk); 377 } 378 379 if(_entity == null) { 380 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 381 long _entityId = pk.getEntityId(); 382 ResultSet _rs = null; 383 384 try { 385 _ps.setLong(1, _entityId); 386 _rs = _ps.executeQuery(); 387 if(_rs.next()) { 388 _entity = getEntityFromResultSet(session, entityPermission, _rs); 389 } 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 403 return _entity; 404 } 405 406 public Set<ProfilePK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 407 throws PersistenceDatabaseException { 408 Set<ProfilePK> _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 = getPKsFromResultSetAsSet(_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 java.util.List<ProfilePK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 435 throws PersistenceDatabaseException { 436 java.util.List<ProfilePK> _pks; 437 ResultSet _rs = null; 438 439 try { 440 if(params.length != 0) { 441 Session.setQueryParams(ps, params); 442 } 443 444 _rs = ps.executeQuery(); 445 _pks = getPKsFromResultSetAsList(_rs); 446 _rs.close(); 447 } catch (SQLException se) { 448 throw new PersistenceDatabaseException(se); 449 } finally { 450 if(_rs != null) { 451 try { 452 _rs.close(); 453 } catch (SQLException se) { 454 // do nothing 455 } 456 } 457 } 458 459 return _pks; 460 } 461 462 public ProfilePK getPKFromQuery(PreparedStatement ps, final Object... params) 463 throws PersistenceDatabaseException { 464 ProfilePK _pk = null; 465 ResultSet _rs = null; 466 467 try { 468 if(params.length != 0) { 469 Session.setQueryParams(ps, params); 470 } 471 472 _rs = ps.executeQuery(); 473 if(_rs.next()) { 474 _pk = getPKFromResultSet(_rs); 475 } 476 _rs.close(); 477 } catch (SQLException se) { 478 throw new PersistenceDatabaseException(se); 479 } finally { 480 if(_rs != null) { 481 try { 482 _rs.close(); 483 } catch (SQLException se) { 484 // do nothing 485 } 486 } 487 } 488 489 return _pk; 490 } 491 492 public java.util.List<Profile> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 493 throws PersistenceDatabaseException { 494 PreparedStatement ps = session.prepareStatement(ProfileFactory.class, queryMap.get(entityPermission)); 495 496 return getEntitiesFromQuery(session, entityPermission, ps, params); 497 } 498 499 public java.util.List<Profile> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 500 throws PersistenceDatabaseException { 501 Session session = ThreadSession.currentSession(); 502 PreparedStatement ps = session.prepareStatement(ProfileFactory.class, queryMap.get(entityPermission)); 503 504 return getEntitiesFromQuery(session, entityPermission, ps, params); 505 } 506 507 public java.util.List<Profile> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 508 throws PersistenceDatabaseException { 509 PreparedStatement ps = session.prepareStatement(ProfileFactory.class, queryMap.get(entityPermission)); 510 511 return getEntitiesFromQuery(session, entityPermission, ps); 512 } 513 514 public java.util.List<Profile> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 515 throws PersistenceDatabaseException { 516 Session session = ThreadSession.currentSession(); 517 PreparedStatement ps = session.prepareStatement(ProfileFactory.class, queryMap.get(entityPermission)); 518 519 return getEntitiesFromQuery(session, entityPermission, ps); 520 } 521 522 public java.util.List<Profile> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps) 523 throws PersistenceDatabaseException { 524 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps); 525 } 526 527 public java.util.List<Profile> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 528 throws PersistenceDatabaseException { 529 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 530 } 531 532 public java.util.List<Profile> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 533 throws PersistenceDatabaseException { 534 java.util.List<Profile> _entities; 535 ResultSet _rs = null; 536 537 try { 538 if(params.length != 0) { 539 Session.setQueryParams(ps, params); 540 } 541 542 _rs = ps.executeQuery(); 543 _entities = getEntitiesFromResultSet(session, entityPermission, _rs); 544 _rs.close(); 545 } catch (SQLException se) { 546 throw new PersistenceDatabaseException(se); 547 } finally { 548 if(_rs != null) { 549 try { 550 _rs.close(); 551 } catch (SQLException se) { 552 // do nothing 553 } 554 } 555 } 556 557 return _entities; 558 } 559 560 public Profile getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 561 throws PersistenceDatabaseException { 562 PreparedStatement ps = session.prepareStatement(ProfileFactory.class, queryMap.get(entityPermission)); 563 564 return getEntityFromQuery(session, entityPermission, ps, params); 565 } 566 567 public Profile getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 568 throws PersistenceDatabaseException { 569 Session session = ThreadSession.currentSession(); 570 PreparedStatement ps = session.prepareStatement(ProfileFactory.class, queryMap.get(entityPermission)); 571 572 return getEntityFromQuery(session, entityPermission, ps, params); 573 } 574 575 public Profile getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 576 throws PersistenceDatabaseException { 577 PreparedStatement ps = session.prepareStatement(ProfileFactory.class, queryMap.get(entityPermission)); 578 579 return getEntityFromQuery(session, entityPermission, ps); 580 } 581 582 public Profile getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 583 throws PersistenceDatabaseException { 584 Session session = ThreadSession.currentSession(); 585 PreparedStatement ps = session.prepareStatement(ProfileFactory.class, queryMap.get(entityPermission)); 586 587 return getEntityFromQuery(session, entityPermission, ps); 588 } 589 590 public Profile getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps) 591 throws PersistenceDatabaseException { 592 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps); 593 } 594 595 public Profile getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 596 throws PersistenceDatabaseException { 597 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 598 } 599 600 public Profile getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 601 throws PersistenceDatabaseException { 602 Profile _entity = null; 603 ResultSet _rs = null; 604 605 try { 606 if(params.length != 0) { 607 Session.setQueryParams(ps, params); 608 } 609 610 _rs = ps.executeQuery(); 611 if(_rs.next()) { 612 _entity = getEntityFromResultSet(session, entityPermission, _rs); 613 } 614 _rs.close(); 615 } catch (SQLException se) { 616 throw new PersistenceDatabaseException(se); 617 } finally { 618 if(_rs != null) { 619 try { 620 _rs.close(); 621 } catch (SQLException se) { 622 // do nothing 623 } 624 } 625 } 626 627 return _entity; 628 } 629 630 public java.util.List<Profile> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 631 throws PersistenceDatabaseException { 632 return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 633 } 634 635 public java.util.List<Profile> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 636 throws PersistenceDatabaseException { 637 java.util.List<Profile> _result = new ArrayList<>(); 638 639 try { 640 while(rs.next()) { 641 _result.add(getEntityFromResultSet(session, entityPermission, rs)); 642 } 643 } catch (SQLException se) { 644 throw new PersistenceDatabaseException(se); 645 } 646 647 return _result; 648 } 649 650 public Profile getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 651 throws PersistenceDatabaseException { 652 return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 653 } 654 655 public Profile getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 656 throws PersistenceDatabaseException { 657 Profile _entity; 658 659 try { 660 Long prfl_profileid = rs.getLong(PRFL_PROFILEID); 661 ProfilePK _pk = new ProfilePK(prfl_profileid); 662 663 // See if we already have the entity in the session cache 664 _entity = (Profile)session.getEntity(_pk); 665 if(_entity != null) { 666 // If the requested permission is READ_WRITE, and the cached permission is 667 // READ_ONLY, then pretend that the cached object wasn't found, and create 668 // a new entity that is READ_WRITE. 669 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 670 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 671 _entity = null; 672 } 673 } 674 boolean foundInSessionCache = _entity != null; 675 676 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 677 _entity = getEntityFromCache(session, _pk); 678 } 679 680 if(_entity == null) { 681 Long prfl_par_partyid = rs.getLong(PRFL_PAR_PARTYID); 682 if(rs.wasNull()) 683 prfl_par_partyid = null; 684 685 String prfl_nickname = rs.getString(PRFL_NICKNAME); 686 if(rs.wasNull()) 687 prfl_nickname = null; 688 689 Long prfl_icn_iconid = rs.getLong(PRFL_ICN_ICONID); 690 if(rs.wasNull()) 691 prfl_icn_iconid = null; 692 693 String prfl_pronunciation = rs.getString(PRFL_PRONUNCIATION); 694 if(rs.wasNull()) 695 prfl_pronunciation = null; 696 697 Long prfl_gndr_genderid = rs.getLong(PRFL_GNDR_GENDERID); 698 if(rs.wasNull()) 699 prfl_gndr_genderid = null; 700 701 String prfl_pronouns = rs.getString(PRFL_PRONOUNS); 702 if(rs.wasNull()) 703 prfl_pronouns = null; 704 705 Integer prfl_birthday = rs.getInt(PRFL_BIRTHDAY); 706 if(rs.wasNull()) 707 prfl_birthday = null; 708 709 Long prfl_bdyf_birthdayformatid = rs.getLong(PRFL_BDYF_BIRTHDAYFORMATID); 710 if(rs.wasNull()) 711 prfl_bdyf_birthdayformatid = null; 712 713 String prfl_occupation = rs.getString(PRFL_OCCUPATION); 714 if(rs.wasNull()) 715 prfl_occupation = null; 716 717 String prfl_hobbies = rs.getString(PRFL_HOBBIES); 718 if(rs.wasNull()) 719 prfl_hobbies = null; 720 721 String prfl_location = rs.getString(PRFL_LOCATION); 722 if(rs.wasNull()) 723 prfl_location = null; 724 725 Long prfl_biomimetypeid = rs.getLong(PRFL_BIOMIMETYPEID); 726 if(rs.wasNull()) 727 prfl_biomimetypeid = null; 728 729 String prfl_bio = rs.getString(PRFL_BIO); 730 if(rs.wasNull()) 731 prfl_bio = null; 732 733 Long prfl_signaturemimetypeid = rs.getLong(PRFL_SIGNATUREMIMETYPEID); 734 if(rs.wasNull()) 735 prfl_signaturemimetypeid = null; 736 737 String prfl_signature = rs.getString(PRFL_SIGNATURE); 738 if(rs.wasNull()) 739 prfl_signature = null; 740 741 Long prfl_fromtime = rs.getLong(PRFL_FROMTIME); 742 if(rs.wasNull()) 743 prfl_fromtime = null; 744 745 Long prfl_thrutime = rs.getLong(PRFL_THRUTIME); 746 if(rs.wasNull()) 747 prfl_thrutime = null; 748 749 ProfileValue _value = new ProfileValue(_pk, prfl_par_partyid == null? null: new PartyPK(prfl_par_partyid), prfl_nickname, prfl_icn_iconid == null? null: new IconPK(prfl_icn_iconid), prfl_pronunciation, prfl_gndr_genderid == null? null: new GenderPK(prfl_gndr_genderid), prfl_pronouns, prfl_birthday, prfl_bdyf_birthdayformatid == null? null: new BirthdayFormatPK(prfl_bdyf_birthdayformatid), prfl_occupation, prfl_hobbies, prfl_location, prfl_biomimetypeid == null? null: new MimeTypePK(prfl_biomimetypeid), prfl_bio, prfl_signaturemimetypeid == null? null: new MimeTypePK(prfl_signaturemimetypeid), prfl_signature, prfl_fromtime, prfl_thrutime); 750 _entity = new Profile(_value, entityPermission); 751 } 752 753 if(!foundInSessionCache) { 754 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 755 session.putReadOnlyEntity(_pk, _entity); 756 session.getValueCache().put(_entity.getProfileValue()); 757 } else { 758 session.putReadWriteEntity(_pk, _entity); 759 } 760 } 761 } catch (SQLException se) { 762 throw new PersistenceDatabaseException(se); 763 } 764 765 return _entity; 766 } 767 768 public Profile create(Session session, Party party, String nickname, Icon icon, String pronunciation, Gender gender, String pronouns, Integer birthday, BirthdayFormat birthdayFormat, String occupation, String hobbies, String location, MimeType bioMimeType, String bio, MimeType signatureMimeType, String signature, Long fromTime, Long thruTime) 769 throws PersistenceDatabaseException, PersistenceNotNullException { 770 return create(session, party == null ? null : party.getPrimaryKey(), nickname, icon == null ? null : icon.getPrimaryKey(), pronunciation, gender == null ? null : gender.getPrimaryKey(), pronouns, birthday, birthdayFormat == null ? null : birthdayFormat.getPrimaryKey(), occupation, hobbies, location, bioMimeType == null ? null : bioMimeType.getPrimaryKey(), bio, signatureMimeType == null ? null : signatureMimeType.getPrimaryKey(), signature, fromTime, thruTime); 771 } 772 773 public Profile create(Party party, String nickname, Icon icon, String pronunciation, Gender gender, String pronouns, Integer birthday, BirthdayFormat birthdayFormat, String occupation, String hobbies, String location, MimeType bioMimeType, String bio, MimeType signatureMimeType, String signature, Long fromTime, Long thruTime) 774 throws PersistenceDatabaseException, PersistenceNotNullException { 775 return create(ThreadSession.currentSession(), party == null ? null : party.getPrimaryKey(), nickname, icon == null ? null : icon.getPrimaryKey(), pronunciation, gender == null ? null : gender.getPrimaryKey(), pronouns, birthday, birthdayFormat == null ? null : birthdayFormat.getPrimaryKey(), occupation, hobbies, location, bioMimeType == null ? null : bioMimeType.getPrimaryKey(), bio, signatureMimeType == null ? null : signatureMimeType.getPrimaryKey(), signature, fromTime, thruTime); 776 } 777 778 private void bindForCreate(PreparedStatement _ps, ProfileValue _value) 779 throws SQLException { 780 _ps.setLong(1, _value.getEntityId()); 781 782 PartyPK prfl_par_partyid = _value.getPartyPK(); 783 if(prfl_par_partyid == null) 784 _ps.setNull(2, Types.BIGINT); 785 else 786 _ps.setLong(2, prfl_par_partyid.getEntityId()); 787 788 String prfl_nickname = _value.getNickname(); 789 if(prfl_nickname == null) 790 _ps.setNull(3, Types.VARCHAR); 791 else 792 _ps.setString(3, prfl_nickname); 793 794 IconPK prfl_icn_iconid = _value.getIconPK(); 795 if(prfl_icn_iconid == null) 796 _ps.setNull(4, Types.BIGINT); 797 else 798 _ps.setLong(4, prfl_icn_iconid.getEntityId()); 799 800 String prfl_pronunciation = _value.getPronunciation(); 801 if(prfl_pronunciation == null) 802 _ps.setNull(5, Types.VARCHAR); 803 else 804 _ps.setString(5, prfl_pronunciation); 805 806 GenderPK prfl_gndr_genderid = _value.getGenderPK(); 807 if(prfl_gndr_genderid == null) 808 _ps.setNull(6, Types.BIGINT); 809 else 810 _ps.setLong(6, prfl_gndr_genderid.getEntityId()); 811 812 String prfl_pronouns = _value.getPronouns(); 813 if(prfl_pronouns == null) 814 _ps.setNull(7, Types.VARCHAR); 815 else 816 _ps.setString(7, prfl_pronouns); 817 818 Integer prfl_birthday = _value.getBirthday(); 819 if(prfl_birthday == null) 820 _ps.setNull(8, Types.INTEGER); 821 else 822 _ps.setInt(8, prfl_birthday); 823 824 BirthdayFormatPK prfl_bdyf_birthdayformatid = _value.getBirthdayFormatPK(); 825 if(prfl_bdyf_birthdayformatid == null) 826 _ps.setNull(9, Types.BIGINT); 827 else 828 _ps.setLong(9, prfl_bdyf_birthdayformatid.getEntityId()); 829 830 String prfl_occupation = _value.getOccupation(); 831 if(prfl_occupation == null) 832 _ps.setNull(10, Types.VARCHAR); 833 else 834 _ps.setString(10, prfl_occupation); 835 836 String prfl_hobbies = _value.getHobbies(); 837 if(prfl_hobbies == null) 838 _ps.setNull(11, Types.VARCHAR); 839 else 840 _ps.setString(11, prfl_hobbies); 841 842 String prfl_location = _value.getLocation(); 843 if(prfl_location == null) 844 _ps.setNull(12, Types.VARCHAR); 845 else 846 _ps.setString(12, prfl_location); 847 848 MimeTypePK prfl_biomimetypeid = _value.getBioMimeTypePK(); 849 if(prfl_biomimetypeid == null) 850 _ps.setNull(13, Types.BIGINT); 851 else 852 _ps.setLong(13, prfl_biomimetypeid.getEntityId()); 853 854 String prfl_bio = _value.getBio(); 855 if(prfl_bio == null) 856 _ps.setNull(14, Types.VARCHAR); 857 else 858 _ps.setString(14, prfl_bio); 859 860 MimeTypePK prfl_signaturemimetypeid = _value.getSignatureMimeTypePK(); 861 if(prfl_signaturemimetypeid == null) 862 _ps.setNull(15, Types.BIGINT); 863 else 864 _ps.setLong(15, prfl_signaturemimetypeid.getEntityId()); 865 866 String prfl_signature = _value.getSignature(); 867 if(prfl_signature == null) 868 _ps.setNull(16, Types.VARCHAR); 869 else 870 _ps.setString(16, prfl_signature); 871 872 Long prfl_fromtime = _value.getFromTime(); 873 if(prfl_fromtime == null) 874 _ps.setNull(17, Types.BIGINT); 875 else 876 _ps.setLong(17, prfl_fromtime); 877 878 Long prfl_thrutime = _value.getThruTime(); 879 if(prfl_thrutime == null) 880 _ps.setNull(18, Types.BIGINT); 881 else 882 _ps.setLong(18, prfl_thrutime); 883 884 } 885 886 public Profile create(Session session, PartyPK partyPK, String nickname, IconPK iconPK, String pronunciation, GenderPK genderPK, String pronouns, Integer birthday, BirthdayFormatPK birthdayFormatPK, String occupation, String hobbies, String location, MimeTypePK bioMimeTypePK, String bio, MimeTypePK signatureMimeTypePK, String signature, Long fromTime, Long thruTime) 887 throws PersistenceDatabaseException, PersistenceNotNullException { 888 ProfilePK _pk = getNextPK(); 889 ProfileValue _value = new ProfileValue(_pk, partyPK, nickname, iconPK, pronunciation, genderPK, pronouns, birthday, birthdayFormatPK, occupation, hobbies, location, bioMimeTypePK, bio, signatureMimeTypePK, signature, fromTime, thruTime); 890 891 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 892 893 try { 894 bindForCreate(_ps, _value); 895 896 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 897 int _count = _ps.executeUpdate(); 898 899 if(_count != 1) { 900 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 901 } 902 } else { 903 _ps.executeUpdate(); 904 } 905 906 session.getValueCache().put(_value); 907 } catch (SQLException se) { 908 throw new PersistenceDatabaseException(se); 909 } 910 911 Profile _entity = new Profile(_value, EntityPermission.READ_ONLY); 912 session.putReadOnlyEntity(_pk, _entity); 913 914 return _entity; 915 } 916 917 public Profile create(PartyPK partyPK, String nickname, IconPK iconPK, String pronunciation, GenderPK genderPK, String pronouns, Integer birthday, BirthdayFormatPK birthdayFormatPK, String occupation, String hobbies, String location, MimeTypePK bioMimeTypePK, String bio, MimeTypePK signatureMimeTypePK, String signature, Long fromTime, Long thruTime) 918 throws PersistenceDatabaseException, PersistenceNotNullException { 919 return create(ThreadSession.currentSession(), partyPK, nickname, iconPK, pronunciation, genderPK, pronouns, birthday, birthdayFormatPK, occupation, hobbies, location, bioMimeTypePK, bio, signatureMimeTypePK, signature, fromTime, thruTime); 920 } 921 922 public void create(Session session, Collection<ProfileValue> _values) 923 throws PersistenceDatabaseException, PersistenceNotNullException { 924 int _size = _values.size(); 925 926 if(_size > 0) { 927 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 928 List<ProfileValue> _cacheValues = new ArrayList<>(_size); 929 930 try { 931 for(ProfileValue _value : _values) { 932 _value.setEntityId(entityIdGenerator.getNextEntityId()); 933 bindForCreate(_ps, _value); 934 935 _ps.addBatch(); 936 937 _cacheValues.add(_value); 938 } 939 940 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 941 int[] _counts = _ps.executeBatch(); 942 943 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 944 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 945 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 946 } 947 } 948 } else { 949 _ps.executeBatch(); 950 } 951 952 _ps.clearBatch(); 953 } catch (SQLException se) { 954 throw new PersistenceDatabaseException(se); 955 } 956 957 _cacheValues.forEach((_cacheValue) -> { 958 Profile _cacheEntity = new Profile(_cacheValue, EntityPermission.READ_ONLY); 959 960 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 961 }); 962 } 963 } 964 965 public void create(Collection<ProfileValue> _values) 966 throws PersistenceDatabaseException, PersistenceNotNullException { 967 create(ThreadSession.currentSession(), _values); 968 } 969 970 private boolean bindForStore(PreparedStatement _ps, ProfileValue _value) 971 throws SQLException { 972 boolean _hasBeenModified = _value.hasBeenModified(); 973 974 if(_hasBeenModified) { 975 PartyPK prfl_par_partyid = _value.getPartyPK(); 976 if(prfl_par_partyid == null) 977 _ps.setNull(1, Types.BIGINT); 978 else 979 _ps.setLong(1, prfl_par_partyid.getEntityId()); 980 981 String prfl_nickname = _value.getNickname(); 982 if(prfl_nickname == null) 983 _ps.setNull(2, Types.VARCHAR); 984 else 985 _ps.setString(2, prfl_nickname); 986 987 IconPK prfl_icn_iconid = _value.getIconPK(); 988 if(prfl_icn_iconid == null) 989 _ps.setNull(3, Types.BIGINT); 990 else 991 _ps.setLong(3, prfl_icn_iconid.getEntityId()); 992 993 String prfl_pronunciation = _value.getPronunciation(); 994 if(prfl_pronunciation == null) 995 _ps.setNull(4, Types.VARCHAR); 996 else 997 _ps.setString(4, prfl_pronunciation); 998 999 GenderPK prfl_gndr_genderid = _value.getGenderPK(); 1000 if(prfl_gndr_genderid == null) 1001 _ps.setNull(5, Types.BIGINT); 1002 else 1003 _ps.setLong(5, prfl_gndr_genderid.getEntityId()); 1004 1005 String prfl_pronouns = _value.getPronouns(); 1006 if(prfl_pronouns == null) 1007 _ps.setNull(6, Types.VARCHAR); 1008 else 1009 _ps.setString(6, prfl_pronouns); 1010 1011 Integer prfl_birthday = _value.getBirthday(); 1012 if(prfl_birthday == null) 1013 _ps.setNull(7, Types.INTEGER); 1014 else 1015 _ps.setInt(7, prfl_birthday); 1016 1017 BirthdayFormatPK prfl_bdyf_birthdayformatid = _value.getBirthdayFormatPK(); 1018 if(prfl_bdyf_birthdayformatid == null) 1019 _ps.setNull(8, Types.BIGINT); 1020 else 1021 _ps.setLong(8, prfl_bdyf_birthdayformatid.getEntityId()); 1022 1023 String prfl_occupation = _value.getOccupation(); 1024 if(prfl_occupation == null) 1025 _ps.setNull(9, Types.VARCHAR); 1026 else 1027 _ps.setString(9, prfl_occupation); 1028 1029 String prfl_hobbies = _value.getHobbies(); 1030 if(prfl_hobbies == null) 1031 _ps.setNull(10, Types.VARCHAR); 1032 else 1033 _ps.setString(10, prfl_hobbies); 1034 1035 String prfl_location = _value.getLocation(); 1036 if(prfl_location == null) 1037 _ps.setNull(11, Types.VARCHAR); 1038 else 1039 _ps.setString(11, prfl_location); 1040 1041 MimeTypePK prfl_biomimetypeid = _value.getBioMimeTypePK(); 1042 if(prfl_biomimetypeid == null) 1043 _ps.setNull(12, Types.BIGINT); 1044 else 1045 _ps.setLong(12, prfl_biomimetypeid.getEntityId()); 1046 1047 String prfl_bio = _value.getBio(); 1048 if(prfl_bio == null) 1049 _ps.setNull(13, Types.VARCHAR); 1050 else 1051 _ps.setString(13, prfl_bio); 1052 1053 MimeTypePK prfl_signaturemimetypeid = _value.getSignatureMimeTypePK(); 1054 if(prfl_signaturemimetypeid == null) 1055 _ps.setNull(14, Types.BIGINT); 1056 else 1057 _ps.setLong(14, prfl_signaturemimetypeid.getEntityId()); 1058 1059 String prfl_signature = _value.getSignature(); 1060 if(prfl_signature == null) 1061 _ps.setNull(15, Types.VARCHAR); 1062 else 1063 _ps.setString(15, prfl_signature); 1064 1065 Long prfl_fromtime = _value.getFromTime(); 1066 if(prfl_fromtime == null) 1067 _ps.setNull(16, Types.BIGINT); 1068 else 1069 _ps.setLong(16, prfl_fromtime); 1070 1071 Long prfl_thrutime = _value.getThruTime(); 1072 if(prfl_thrutime == null) 1073 _ps.setNull(17, Types.BIGINT); 1074 else 1075 _ps.setLong(17, prfl_thrutime); 1076 1077 _ps.setLong(18, _value.getPrimaryKey().getEntityId()); 1078 1079 _value.clearHasBeenModified(); 1080 } 1081 1082 return _hasBeenModified; 1083 } 1084 1085 @Override 1086 public void store(Session session, Profile entity) 1087 throws PersistenceDatabaseException { 1088 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 1089 1090 try { 1091 ProfileValue _value = entity.getProfileValue(); 1092 1093 if(bindForStore(_ps, _value)) { 1094 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 1095 int _count = _ps.executeUpdate(); 1096 1097 if(_count != 1) { 1098 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 1099 } 1100 } else { 1101 _ps.executeUpdate(); 1102 } 1103 1104 session.getValueCache().put(_value); 1105 } 1106 } catch (SQLException se) { 1107 throw new PersistenceDatabaseException(se); 1108 } 1109 } 1110 1111 @Override 1112 public void store(Session session, Collection<Profile> entities) 1113 throws PersistenceDatabaseException { 1114 if(entities.size() > 0) { 1115 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 1116 int _modifiedEntities = 0; 1117 1118 try { 1119 for(Profile entity : entities) { 1120 if(bindForStore(_ps, entity.getProfileValue())) { 1121 _ps.addBatch(); 1122 _modifiedEntities++; 1123 } 1124 } 1125 1126 if(_modifiedEntities != 0) { 1127 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 1128 int[] _counts = _ps.executeBatch(); 1129 1130 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1131 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1132 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1133 } 1134 } 1135 } else { 1136 _ps.executeBatch(); 1137 } 1138 1139 _ps.clearBatch(); 1140 1141 entities.forEach((entity) -> { 1142 session.getValueCache().put(entity.getProfileValue()); 1143 }); 1144 } 1145 } catch (SQLException se) { 1146 throw new PersistenceDatabaseException(se); 1147 } 1148 } 1149 } 1150 1151 @Override 1152 public void store(Collection<Profile> entities) 1153 throws PersistenceDatabaseException { 1154 store(ThreadSession.currentSession(), entities); 1155 } 1156 1157 @Override 1158 public void remove(Session session, Profile entity) 1159 throws PersistenceDatabaseException { 1160 remove(session, entity.getPrimaryKey()); 1161 } 1162 1163 @Override 1164 public void remove(Session session, ProfilePK pk) 1165 throws PersistenceDatabaseException { 1166 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1167 long _entityId = pk.getEntityId(); 1168 1169 try { 1170 _ps.setLong(1, _entityId); 1171 1172 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1173 int _count = _ps.executeUpdate(); 1174 1175 if(_count != 1) { 1176 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 1177 } 1178 } else { 1179 _ps.executeUpdate(); 1180 } 1181 1182 session.getValueCache().remove(pk); 1183 } catch (SQLException se) { 1184 throw new PersistenceDatabaseException(se); 1185 } 1186 1187 session.removed(pk, false); 1188 } 1189 1190 @Override 1191 public void remove(Session session, Collection<ProfilePK> pks) 1192 throws PersistenceDatabaseException { 1193 if(pks.size() > 0) { 1194 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1195 int _modifiedEntities = 0; 1196 1197 try { 1198 for(ProfilePK pk : pks) { 1199 long _entityId = pk.getEntityId(); 1200 1201 _ps.setLong(1, _entityId); 1202 1203 _ps.addBatch(); 1204 _modifiedEntities++; 1205 } 1206 1207 if(_modifiedEntities != 0) { 1208 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1209 int[] _counts = _ps.executeBatch(); 1210 1211 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1212 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1213 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1214 } 1215 } 1216 } else { 1217 _ps.executeBatch(); 1218 } 1219 1220 _ps.clearBatch(); 1221 1222 pks.forEach((pk) -> { 1223 session.getValueCache().remove(pk); 1224 }); 1225 } 1226 } catch (SQLException se) { 1227 throw new PersistenceDatabaseException(se); 1228 } 1229 1230 pks.forEach((pk) -> { 1231 session.removed(pk, true); 1232 }); 1233 } 1234 } 1235 1236 @Override 1237 public void remove(Collection<ProfilePK> pks) 1238 throws PersistenceDatabaseException { 1239 remove(ThreadSession.currentSession(), pks); 1240 } 1241 1242 @Override 1243 public boolean validPK(Session session, ProfilePK pk) 1244 throws PersistenceDatabaseException { 1245 boolean valid = false; 1246 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1247 ResultSet _rs = null; 1248 1249 try { 1250 _ps.setLong(1, pk.getEntityId()); 1251 1252 _rs = _ps.executeQuery(); 1253 if(_rs.next()) { 1254 long _count = _rs.getLong(1); 1255 if(_rs.wasNull()) 1256 _count = 0; 1257 1258 if(_count == 1) 1259 valid = true; 1260 } 1261 } catch (SQLException se) { 1262 throw new PersistenceDatabaseException(se); 1263 } finally { 1264 if(_rs != null) { 1265 try { 1266 _rs.close(); 1267 } catch (SQLException se) { 1268 // do nothing 1269 } 1270 } 1271 } 1272 1273 return valid; 1274 } 1275 1276}