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