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