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 * LocationNameElementDescriptionFactory.java 021 */ 022 023package com.echothree.model.data.warehouse.server.factory; 024 025import com.echothree.model.data.warehouse.common.pk.LocationNameElementPK; 026import com.echothree.model.data.party.common.pk.LanguagePK; 027 028import com.echothree.model.data.warehouse.server.entity.LocationNameElement; 029import com.echothree.model.data.party.server.entity.Language; 030 031import com.echothree.model.data.warehouse.common.LocationNameElementDescriptionConstants; 032import com.echothree.model.data.warehouse.common.pk.LocationNameElementDescriptionPK; 033import com.echothree.model.data.warehouse.server.value.LocationNameElementDescriptionValue; 034import com.echothree.model.data.warehouse.server.entity.LocationNameElementDescription; 035import com.echothree.util.common.exception.PersistenceDatabaseException; 036import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 037import com.echothree.util.common.exception.PersistenceNotNullException; 038import com.echothree.util.server.persistence.BaseFactory; 039import com.echothree.util.server.persistence.EntityIdGenerator; 040import com.echothree.util.server.persistence.EntityPermission; 041import com.echothree.util.server.persistence.PersistenceDebugFlags; 042import com.echothree.util.server.persistence.Session; 043import java.sql.PreparedStatement; 044import java.sql.ResultSet; 045import java.sql.SQLException; 046import java.sql.Types; 047import java.io.ByteArrayInputStream; 048import java.io.StringReader; 049import java.util.ArrayList; 050import java.util.Collection; 051import java.util.HashSet; 052import java.util.List; 053import java.util.Map; 054import java.util.Set; 055import javax.enterprise.context.ApplicationScoped; 056import javax.enterprise.inject.spi.CDI; 057import javax.inject.Inject; 058import org.jooq.ResultQuery; 059import org.slf4j.Logger; 060import org.slf4j.LoggerFactory; 061 062@ApplicationScoped 063public class LocationNameElementDescriptionFactory 064 implements BaseFactory<LocationNameElementDescriptionPK, LocationNameElementDescription> { 065 066 @Inject 067 Session session; 068 069 //private static final Logger log = LoggerFactory.getLogger(LocationNameElementDescriptionFactory.class); 070 071 final private static String SQL_SELECT_READ_ONLY = "SELECT locned_locationnameelementdescriptionid, locned_locne_locationnameelementid, locned_lang_languageid, locned_description, locned_fromtime, locned_thrutime FROM locationnameelementdescriptions WHERE locned_locationnameelementdescriptionid = ?"; 072 final private static String SQL_SELECT_READ_WRITE = "SELECT locned_locationnameelementdescriptionid, locned_locne_locationnameelementid, locned_lang_languageid, locned_description, locned_fromtime, locned_thrutime FROM locationnameelementdescriptions WHERE locned_locationnameelementdescriptionid = ? FOR UPDATE"; 073 final private static String SQL_INSERT = "INSERT INTO locationnameelementdescriptions (locned_locationnameelementdescriptionid, locned_locne_locationnameelementid, locned_lang_languageid, locned_description, locned_fromtime, locned_thrutime) VALUES (?, ?, ?, ?, ?, ?)"; 074 final private static String SQL_UPDATE = "UPDATE locationnameelementdescriptions SET locned_locne_locationnameelementid = ?, locned_lang_languageid = ?, locned_description = ?, locned_fromtime = ?, locned_thrutime = ? WHERE locned_locationnameelementdescriptionid = ?"; 075 final private static String SQL_DELETE = "DELETE FROM locationnameelementdescriptions WHERE locned_locationnameelementdescriptionid = ?"; 076 final private static String SQL_VALID = "SELECT COUNT(*) FROM locationnameelementdescriptions WHERE locned_locationnameelementdescriptionid = ?"; 077 078 final public static String LOCNED_LOCATIONNAMEELEMENTDESCRIPTIONID = "locned_locationnameelementdescriptionid"; 079 final public static String LOCNED_LOCNE_LOCATIONNAMEELEMENTID = "locned_locne_locationnameelementid"; 080 final public static String LOCNED_LANG_LANGUAGEID = "locned_lang_languageid"; 081 final public static String LOCNED_DESCRIPTION = "locned_description"; 082 final public static String LOCNED_FROMTIME = "locned_fromtime"; 083 final public static String LOCNED_THRUTIME = "locned_thrutime"; 084 085 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(LocationNameElementDescriptionConstants.COMPONENT_VENDOR_NAME, LocationNameElementDescriptionConstants.ENTITY_TYPE_NAME); 086 087 /** Creates a new instance of LocationNameElementDescriptionFactory */ 088 protected LocationNameElementDescriptionFactory() { 089 super(); 090 } 091 092 public static LocationNameElementDescriptionFactory getInstance() { 093 return CDI.current().select(LocationNameElementDescriptionFactory.class).get(); 094 } 095 096 @Override 097 public String getComponentVendorName() { 098 return LocationNameElementDescriptionConstants.COMPONENT_VENDOR_NAME; 099 } 100 101 @Override 102 public String getEntityTypeName() { 103 return LocationNameElementDescriptionConstants.ENTITY_TYPE_NAME; 104 } 105 106 public PreparedStatement prepareStatement(String query) { 107 return session.prepareStatement(query); 108 } 109 110 public LocationNameElementDescriptionPK getNextPK() { 111 return new LocationNameElementDescriptionPK(entityIdGenerator.getNextEntityId()); 112 } 113 114 public Set<LocationNameElementDescriptionPK> getPKsFromResultSetAsSet(ResultSet rs) 115 throws PersistenceDatabaseException { 116 Set<LocationNameElementDescriptionPK> _result = new HashSet<>(); 117 118 try { 119 while(rs.next()) { 120 _result.add(getPKFromResultSet(rs)); 121 } 122 } catch (SQLException se) { 123 throw new PersistenceDatabaseException(se); 124 } 125 126 return _result; 127 } 128 129 public java.util.List<LocationNameElementDescriptionPK> getPKsFromResultSetAsList(ResultSet rs) 130 throws PersistenceDatabaseException { 131 java.util.List<LocationNameElementDescriptionPK> _result = new ArrayList<>(); 132 133 try { 134 while(rs.next()) { 135 _result.add(getPKFromResultSet(rs)); 136 } 137 } catch (SQLException se) { 138 throw new PersistenceDatabaseException(se); 139 } 140 141 return _result; 142 } 143 144 public LocationNameElementDescriptionPK getPKFromResultSet(ResultSet rs) 145 throws PersistenceDatabaseException { 146 LocationNameElementDescriptionPK _result; 147 148 try { 149 long locned_locationnameelementdescriptionid = rs.getLong(LOCNED_LOCATIONNAMEELEMENTDESCRIPTIONID); 150 Long _entityId = rs.wasNull() ? null : locned_locationnameelementdescriptionid; 151 152 _result = new LocationNameElementDescriptionPK(_entityId); 153 } catch (SQLException se) { 154 throw new PersistenceDatabaseException(se); 155 } 156 157 return _result; 158 } 159 160 public java.util.List<LocationNameElementDescriptionValue> getValuesFromPKs(Collection<LocationNameElementDescriptionPK> pks) 161 throws PersistenceDatabaseException { 162 java.util.List<LocationNameElementDescriptionValue> _values = new ArrayList<>(pks.size()); 163 164 for(LocationNameElementDescriptionPK _pk: pks) { 165 _values.add(getValueFromPK(_pk)); 166 } 167 168 return _values; 169 } 170 171 public LocationNameElementDescriptionValue getValueFromPK(LocationNameElementDescriptionPK pk) 172 throws PersistenceDatabaseException { 173 LocationNameElementDescriptionValue _value; 174 175 // See if we already have the entity in the session cache 176 LocationNameElementDescription _entity = (LocationNameElementDescription)session.getEntity(pk); 177 if(_entity == null) 178 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getLocationNameElementDescriptionValue(); 179 else 180 _value = _entity.getLocationNameElementDescriptionValue(); 181 182 return _value; 183 } 184 185 public java.util.List<LocationNameElementDescriptionValue> getValuesFromResultSet(ResultSet rs) 186 throws PersistenceDatabaseException { 187 java.util.List<LocationNameElementDescriptionValue> _result = new ArrayList<>(); 188 189 try { 190 while(rs.next()) { 191 _result.add(getValueFromResultSet(rs)); 192 } 193 } catch (SQLException se) { 194 throw new PersistenceDatabaseException(se); 195 } 196 197 return _result; 198 } 199 200 public LocationNameElementDescriptionValue getValueFromResultSet(ResultSet rs) 201 throws PersistenceDatabaseException { 202 LocationNameElementDescriptionValue _value; 203 204 try { 205 Long locned_locationnameelementdescriptionid = rs.getLong(LOCNED_LOCATIONNAMEELEMENTDESCRIPTIONID); 206 LocationNameElementDescriptionPK _pk = new LocationNameElementDescriptionPK(locned_locationnameelementdescriptionid); 207 208 // See if we already have the entity in the session cache 209 LocationNameElementDescription _entity = (LocationNameElementDescription)session.getEntity(_pk); 210 211 if(_entity == null) { 212 Long locned_locne_locationnameelementid = rs.getLong(LOCNED_LOCNE_LOCATIONNAMEELEMENTID); 213 if(rs.wasNull()) 214 locned_locne_locationnameelementid = null; 215 216 Long locned_lang_languageid = rs.getLong(LOCNED_LANG_LANGUAGEID); 217 if(rs.wasNull()) 218 locned_lang_languageid = null; 219 220 String locned_description = rs.getString(LOCNED_DESCRIPTION); 221 if(rs.wasNull()) 222 locned_description = null; 223 224 Long locned_fromtime = rs.getLong(LOCNED_FROMTIME); 225 if(rs.wasNull()) 226 locned_fromtime = null; 227 228 Long locned_thrutime = rs.getLong(LOCNED_THRUTIME); 229 if(rs.wasNull()) 230 locned_thrutime = null; 231 232 _value = new LocationNameElementDescriptionValue(_pk, new LocationNameElementPK(locned_locne_locationnameelementid), new LanguagePK(locned_lang_languageid), locned_description, locned_fromtime, locned_thrutime); 233 } else 234 _value = _entity.getLocationNameElementDescriptionValue(); 235 } catch (SQLException se) { 236 throw new PersistenceDatabaseException(se); 237 } 238 239 return _value; 240 } 241 242 public java.util.List<LocationNameElementDescription> getEntitiesFromPKs(EntityPermission entityPermission, Collection<LocationNameElementDescriptionPK> pks) 243 throws PersistenceDatabaseException { 244 java.util.List<LocationNameElementDescription> _entities = new ArrayList<>(pks.size()); 245 246 for(LocationNameElementDescriptionPK _pk: pks) { 247 _entities.add(getEntityFromPK(entityPermission, _pk)); 248 } 249 250 return _entities; 251 } 252 253 public LocationNameElementDescription getEntityFromValue(EntityPermission entityPermission, LocationNameElementDescriptionValue value) { 254 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 255 } 256 257 public LocationNameElementDescription getEntityFromCache(LocationNameElementDescriptionPK pk) { 258 LocationNameElementDescriptionValue _value = (LocationNameElementDescriptionValue)session.getValueCache().get(pk); 259 260 return _value == null ? null : new LocationNameElementDescription(_value, EntityPermission.READ_ONLY); 261 } 262 263 public LocationNameElementDescription getEntityFromPK(EntityPermission entityPermission, LocationNameElementDescriptionPK pk) 264 throws PersistenceDatabaseException { 265 LocationNameElementDescription _entity; 266 267 // See if we already have the entity in the session cache 268 _entity = (LocationNameElementDescription)session.getEntity(pk); 269 if(_entity != null) { 270 // If the requested permission is READ_WRITE, and the cached permission is 271 // READ_ONLY, then pretend that the cached object wasn't found, and create 272 // a new entity that is READ_WRITE. 273 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 274 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 275 _entity = null; 276 } 277 } 278 279 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 280 _entity = getEntityFromCache(pk); 281 } 282 283 if(_entity == null) { 284 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 285 long _entityId = pk.getEntityId(); 286 ResultSet _rs = null; 287 288 try { 289 _ps.setLong(1, _entityId); 290 _rs = _ps.executeQuery(); 291 if(_rs.next()) { 292 _entity = getEntityFromResultSet(entityPermission, _rs); 293 } 294 } catch (SQLException se) { 295 throw new PersistenceDatabaseException(se); 296 } finally { 297 if(_rs != null) { 298 try { 299 _rs.close(); 300 } catch (SQLException se) { 301 // do nothing 302 } 303 } 304 } 305 } 306 307 return _entity; 308 } 309 310 public Set<LocationNameElementDescriptionPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 311 throws PersistenceDatabaseException { 312 Set<LocationNameElementDescriptionPK> _pks; 313 ResultSet _rs = null; 314 315 try { 316 if(params.length != 0) { 317 Session.setQueryParams(ps, params); 318 } 319 320 _rs = ps.executeQuery(); 321 _pks = getPKsFromResultSetAsSet(_rs); 322 _rs.close(); 323 } catch (SQLException se) { 324 throw new PersistenceDatabaseException(se); 325 } finally { 326 if(_rs != null) { 327 try { 328 _rs.close(); 329 } catch (SQLException se) { 330 // do nothing 331 } 332 } 333 } 334 335 return _pks; 336 } 337 338 public java.util.List<LocationNameElementDescriptionPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 339 throws PersistenceDatabaseException { 340 java.util.List<LocationNameElementDescriptionPK> _pks; 341 ResultSet _rs = null; 342 343 try { 344 if(params.length != 0) { 345 Session.setQueryParams(ps, params); 346 } 347 348 _rs = ps.executeQuery(); 349 _pks = getPKsFromResultSetAsList(_rs); 350 _rs.close(); 351 } catch (SQLException se) { 352 throw new PersistenceDatabaseException(se); 353 } finally { 354 if(_rs != null) { 355 try { 356 _rs.close(); 357 } catch (SQLException se) { 358 // do nothing 359 } 360 } 361 } 362 363 return _pks; 364 } 365 366 public LocationNameElementDescriptionPK getPKFromQuery(PreparedStatement ps, final Object... params) 367 throws PersistenceDatabaseException { 368 LocationNameElementDescriptionPK _pk = null; 369 ResultSet _rs = null; 370 371 try { 372 if(params.length != 0) { 373 Session.setQueryParams(ps, params); 374 } 375 376 _rs = ps.executeQuery(); 377 if(_rs.next()) { 378 _pk = getPKFromResultSet(_rs); 379 } 380 _rs.close(); 381 } catch (SQLException se) { 382 throw new PersistenceDatabaseException(se); 383 } finally { 384 if(_rs != null) { 385 try { 386 _rs.close(); 387 } catch (SQLException se) { 388 // do nothing 389 } 390 } 391 } 392 393 return _pk; 394 } 395 396 public java.util.List<LocationNameElementDescription> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 397 throws PersistenceDatabaseException { 398 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 399 400 return getEntitiesFromQuery(entityPermission, ps, params); 401 } 402 403 public java.util.List<LocationNameElementDescription> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 404 throws PersistenceDatabaseException { 405 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 406 407 return getEntitiesFromQuery(entityPermission, ps); 408 } 409 410 public java.util.List<LocationNameElementDescription> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 411 throws PersistenceDatabaseException { 412 PreparedStatement ps = session.prepareStatement(query.getSQL()); 413 414 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 415 } 416 417 public java.util.List<LocationNameElementDescription> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 418 throws PersistenceDatabaseException { 419 java.util.List<LocationNameElementDescription> _entities; 420 ResultSet _rs = null; 421 422 try { 423 if(params.length != 0) { 424 Session.setQueryParams(ps, params); 425 } 426 427 _rs = ps.executeQuery(); 428 _entities = getEntitiesFromResultSet(entityPermission, _rs); 429 _rs.close(); 430 } catch (SQLException se) { 431 throw new PersistenceDatabaseException(se); 432 } finally { 433 if(_rs != null) { 434 try { 435 _rs.close(); 436 } catch (SQLException se) { 437 // do nothing 438 } 439 } 440 } 441 442 return _entities; 443 } 444 445 public LocationNameElementDescription getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 446 throws PersistenceDatabaseException { 447 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 448 449 return getEntityFromQuery(entityPermission, ps, params); 450 } 451 452 public LocationNameElementDescription getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 453 throws PersistenceDatabaseException { 454 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 455 456 return getEntityFromQuery(entityPermission, ps); 457 } 458 459 public LocationNameElementDescription getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 460 throws PersistenceDatabaseException { 461 PreparedStatement ps = session.prepareStatement(query.getSQL()); 462 463 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 464 } 465 466 public LocationNameElementDescription getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 467 throws PersistenceDatabaseException { 468 LocationNameElementDescription _entity = null; 469 ResultSet _rs = null; 470 471 try { 472 if(params.length != 0) { 473 Session.setQueryParams(ps, params); 474 } 475 476 _rs = ps.executeQuery(); 477 if(_rs.next()) { 478 _entity = getEntityFromResultSet(entityPermission, _rs); 479 } 480 _rs.close(); 481 } catch (SQLException se) { 482 throw new PersistenceDatabaseException(se); 483 } finally { 484 if(_rs != null) { 485 try { 486 _rs.close(); 487 } catch (SQLException se) { 488 // do nothing 489 } 490 } 491 } 492 493 return _entity; 494 } 495 496 public java.util.List<LocationNameElementDescription> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 497 throws PersistenceDatabaseException { 498 java.util.List<LocationNameElementDescription> _result = new ArrayList<>(); 499 500 try { 501 while(rs.next()) { 502 _result.add(getEntityFromResultSet(entityPermission, rs)); 503 } 504 } catch (SQLException se) { 505 throw new PersistenceDatabaseException(se); 506 } 507 508 return _result; 509 } 510 511 public LocationNameElementDescription getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 512 throws PersistenceDatabaseException { 513 LocationNameElementDescription _entity; 514 515 try { 516 Long locned_locationnameelementdescriptionid = rs.getLong(LOCNED_LOCATIONNAMEELEMENTDESCRIPTIONID); 517 LocationNameElementDescriptionPK _pk = new LocationNameElementDescriptionPK(locned_locationnameelementdescriptionid); 518 519 // See if we already have the entity in the session cache 520 _entity = (LocationNameElementDescription)session.getEntity(_pk); 521 if(_entity != null) { 522 // If the requested permission is READ_WRITE, and the cached permission is 523 // READ_ONLY, then pretend that the cached object wasn't found, and create 524 // a new entity that is READ_WRITE. 525 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 526 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 527 _entity = null; 528 } 529 } 530 boolean foundInSessionCache = _entity != null; 531 532 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 533 _entity = getEntityFromCache(_pk); 534 } 535 536 if(_entity == null) { 537 Long locned_locne_locationnameelementid = rs.getLong(LOCNED_LOCNE_LOCATIONNAMEELEMENTID); 538 if(rs.wasNull()) 539 locned_locne_locationnameelementid = null; 540 541 Long locned_lang_languageid = rs.getLong(LOCNED_LANG_LANGUAGEID); 542 if(rs.wasNull()) 543 locned_lang_languageid = null; 544 545 String locned_description = rs.getString(LOCNED_DESCRIPTION); 546 if(rs.wasNull()) 547 locned_description = null; 548 549 Long locned_fromtime = rs.getLong(LOCNED_FROMTIME); 550 if(rs.wasNull()) 551 locned_fromtime = null; 552 553 Long locned_thrutime = rs.getLong(LOCNED_THRUTIME); 554 if(rs.wasNull()) 555 locned_thrutime = null; 556 557 LocationNameElementDescriptionValue _value = new LocationNameElementDescriptionValue(_pk, locned_locne_locationnameelementid == null? null: new LocationNameElementPK(locned_locne_locationnameelementid), locned_lang_languageid == null? null: new LanguagePK(locned_lang_languageid), locned_description, locned_fromtime, locned_thrutime); 558 _entity = new LocationNameElementDescription(_value, entityPermission); 559 } 560 561 if(!foundInSessionCache) { 562 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 563 session.putReadOnlyEntity(_pk, _entity); 564 session.getValueCache().put(_entity.getLocationNameElementDescriptionValue()); 565 } else { 566 session.putReadWriteEntity(_pk, _entity); 567 } 568 } 569 } catch (SQLException se) { 570 throw new PersistenceDatabaseException(se); 571 } 572 573 return _entity; 574 } 575 576 public LocationNameElementDescription create(LocationNameElement locationNameElement, Language language, String description, Long fromTime, Long thruTime) 577 throws PersistenceDatabaseException, PersistenceNotNullException { 578 return create(locationNameElement == null ? null : locationNameElement.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, fromTime, thruTime); 579 } 580 581 private void bindForCreate(PreparedStatement _ps, LocationNameElementDescriptionValue _value) 582 throws SQLException { 583 _ps.setLong(1, _value.getEntityId()); 584 585 LocationNameElementPK locned_locne_locationnameelementid = _value.getLocationNameElementPK(); 586 if(locned_locne_locationnameelementid == null) 587 _ps.setNull(2, Types.BIGINT); 588 else 589 _ps.setLong(2, locned_locne_locationnameelementid.getEntityId()); 590 591 LanguagePK locned_lang_languageid = _value.getLanguagePK(); 592 if(locned_lang_languageid == null) 593 _ps.setNull(3, Types.BIGINT); 594 else 595 _ps.setLong(3, locned_lang_languageid.getEntityId()); 596 597 String locned_description = _value.getDescription(); 598 if(locned_description == null) 599 _ps.setNull(4, Types.VARCHAR); 600 else 601 _ps.setString(4, locned_description); 602 603 Long locned_fromtime = _value.getFromTime(); 604 if(locned_fromtime == null) 605 _ps.setNull(5, Types.BIGINT); 606 else 607 _ps.setLong(5, locned_fromtime); 608 609 Long locned_thrutime = _value.getThruTime(); 610 if(locned_thrutime == null) 611 _ps.setNull(6, Types.BIGINT); 612 else 613 _ps.setLong(6, locned_thrutime); 614 615 } 616 617 public LocationNameElementDescription create(LocationNameElementPK locationNameElementPK, LanguagePK languagePK, String description, Long fromTime, Long thruTime) 618 throws PersistenceDatabaseException, PersistenceNotNullException { 619 LocationNameElementDescriptionPK _pk = getNextPK(); 620 LocationNameElementDescriptionValue _value = new LocationNameElementDescriptionValue(_pk, locationNameElementPK, languagePK, description, fromTime, thruTime); 621 622 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 623 624 try { 625 bindForCreate(_ps, _value); 626 627 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 628 int _count = _ps.executeUpdate(); 629 630 if(_count != 1) { 631 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 632 } 633 } else { 634 _ps.executeUpdate(); 635 } 636 637 session.getValueCache().put(_value); 638 } catch (SQLException se) { 639 throw new PersistenceDatabaseException(se); 640 } 641 642 LocationNameElementDescription _entity = new LocationNameElementDescription(_value, EntityPermission.READ_ONLY); 643 session.putReadOnlyEntity(_pk, _entity); 644 645 return _entity; 646 } 647 648 public void create(Collection<LocationNameElementDescriptionValue> _values) 649 throws PersistenceDatabaseException, PersistenceNotNullException { 650 int _size = _values.size(); 651 652 if(_size > 0) { 653 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 654 List<LocationNameElementDescriptionValue> _cacheValues = new ArrayList<>(_size); 655 656 try { 657 for(LocationNameElementDescriptionValue _value : _values) { 658 _value.setEntityId(entityIdGenerator.getNextEntityId()); 659 bindForCreate(_ps, _value); 660 661 _ps.addBatch(); 662 663 _cacheValues.add(_value); 664 } 665 666 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 667 int[] _counts = _ps.executeBatch(); 668 669 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 670 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 671 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 672 } 673 } 674 } else { 675 _ps.executeBatch(); 676 } 677 678 _ps.clearBatch(); 679 } catch (SQLException se) { 680 throw new PersistenceDatabaseException(se); 681 } 682 683 _cacheValues.forEach((_cacheValue) -> { 684 LocationNameElementDescription _cacheEntity = new LocationNameElementDescription(_cacheValue, EntityPermission.READ_ONLY); 685 686 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 687 }); 688 } 689 } 690 691 private boolean bindForStore(PreparedStatement _ps, LocationNameElementDescriptionValue _value) 692 throws SQLException { 693 boolean _hasBeenModified = _value.hasBeenModified(); 694 695 if(_hasBeenModified) { 696 LocationNameElementPK locned_locne_locationnameelementid = _value.getLocationNameElementPK(); 697 if(locned_locne_locationnameelementid == null) 698 _ps.setNull(1, Types.BIGINT); 699 else 700 _ps.setLong(1, locned_locne_locationnameelementid.getEntityId()); 701 702 LanguagePK locned_lang_languageid = _value.getLanguagePK(); 703 if(locned_lang_languageid == null) 704 _ps.setNull(2, Types.BIGINT); 705 else 706 _ps.setLong(2, locned_lang_languageid.getEntityId()); 707 708 String locned_description = _value.getDescription(); 709 if(locned_description == null) 710 _ps.setNull(3, Types.VARCHAR); 711 else 712 _ps.setString(3, locned_description); 713 714 Long locned_fromtime = _value.getFromTime(); 715 if(locned_fromtime == null) 716 _ps.setNull(4, Types.BIGINT); 717 else 718 _ps.setLong(4, locned_fromtime); 719 720 Long locned_thrutime = _value.getThruTime(); 721 if(locned_thrutime == null) 722 _ps.setNull(5, Types.BIGINT); 723 else 724 _ps.setLong(5, locned_thrutime); 725 726 _ps.setLong(6, _value.getPrimaryKey().getEntityId()); 727 728 _value.clearHasBeenModified(); 729 } 730 731 return _hasBeenModified; 732 } 733 734 @Override 735 public void store(LocationNameElementDescription entity) 736 throws PersistenceDatabaseException { 737 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 738 739 try { 740 LocationNameElementDescriptionValue _value = entity.getLocationNameElementDescriptionValue(); 741 742 if(bindForStore(_ps, _value)) { 743 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 744 int _count = _ps.executeUpdate(); 745 746 if(_count != 1) { 747 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 748 } 749 } else { 750 _ps.executeUpdate(); 751 } 752 753 session.getValueCache().put(_value); 754 } 755 } catch (SQLException se) { 756 throw new PersistenceDatabaseException(se); 757 } 758 } 759 760 @Override 761 public void store(Collection<LocationNameElementDescription> entities) 762 throws PersistenceDatabaseException { 763 if(entities.size() > 0) { 764 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 765 int _modifiedEntities = 0; 766 767 try { 768 for(LocationNameElementDescription entity : entities) { 769 if(bindForStore(_ps, entity.getLocationNameElementDescriptionValue())) { 770 _ps.addBatch(); 771 _modifiedEntities++; 772 } 773 } 774 775 if(_modifiedEntities != 0) { 776 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 777 int[] _counts = _ps.executeBatch(); 778 779 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 780 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 781 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 782 } 783 } 784 } else { 785 _ps.executeBatch(); 786 } 787 788 _ps.clearBatch(); 789 790 entities.forEach((entity) -> { 791 session.getValueCache().put(entity.getLocationNameElementDescriptionValue()); 792 }); 793 } 794 } catch (SQLException se) { 795 throw new PersistenceDatabaseException(se); 796 } 797 } 798 } 799 800 @Override 801 public void remove(LocationNameElementDescription entity) 802 throws PersistenceDatabaseException { 803 remove(entity.getPrimaryKey()); 804 } 805 806 @Override 807 public void remove(LocationNameElementDescriptionPK pk) 808 throws PersistenceDatabaseException { 809 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 810 long _entityId = pk.getEntityId(); 811 812 try { 813 _ps.setLong(1, _entityId); 814 815 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 816 int _count = _ps.executeUpdate(); 817 818 if(_count != 1) { 819 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 820 } 821 } else { 822 _ps.executeUpdate(); 823 } 824 825 session.getValueCache().remove(pk); 826 } catch (SQLException se) { 827 throw new PersistenceDatabaseException(se); 828 } 829 830 session.removed(pk, false); 831 } 832 833 @Override 834 public void remove(Collection<LocationNameElementDescriptionPK> pks) 835 throws PersistenceDatabaseException { 836 if(pks.size() > 0) { 837 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 838 int _modifiedEntities = 0; 839 840 try { 841 for(LocationNameElementDescriptionPK pk : pks) { 842 long _entityId = pk.getEntityId(); 843 844 _ps.setLong(1, _entityId); 845 846 _ps.addBatch(); 847 _modifiedEntities++; 848 } 849 850 if(_modifiedEntities != 0) { 851 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 852 int[] _counts = _ps.executeBatch(); 853 854 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 855 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 856 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 857 } 858 } 859 } else { 860 _ps.executeBatch(); 861 } 862 863 _ps.clearBatch(); 864 865 pks.forEach((pk) -> { 866 session.getValueCache().remove(pk); 867 }); 868 } 869 } catch (SQLException se) { 870 throw new PersistenceDatabaseException(se); 871 } 872 873 pks.forEach((pk) -> { 874 session.removed(pk, true); 875 }); 876 } 877 } 878 879 @Override 880 public boolean validPK(LocationNameElementDescriptionPK pk) 881 throws PersistenceDatabaseException { 882 boolean valid = false; 883 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 884 ResultSet _rs = null; 885 886 try { 887 _ps.setLong(1, pk.getEntityId()); 888 889 _rs = _ps.executeQuery(); 890 if(_rs.next()) { 891 long _count = _rs.getLong(1); 892 if(_rs.wasNull()) 893 _count = 0; 894 895 if(_count == 1) 896 valid = true; 897 } 898 } catch (SQLException se) { 899 throw new PersistenceDatabaseException(se); 900 } finally { 901 if(_rs != null) { 902 try { 903 _rs.close(); 904 } catch (SQLException se) { 905 // do nothing 906 } 907 } 908 } 909 910 return valid; 911 } 912 913}