where主键条件

@param entityClass
@param entityName
@param useVersion
@return
554280
public static String wherePKColumns(Class<?> entityClass, String entityName, boolean useVersion) {
        StringBuilder sql = new StringBuilder();
        boolean hasLogicDelete = hasLogicDeleteColumn(entityClass);

        sql.append("<where>");
        //获取全部列
        Set<EntityColumn> columnSet = EntityHelper.getPKColumns(entityClass);
        //当某个列有主键策略时，不需要考虑他的属性是否为空，因为如果为空，一定会根据主键策略给他生成一个值
        for (EntityColumn column : columnSet) {
            sql.append(" AND ").append(column.getColumnEqualsHolder(entityName));
        }
        if (useVersion) {
            sql.append(whereVersion(entityClass));
        }

        if (hasLogicDelete) {
            sql.append(whereLogicDelete(entityClass, false));
        }

        sql.append("</where>");
        return sql.toString();
    }
884935
@ManyToOne(targetEntity = org.openprovenance.prov.sql.QualifiedName.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "USED_ENTITY")
    public org.openprovenance.prov.model.QualifiedName getUsedEntity() {
        return usedEntity;
    }
107872
public static String exampleSelectColumns(Class<?> entityClass) {
        StringBuilder sql = new StringBuilder();
        sql.append("<choose>");
        sql.append("<when test=\"@tk.mybatis.mapper.util.OGNL@hasSelectColumns(_parameter)\">");
        sql.append("<foreach collection=\"_parameter.selectColumns\" item=\"selectColumn\" separator=\",\">");
        sql.append("${selectColumn}");
        sql.append("</foreach>");
        sql.append("</when>");
        //不支持指定列的时候查询全部列
        sql.append("<otherwise>");
        sql.append(getAllColumns(entityClass));
        sql.append("</otherwise>");
        sql.append("</choose>");
        return sql.toString();
    }
1263708
public static String updateTable(Class<?> entityClass, String defaultTableName) {
        return updateTable(entityClass, defaultTableName, null);
    }
663387
@Override
    public <T> T find(Class<T> entityClass, Object primaryKey)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "em.find(" + entityClass + ',' + primaryKey + ");\n" + toString());

        return getEMInvocationInfo(false).find(entityClass, primaryKey);
    }
1217711
@Override
  @SuppressWarnings("unchecked")
  public <E extends Entity> E getEntity(String attributeName, Class<E> clazz) {
    Entity entity = delegate().getEntity(attributeName, clazz);
    if (clazz.equals(FileMeta.class)) {
      return entity != null ? (E) new FileMeta(newPretendingEntity(entity)) : null;
    } else {
      throw new UnsupportedOperationException("Can't return typed pretending entities");
    }
  }
79481
private static Class<?> getIdClass(Class<?> entityClass) {
        Type[] genTypes = entityClass.getGenericInterfaces();

        for (int i = 0; i < genTypes.length; i++) {
            Type genType = genTypes[i];
            String s1 = genType.getClass().getName();
            String s2 = BaseEntity.class.getName();
            if (s1.startsWith(s2)) {
                Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
                // ID真实的class
                Class<?> mapperClass = (Class<?>) params[0];
                return mapperClass;
            }
        }

        return null;
    }
1189102
@SuppressWarnings("unchecked")
    @Override
    public Set<JsonEntityBean> search(String entityType, String searchTerm) {

        Set<JsonEntityBean> results = new HashSet<>();

        EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
        if (entityEnum == null) {
            throw new IllegalArgumentException(
                    String.format("Parameter entityType has an unknown value of [%s]", entityType));
        }

        EntityIdentifier[] identifiers;

        Class identifierType;

        // if the entity type is a group, use the group service's findGroup method
        // to locate it
        if (entityEnum.isGroup()) {
            identifiers =
                    GroupService.searchForGroups(
                            searchTerm,
                            GroupService.SearchMethod.CONTAINS_CI,
                            entityEnum.getClazz());
            identifierType = IEntityGroup.class;
        }

        // otherwise use the getGroupMember method
        else {
            identifiers =
                    GroupService.searchForEntities(
                            searchTerm,
                            GroupService.SearchMethod.CONTAINS_CI,
                            entityEnum.getClazz());
            identifierType = entityEnum.getClazz();
        }

        for (int i = 0; i < identifiers.length; i++) {
            if (identifiers[i].getType().equals(identifierType)) {
                IGroupMember entity = GroupService.getGroupMember(identifiers[i]);
                if (entity != null) {
                    JsonEntityBean jsonBean = getEntity(entity);
                    results.add(jsonBean);
                } else {
                    log.warn("Grouper member entity of " + identifiers[i].getKey() + " is null.");
                }
            }
        }

        return results;
    }
457617
def _get_entity_by_name(self, entity_name):
        """"""
        if entity_name in self._registry:
            return self._registry[entity_name]
        else:
            return self._find_entity_in_records_by_class_name(entity_name)
817197
private static TableModel entity2ModelIgnoreConfigMethod(Class<?> entityClass) {
		DialectException.assureNotNull(entityClass, "entity2Model method does not accept a null class");

		// Entity
		String tableName = null;
		Map<String, Object> entityMap = getFirstEntityAnno(entityClass, "Entity");
		tableName = (String) entityMap.get("name");

		// Table
		Map<String, Object> tableMap = getFirstEntityAnno(entityClass, "Table");
		if (!StrUtils.isEmpty(tableMap.get("name")))
			tableName = (String) tableMap.get("name");
		if (StrUtils.isEmpty(tableName))
			tableName = entityClass.getSimpleName();
		TableModel model = new TableModel(tableName); // Build the tableModel
		model.setEntityClass(entityClass);
		if (!tableMap.isEmpty()) {
			// Index
			Annotation[] indexes = (Annotation[]) tableMap.get("indexes");
			if (indexes != null && indexes.length > 0)
				for (Annotation anno : indexes) {
					Map<String, Object> mp = changeAnnotationValuesToMap(anno, anno.annotationType());
					String columnListString = (String) mp.get("columnList");
					String[] columns;
					if (columnListString.indexOf(',') >= 0)
						columns = columnListString.split(",");
					else
						columns = new String[] { columnListString };
					if (columns.length > 0)
						model.index((String) mp.get("name")).columns(columns).setUnique((Boolean) mp.get("unique"));
				}

			// Unique
			Annotation[] uniques = (Annotation[]) tableMap.get("uniqueConstraints");
			if (uniques != null && uniques.length > 0)
				for (Annotation anno : uniques) {
					Map<String, Object> mp = changeAnnotationValuesToMap(anno, anno.annotationType());
					String[] columnNames = (String[]) mp.get("columnNames");
					if (columnNames != null && columnNames.length > 0)
						model.unique((String) mp.get("name")).columns(columnNames);
				}
		}

		// SequenceGenerator
		Map<String, Object> seqMap = getFirstEntityAnno(entityClass, "SequenceGenerator");
		if (!seqMap.isEmpty()) {
			model.sequenceGenerator((String) seqMap.get("name"), (String) seqMap.get("sequenceName"),
					(Integer) seqMap.get("initialValue"), (Integer) seqMap.get("allocationSize"));
		}

		// TableGenerator
		Map<String, Object> tableGenMap = getFirstEntityAnno(entityClass, "TableGenerator");
		if (!tableGenMap.isEmpty()) {
			model.tableGenerator((String) tableGenMap.get("name"), (String) tableGenMap.get("table"),
					(String) tableGenMap.get("pkColumnName"), (String) tableGenMap.get("valueColumnName"),
					(String) tableGenMap.get("pkColumnValue"), (Integer) tableGenMap.get("initialValue"),
					(Integer) tableGenMap.get("allocationSize"));
		}

		// UUIDAny
		Map<String, Object> uuidAnyMp = getFirstEntityAnno(entityClass, "UUIDAny");
		if (!uuidAnyMp.isEmpty()) {
			model.uuidAny((String) uuidAnyMp.get("name"), (Integer) uuidAnyMp.get("length"));
		}

		// FKey
		List<Map<String, Object>> fkeys = getEntityAnnos(entityClass, "FKey");
		for (Map<String, Object> map : fkeys) {
			Boolean ddl = (Boolean) map.get("ddl");
			if (ddl == null)
				ddl = true;
			model.fkey((String) map.get("name")).columns((String[]) map.get("columns")).refs((String[]) map.get("refs"))
					.ddl(ddl);
		}

		BeanInfo beanInfo = null;
		PropertyDescriptor[] pds = null;
		try {
			beanInfo = Introspector.getBeanInfo(entityClass);
			pds = beanInfo.getPropertyDescriptors();
		} catch (Exception e) {
			DialectException.throwEX("entity2Model can not get bean info", e);
		}

		for (PropertyDescriptor pd : pds) {
			String entityfieldName = pd.getName();
			if ("class".equals(entityfieldName) || "simpleName".equals(entityfieldName)
					|| "canonicalName".equals(entityfieldName))
				continue;
			Class<?> propertyClass = pd.getPropertyType();

			Field field = ReflectionUtils.findField(entityClass, entityfieldName);
			if (field == null)
				continue;

			if (!getFirstEntityAnno(field, "Transient").isEmpty() || !TypeUtils.canMapToSqlType(propertyClass)) {
				ColumnModel col = new ColumnModel(entityfieldName);
				col.setColumnType(TypeUtils.toType(propertyClass));
				col.setLengths(new Integer[] { 255, 0, 0 });
				col.setTransientable(true);
				col.setEntityField(entityfieldName);
				col.setTableModel(model);
				model.addColumn(col);
			} else {

				// SequenceGenerator
				Map<String, Object> map = getFirstEntityAnno(field, "SequenceGenerator");
				if (!map.isEmpty()) {
					model.sequenceGenerator((String) map.get("name"), (String) map.get("sequenceName"),
							(Integer) map.get("initialValue"), (Integer) map.get("allocationSize"));
				}

				// TableGenerator
				map = getFirstEntityAnno(field, "TableGenerator");
				if (!map.isEmpty()) {
					model.tableGenerator((String) map.get("name"), (String) map.get("table"),
							(String) map.get("pkColumnName"), (String) map.get("valueColumnName"),
							(String) map.get("pkColumnValue"), (Integer) map.get("initialValue"),
							(Integer) map.get("allocationSize"));
				}

				// UUIDAny
				map = getFirstEntityAnno(field, "UUIDAny");
				if (!map.isEmpty()) {
					model.uuidAny((String) map.get("name"), (Integer) map.get("length"));
				}

				ColumnModel col = new ColumnModel(entityfieldName);
				col.entityField(entityfieldName);
				// Column
				Map<String, Object> colMap = getFirstEntityAnno(field, "Column");
				if (!colMap.isEmpty()) {
					if (!(Boolean) colMap.get("nullable"))
						col.setNullable(false);
					if (!StrUtils.isEmpty(colMap.get("name")))
						col.setColumnName((String) colMap.get("name"));
					col.setLength((Integer) colMap.get("length"));
					col.setPrecision((Integer) colMap.get("precision"));
					col.setScale((Integer) colMap.get("scale"));
					col.setLengths(new Integer[] { col.getLength(), col.getPrecision(), col.getScale() });
					if (!StrUtils.isEmpty(colMap.get("columnDefinition")))
						col.setColumnType(TypeUtils.toType((String) colMap.get("columnDefinition")));
					else
						col.setColumnType(TypeUtils.toType(propertyClass));
					col.setInsertable((Boolean) colMap.get("insertable"));
					col.setUpdatable((Boolean) colMap.get("updatable"));
				} else {
					col.setColumnType(TypeUtils.toType(propertyClass));
					col.setLengths(new Integer[] { 255, 0, 0 });
				}

				// Id
				if (!getFirstEntityAnno(field, "Id").isEmpty() || !getFirstEntityAnno(field, "PKey").isEmpty())
					col.pkey();

				// Is a ShardTable column?
				Map<String, Object> shardTableMap = getFirstEntityAnno(field, "ShardTable");
				if (!shardTableMap.isEmpty())
					col.shardTable((String[]) shardTableMap.get("value"));

				// Is ShardDatabase?
				Map<String, Object> shardDatabaseMap = getFirstEntityAnno(field, "ShardDatabase");
				if (!shardDatabaseMap.isEmpty())
					col.shardDatabase((String[]) shardDatabaseMap.get("value"));

				col.setEntityField(entityfieldName);
				col.setTableModel(model);
				// col will also set TableModel field point to its owner
				model.addColumn(col);

				// shortcut Id generator annotations
				if (existEntityAnno(field, "AutoId"))
					col.autoId();
				if (existEntityAnno(field, "IdentityId"))
					col.identityId();
				if (existEntityAnno(field, "TimeStampId"))
					col.timeStampId();
				if (existEntityAnno(field, "UUID25"))
					col.uuid25();
				if (existEntityAnno(field, "UUID32"))
					col.uuid32();
				if (existEntityAnno(field, "UUID36"))
					col.uuid36();
				if (existEntityAnno(field, "Snowflake"))
					col.snowflake();

				// GeneratedValue
				Map<String, Object> gvMap = getFirstEntityAnno(field, "GeneratedValue");
				if (!gvMap.isEmpty()) {
					Object strategy = gvMap.get("strategy");
					if (strategy != null) {
						String strategyStr = strategy.toString();

						if ("AUTO".equals(strategyStr))
							col.autoId();
						else if ("IDENTITY".equals(strategyStr))
							col.identityId();
						else if ("UUID25".equals(strategyStr))
							col.uuid25();
						else if ("UUID32".equals(strategyStr))
							col.uuid32();
						else if ("UUID36".equals(strategyStr))
							col.uuid36();
						else if ("TIMESTAMP".equals(strategyStr))
							col.timeStampId();
						else {
							String generator = (String) gvMap.get("generator");
							if (StrUtils.isEmpty(generator))
								throw new DialectException(
										"GeneratedValue strategy '" + strategyStr + "' can not find a generator");
							col.idGenerator(generator);
						}
					}
				}

				// SingleFKey is a shortcut format of FKey, only for 1
				// column
				Map<String, Object> refMap = getFirstEntityAnno(field, "SingleFKey");
				if (!refMap.isEmpty()) {
					Boolean ddl = (Boolean) refMap.get("ddl");
					if (ddl == null)
						ddl = true;
					model.fkey((String) refMap.get("name")).columns(col.getColumnName())
							.refs((String[]) refMap.get("refs")).ddl(ddl);
				}

				// SingleIndex is a ShortCut format of Index, only for 1
				// column
				Map<String, Object> idxMap = getFirstEntityAnno(field, "SingleIndex");
				if (!idxMap.isEmpty())
					model.index((String) idxMap.get("name")).columns(col.getColumnName());

				// SingleUnique is a ShortCut format of Unique, only for 1
				// column
				Map<String, Object> uniMap = getFirstEntityAnno(field, "SingleUnique");
				if (!uniMap.isEmpty())
					model.unique((String) uniMap.get("name")).columns(col.getColumnName());
			}

		} // End of columns loop
		return model;
	}
913015
public static RepositoryQuery lookupFrom(EbeanQueryMethod method, EbeanServer ebeanServer) {
        final String queryName = method.getNamedQueryName();

        LOG.debug("Looking up named query {}", queryName);

        try {
            Query query = ebeanServer.createNamedQuery(method.getEntityInformation().getJavaType(), queryName);
            return new NamedEbeanQuery(method, ebeanServer, query);
        } catch (PersistenceException e) {
            LOG.debug("Did not find named query {}", queryName);
            return null;
        }
    }
1298637
@SuppressWarnings("unchecked")
    @Transactional
    public Comparable<Object> getVersion(E entity) {
        EntityType<E> entityType = entityManager.getMetamodel().entity(type);
        if (!entityType.hasVersionAttribute()) {
            return null;
        }
        return (Comparable<Object>) jpaUtil.getValue(entity, getVersionAttribute(entityType));
    }
1028122
public Entity get(Entity where) throws SQLException {
		return db.find(null, fixEntity(where), new EntityHandler());
	}
653997
public EntityType getEntityType(Class<?> entityClass) {
    String className = entityClass.getName();
    EntityType type = entityTypes.get(className);
    if (null != type) { return type; }

    type = classEntityTypes.get(className);
    if (null == type) {
      List<EntityType> matched = CollectUtils.newArrayList();
      for (EntityType entityType : entityTypes.values()) {
        if (className.equals(entityType.getEntityName())
            || className.equals(entityType.getEntityClass().getName())) {
          matched.add(entityType);
        }
      }
      if (matched.size() > 1) { throw new RuntimeException("multi-entityName for class:" + className); }
      if (matched.isEmpty()) {
        EntityType tmp = new EntityType(entityClass);
        classEntityTypes.put(className, tmp);
        return tmp;
      } else {
        classEntityTypes.put(className, matched.get(0));
        type = (EntityType) matched.get(0);
      }
    }
    return type;
  }
476528
protected final boolean entityExists(final String entityName) {
        final Set<EntityType<?>> entityTypes = getEm().getMetamodel().getEntities();
        for (final EntityType<?> entityType : entityTypes) {
            if (entityType.getName().equals(entityName)) {
                return true;
            }
        }
        return false;
    }
964985
@Override
    public <T> Query<T> createQuery(Class<T> entityType) {
        Assert.notNull(entityType, "entityType must not null");
        return ebeanServer.find(entityType);
    }
196488
public SelectBuilder rightJoin(Class<?> entityClass) {
    currentTable = rootTable.rightJoin(entityClass, currentTable.entityClass);
    return this;
  }