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