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