/** * Add an entry to clear a query cache. */ public void addInvalidate(BeanDescriptor<?> descriptor) { touchedTables.add(descriptor.getBaseTable()); }
/** * Delete by Id. */ @Override public int delete(Class<?> beanType, Object id, Transaction transaction, boolean permanent) { BeanDescriptor<?> descriptor = beanDescriptorManager.getBeanDescriptor(beanType); if (descriptor.isMultiTenant()) { // convert to a delete by bean EntityBean bean = descriptor.createEntityBean(); descriptor.convertSetId(id, bean); return delete(bean, transaction, permanent); } id = descriptor.convertId(id); DeleteMode deleteMode = (permanent || !descriptor.isSoftDelete()) ? DeleteMode.HARD : DeleteMode.SOFT; return delete(descriptor, id, null, transaction, deleteMode); }
private void registerBeanDescriptor(DeployBeanInfo<?> info) { BeanDescriptor desc = new BeanDescriptor<>(this, info.getDescriptor()); descMap.put(desc.getBeanType().getName(), desc); if (desc.isDocStoreMapped()) { descQueueMap.put(desc.getDocStoreQueueId(), desc); } }
@Override public void registerColumn(BeanDescriptor<?> desc, String prefix) { if (targetDescriptor != null) { desc.registerTable(targetDescriptor.getBaseTable(), this); } } /**
/** * Return the table to update depending if the request is a 'publish' one or normal. */ public String getUpdateTable() { return publish ? beanDescriptor.getBaseTable() : beanDescriptor.getDraftTable(); }
@Override public String getDeployWord(String expression) { if (expression.equalsIgnoreCase(beanDescriptor.getName())) { return beanDescriptor.getBaseTable(); } ElPropertyDeploy elProp = beanDescriptor.getElPropertyDeploy(expression); if (elProp != null) { return elProp.getDbColumn(); } else { return null; } }
/** * Load the entity bean from cache data given this is the root bean type. */ EntityBean loadBeanDirect(Object id, Boolean readOnly, CachedBeanData data, PersistenceContext context) { if (context == null) { context = new DefaultPersistenceContext(); } EntityBean bean = desc.createEntityBean(); id = desc.convertSetId(id, bean); CachedBeanDataToBean.load(desc, bean, data, context); EntityBeanIntercept ebi = bean._ebean_getIntercept(); // Not using a loadContext for beans coming out of L2 cache // so that means no batch lazy loading for these beans ebi.setBeanLoader(desc.getEbeanServer()); if (Boolean.TRUE.equals(readOnly)) { ebi.setReadOnly(true); } ebi.setPersistenceContext(context); desc.contextPut(context, id, bean); if (desc.isReadAuditing()) { desc.readAuditBean("l2", "", bean); } return bean; }
CachedBeanData d = cacheHelp.beanCacheGetData(cacheKey(id)); if (d != null) { Object shareableBean = d.getSharableBean(); if (shareableBean != null) { if (isReadAuditing()) { readAuditBean("ref", "", shareableBean); return findReferenceBean(id, pc); EntityBean eb = createEntityBean(); id = convertSetId(id, eb); contextPut(pc, id, eb); ebi.setPersistenceContext(pc);
public ModelBuildPropertyVisitor visitBean(BeanDescriptor<?> descriptor) { if (!descriptor.isInheritanceRoot()) { return null; MTable table = new MTable(descriptor.getBaseTable()); table.setPartitionMeta(descriptor.getPartitionMeta()); table.setComment(descriptor.getDbComment()); if (descriptor.isHistorySupport()) { table.setWithHistory(true); BeanProperty whenCreated = descriptor.getWhenCreatedProperty(); if (whenCreated != null) { table.setWhenCreatedColumn(whenCreated.getDbColumn()); InheritInfo inheritInfo = descriptor.getInheritInfo(); if (inheritInfo != null && inheritInfo.isRoot()) {
if (EntityType.EMBEDDED == desc.getEntityType()) { Object id = desc.getId(bean); desc.contextPut(pc, id, bean); ebi.setPersistenceContext(pc); boolean draft = desc.isDraftInstance(bean); if (desc.lazyLoadMany(ebi)) { return; if (!draft && Mode.LAZYLOAD_BEAN == mode && desc.isBeanCaching()) { if (desc.cacheBeanLoad(bean, ebi, id, pc)) { return; SpiQuery<?> query = server.createQuery(desc.getBeanType()); query.setLazyLoadProperty(ebi.getLazyLoadProperty()); if (draft) { String msg = "Bean not found during lazy load or refresh." + " id[" + id + "] type[" + desc.getBeanType() + "]"; throw new EntityNotFoundException(msg); desc.resetManyProperties(dbBean);
id = desc.convertId(id); if (t != null) { pc = t.getPersistenceContext(); Object existing = desc.contextGet(pc, id); if (existing != null) { return (T) existing; InheritInfo inheritInfo = desc.getInheritInfo(); if (inheritInfo == null || inheritInfo.isConcrete()) { return (T) desc.contextRef(pc, null, false, id); BeanProperty idProp = desc.getIdProperty(); if (idProp == null) { throw new PersistenceException("No ID properties for this type? " + desc);
BeanPropertyAssocMany<?> many = (BeanPropertyAssocMany<?>) parentDesc.getBeanProperty(propertyName); Object parentId = parentDesc.getId(parentBean); parentDesc.contextPut(pc, parentId, parentBean); boolean useManyIdCache = beanCollection != null && parentDesc.isManyPropCaching(); if (useManyIdCache) { Boolean readOnly = null; readOnly = Boolean.TRUE; if (parentDesc.cacheManyPropLoad(many, beanCollection, parentId, readOnly)) { return; SpiQuery<?> query = server.createQuery(parentDesc.getBeanType()); String idProperty = parentDesc.getIdBinder().getIdProperty(); query.select(idProperty); parentDesc.cacheManyPropPut(many, beanCollection, parentId);
@Override public void registerColumn(BeanDescriptor<?> desc, String prefix) { if (embedded) { for (BeanProperty prop : embeddedProps) { prop.registerColumn(desc, SplitName.add(prefix, name)); } } else { if (targetIdProperty != null) { BeanDescriptor<T> target = getTargetDescriptor(); String basePath = SplitName.add(prefix, name); if (dbColumn != null) { BeanProperty idProperty = target.getIdProperty(); desc.registerColumn(dbColumn, SplitName.add(basePath, idProperty.getName())); } desc.registerTable(target.getBaseTable(), this); } } }
/** * Set Id Generated value for insert. */ private void setIdGenValue(PersistRequestBean<?> request) { BeanDescriptor<?> desc = request.getBeanDescriptor(); if (!desc.isUseIdGenerator()) { return; } BeanProperty idProp = desc.getIdProperty(); if (idProp == null || idProp.isEmbedded()) { // not supporting IdGeneration for concatenated or Embedded return; } EntityBean bean = request.getEntityBean(); Object uid = idProp.getValue(bean); if (DmlUtil.isNullOrZero(uid)) { // generate the nextId and set it to the property Object nextId = desc.nextId(request.getTransaction()); // cast the data type if required and set it desc.convertSetId(nextId, bean); } }
/** * Build a map of table names to BeanDescriptors. * <p> * This is generally used to maintain caches from table names. * </p> */ private void readTableToDescriptor() { for (BeanDescriptor<?> desc : descMap.values()) { String baseTable = desc.getBaseTable(); if (baseTable != null) { baseTable = baseTable.toLowerCase(); List<BeanDescriptor<?>> list = tableToDescMap.computeIfAbsent(baseTable, k -> new ArrayList<>(1)); list.add(desc); } if (desc.getEntityType() == EntityType.VIEW && desc.isQueryCaching()) { // build map of tables to view entities dependent on those tables // for the purpose of invalidating appropriate query caches String[] dependentTables = desc.getDependentTables(); if (dependentTables != null && dependentTables.length > 0) { for (String depTable : dependentTables) { depTable = depTable.toLowerCase(); List<BeanDescriptor<?>> list = tableToViewDescMap.computeIfAbsent(depTable, k -> new ArrayList<>(1)); list.add(desc); } } } } }
this.shadowFKey = shadowFKey; String tableName = desc.getBaseTable(); String draftTableName = desc.getDraftTable(); this.sqlDraftWithId = desc.isDraftable() ? genSql(false, draftTableName, true) : sqlWithId; this.identityDbColumns = new String[]{id.getIdentityColumn()}; this.supportsGetGeneratedKeys = dbPlatform.getDbIdentity().isSupportsGetGeneratedKeys(); this.supportsSelectLastInsertedId = desc.supportsSelectLastInsertedId(); this.sqlDraftNullId = desc.isDraftable() ? genSql(true, draftTableName, true) : sqlNullId;
private void initialiseAssocOne(String embeddedPrefix) { localHelp = createHelp(embedded, oneToOneExported, embeddedPrefix); if (!isTransient) { //noinspection StatementWithEmptyBody if (embedded || descriptor.isDocStoreOnly()) { // no imported or exported information } else if (!oneToOneExported) { importedId = createImportedId(this, targetDescriptor, tableJoin); if (importedId.isScalar()) { // limit JoinColumn mapping to the @Id / primary key TableJoinColumn[] columns = tableJoin.columns(); String foreignJoinColumn = columns[0].getForeignDbColumn(); String foreignIdColumn = targetDescriptor.getIdProperty().getDbColumn(); if (!foreignJoinColumn.equalsIgnoreCase(foreignIdColumn)) { throw new PersistenceException("Mapping limitation - @JoinColumn on " + getFullBeanName() + " needs to map to a primary key as per Issue #529 " + " - joining to " + foreignJoinColumn + " and not " + foreignIdColumn); } } } else { exportedProperties = createExported(); String delStmt = "delete from " + targetDescriptor.getBaseTable() + " where "; deleteByParentIdSql = delStmt + deriveWhereParentIdSql(false); deleteByParentIdInSql = delStmt + deriveWhereParentIdSql(true); } } }
DeleteMeta(boolean emptyStringAsNull, BeanDescriptor<?> desc, BindableId id, Bindable version, Bindable tenantId) { this.emptyStringAsNull = emptyStringAsNull; this.tableName = desc.getBaseTable(); this.id = id; this.version = version; this.tenantId = tenantId; String tableName = desc.getBaseTable(); this.sqlNone = genSql(ConcurrencyMode.NONE, tableName); this.sqlVersion = genSql(ConcurrencyMode.VERSION, tableName); if (desc.isDraftable()) { String draftTableName = desc.getDraftTable(); this.sqlDraftNone = genSql(ConcurrencyMode.NONE, draftTableName); this.sqlDraftVersion = genSql(ConcurrencyMode.VERSION, draftTableName); } else { this.sqlDraftNone = sqlNone; this.sqlDraftVersion = sqlVersion; } }
/** * Create a non read only reference bean without checking cacheSharableBeans. */ @SuppressWarnings("unchecked") public T createReference(Object id, PersistenceContext pc) { try { if (inheritInfo != null && !inheritInfo.isConcrete()) { return findReferenceBean(id, pc); } EntityBean eb = createEntityBean(); id = convertSetId(id, eb); EntityBeanIntercept ebi = eb._ebean_getIntercept(); ebi.setBeanLoader(ebeanServer); ebi.setReference(idPropertyIndex); if (pc != null) { contextPut(pc, id, eb); ebi.setPersistenceContext(pc); } return (T) eb; } catch (Exception ex) { throw new PersistenceException(ex); } }
@Override public String getAssocIsEmpty(SpiExpressionRequest request, String path) { boolean softDelete = targetDescriptor.isSoftDelete(); sb.append(query.isAsDraft() ? intersectionDraftTable : intersectionPublishTable); } else { sb.append(targetDescriptor.getBaseTable(query.getTemporalMode())); sb.append(targetDescriptor.getBaseTable(query.getTemporalMode())); sb.append(" x2 on "); inverseJoin.addJoin("x2", "x", sb); sb.append(" and ").append(targetDescriptor.getSoftDeletePredicate(alias));