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