@Override public Class<? extends T> getInheritType() { return beanDescriptor.getBeanType(); }
@Override public Class<?> getBeanType() { return loadBuffer.getBeanDescriptor().getBeanType(); }
@Override public Class<?> getBeanType() { return loadContext.getBeanDescriptor().getBeanType(); }
private void checkForValidEmbeddedId(BeanDescriptor<?> d) { IdBinder idBinder = d.getIdBinder(); if (idBinder instanceof IdBinderEmbedded) { IdBinderEmbedded embId = (IdBinderEmbedded) idBinder; BeanDescriptor<?> idBeanDescriptor = embId.getIdBeanDescriptor(); Class<?> idType = idBeanDescriptor.getBeanType(); try { idType.getDeclaredMethod("hashCode"); idType.getDeclaredMethod("equals", Object.class); } catch (NoSuchMethodException e) { checkMissingHashCodeOrEquals(e, idType, d.getBeanType()); } } }
private boolean isUpdate(Object beanId, Object outlineId, MergeRequest request) { return Objects.equals(beanId, outlineId) || !request.isClientGeneratedIds() || request.idExists(targetDescriptor.getBeanType(), beanId); }
public void collectQueryPlans(QueryPlanRequest request) { for (BeanDescriptor<?> desc : immutableDescriptorList) { if (request.includeType(desc.getBeanType())) { desc.collectQueryPlans(request); } } }
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); } }
/** * Return the child property that links back to the master bean. * <p> * Note that childMasterProperty will be null if a field is used instead of * a ManyToOne bean association. * </p> */ private BeanPropertyAssocOne<?> initChildMasterProperty() { if (unidirectional) { return null; } // search for the property, to see if it exists Class<?> beanType = descriptor.getBeanType(); BeanDescriptor<?> targetDesc = getTargetDescriptor(); for (BeanPropertyAssocOne<?> prop : targetDesc.propertiesOne()) { if (mappedBy != null) { // match using mappedBy as property name if (mappedBy.equalsIgnoreCase(prop.getName())) { return prop; } } else { // assume only one property that matches parent object type if (prop.getTargetType().equals(beanType)) { // found it, stop search return prop; } } } throw new RuntimeException("Can not find Master [" + beanType + "] in Child[" + targetDesc + "]"); }
/** * We need to create and execute a query to get the foreign key values as * the delete cascades to them (foreign keys). */ private Query<?> deleteRequiresQuery(BeanDescriptor<?> desc, BeanPropertyAssocOne<?>[] propImportDelete, DeleteMode deleteMode) { Query<?> q = server.createQuery(desc.getBeanType()); StringBuilder sb = new StringBuilder(30); for (BeanPropertyAssocOne<?> aPropImportDelete : propImportDelete) { sb.append(aPropImportDelete.getName()).append(","); } q.setAutoTune(false); q.select(sb.toString()); if (deleteMode.isHard() && desc.isSoftDelete()) { // hard delete so we want this query to include logically deleted rows (if any) q.setIncludeSoftDeletes(); } return q; }
public DefaultOrmQuery(BeanDescriptor<T> desc, SpiEbeanServer server, ExpressionFactory expressionFactory) { this.beanDescriptor = desc; this.rootBeanDescriptor = desc; this.beanType = desc.getBeanType(); this.server = server; this.orderById = server.getServerConfig().isDefaultOrderById(); this.disableLazyLoading = server.getServerConfig().isDisableLazyLoading(); this.expressionFactory = expressionFactory; this.detail = new OrmQueryDetail(); }
@Override public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException { PersistRequestBean<?> persistRequest = request.getPersistRequest(); Object parentBean = persistRequest.getParentBean(); if (parentBean == null) { Class<?> localType = desc.getBeanType(); Class<?> targetType = unidirectional.getTargetType(); String msg = "Error inserting bean [" + localType + "] with unidirectional relationship. "; msg += "For inserts you must use cascade save on the master bean [" + targetType + "]."; throw new PersistenceException(msg); } importedId.bind(request, (EntityBean) parentBean); }
/** * Fetch the destination beans that will be published to. */ void fetchDestinationBeans(List<T> sourceBeans, boolean asDraft) { List<Object> ids = getBeanIds(desc, sourceBeans); Query<T> destQuery = server.find(desc.getBeanType()).where().idIn(ids).query(); if (asDraft) { destQuery.asDraft(); } desc.draftQueryOptimise(destQuery); this.destBeans = server.findMap(destQuery, transaction); }
/** * Execute a query fetching the missing (unloaded) foreign keys. We need to * fetch these key values before the parent bean is deleted. */ void queryForeignKeys() { BeanDescriptor<?> descriptor = request.getBeanDescriptor(); SpiQuery<?> q = (SpiQuery<?>) server.createQuery(descriptor.getBeanType()); Object id = request.getBeanId(); StringBuilder sb = new StringBuilder(30); for (BeanPropertyAssocOne<?> aPropList : propList) { sb.append(aPropList.getName()).append(","); } // run query in a separate persistence context q.setPersistenceContext(new DefaultPersistenceContext()); q.setPersistenceContextScope(PersistenceContextScope.QUERY); q.setAutoTune(false); q.select(sb.toString()); q.setIncludeSoftDeletes(); q.where().idEq(id); SpiTransaction t = request.getTransaction(); if (t.isLogSummary()) { t.logSummary("-- Ebean fetching foreign key values for delete of " + descriptor.getName() + " id:" + id); } beanWithForeignKeys = (EntityBean) server.findOne(q, t); }
/** * Fetch the outline bean with associated one and associated many beans loaded with Id values only. * <p> * We use the Id values to determine what are inserts, updates and deletes as part of the merge. */ private EntityBean fetchOutline(Set<String> paths) { Query<?> query = server.find(desc.getBeanType()); query.setBeanCacheMode(CacheMode.OFF); query.setPersistenceContextScope(PersistenceContextScope.QUERY); query.setId(desc.getId(bean)); query.select(desc.getIdProperty().getName()); for (String path : paths) { MergeNode node = buildNode(path); node.addSelectId(query); } return (EntityBean) server.findOne(query, transaction); }
/** * Create a query plan for a raw sql query. */ CQueryPlan(OrmQueryRequest<?> request, String sql, SqlTree sqlTree, boolean rawSql, boolean rowNumberIncluded, String logWhereSql) { this.server = request.getServer(); this.dataTimeZone = server.getDataTimeZone(); this.beanType = request.getBeanDescriptor().getBeanType(); SpiQuery<?> query = request.getQuery(); this.profileLocation = query.getProfileLocation(); this.label = query.getLabel(); this.location = location(); this.planKey = buildPlanKey(sql, rawSql, rowNumberIncluded, logWhereSql); this.autoTuned = false; this.asOfTableCount = 0; this.sql = sql; this.sqlTree = sqlTree; this.rawSql = rawSql; this.rowNumberIncluded = rowNumberIncluded; this.logWhereSql = logWhereSql; this.encryptedProps = sqlTree.getEncryptedProps(); this.stats = new CQueryPlanStats(this, server.isCollectQueryOrigins()); this.dependentTables = (rawSql) ? Collections.emptySet() : sqlTree.dependentTables(); this.bindCapture = initBindCapture(server.getServerConfig(), query); }
/** * Create a query plan based on a OrmQueryRequest. */ CQueryPlan(OrmQueryRequest<?> request, SqlLimitResponse sqlRes, SqlTree sqlTree, boolean rawSql, String logWhereSql) { this.server = request.getServer(); this.dataTimeZone = server.getDataTimeZone(); this.beanType = request.getBeanDescriptor().getBeanType(); this.planKey = request.getQueryPlanKey(); SpiQuery<?> query = request.getQuery(); this.profileLocation = query.getProfileLocation(); this.label = query.getLabel(); this.location = location(); this.autoTuned = query.isAutoTuned(); this.asOfTableCount = query.getAsOfTableCount(); this.sql = sqlRes.getSql(); this.rowNumberIncluded = sqlRes.isIncludesRowNumberColumn(); this.sqlTree = sqlTree; this.rawSql = rawSql; this.logWhereSql = logWhereSql; this.encryptedProps = sqlTree.getEncryptedProps(); this.stats = new CQueryPlanStats(this, server.isCollectQueryOrigins()); this.dependentTables = sqlTree.dependentTables(); this.bindCapture = initBindCapture(server.getServerConfig(), query); }
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);
public void collectQueryPlans(QueryPlanRequest request) { for (BeanDescriptor<?> desc : immutableDescriptorList) { if (request.includeType(desc.getBeanType())) { desc.collectQueryPlans(request); } } }
SpiQuery<?> query = server.createQuery(parentDesc.getBeanType());
this.local = owningType.equals(descriptor.getBeanType());