public static String buildSelectSQL(String entityName, BeanDescFactory beanDescFactory, EntityOperator entityOperator, Class<?> clazz, NameConverter nameConverter){
        StringBuilder sb = new StringBuilder();
        BeanDesc beanDesc = beanDescFactory.getBeanDesc(clazz);
        String tableName = entityName != null ? entityName : MirageUtil.getTableName(clazz, nameConverter); // if no name is provided, use the clazz
        sb.append("SELECT * FROM ");
        sb.append(tableName);
        sb.append(" WHERE ");

        int count = 0;

        for(int i=0; i<beanDesc.getPropertyDescSize(); i++){
            PropertyDesc pd = beanDesc.getPropertyDesc(i);
            PrimaryKeyInfo primaryKey = entityOperator.getPrimaryKeyInfo(clazz, pd, nameConverter);
            if(primaryKey != null){
                if(count != 0){
                    sb.append(" AND ");
                }
                sb.append(MirageUtil.getColumnName(entityOperator, clazz, pd, nameConverter));
                sb.append(" = ?");
                count++;
            }
        }
        // if no annotated PKs were found:
        if(count == 0){
            // for Maps we assume the ID exists as a PK (and it's the only one)
            if(clazz == Map.class || clazz == HashMap.class || clazz == LinkedHashMap.class) {
                sb.append("ID = ?");
            }  else {
                // for Entities that have no PK we search for a field called ID (so fallback to this convention)
                PropertyDesc propertyDesc = beanDesc.getPropertyDesc("id");
                if(propertyDesc!=null && propertyDesc.getPropertyName()!=null && "id".equals(propertyDesc.getPropertyName())) {
                    sb.append("ID = ?");
                } else {
                    throw new RuntimeException("Primary key is not found: " + clazz.getName());
                }
            }
        }

        return sb.toString();
    }
public static String buildSelectSQL ( String entityName , BeanDescFactory beanDescFactory , EntityOperator entityOperator , Class < ? > clazz , NameConverter nameConverter ) { StringBuilder sb = new StringBuilder ( ) ; BeanDesc beanDesc = beanDescFactory . getBeanDesc ( clazz ) ; String tableName = entityName != null ? entityName : MirageUtil . getTableName ( clazz , nameConverter ) ; sb . append ( "SELECT * FROM " ) ; sb . append ( tableName ) ; sb . append ( " WHERE " ) ; int count = 0 ; for ( int i = 0 ; i < beanDesc . getPropertyDescSize ( ) ; i ++ ) { PropertyDesc pd = beanDesc . getPropertyDesc ( i ) ; PrimaryKeyInfo primaryKey = entityOperator . getPrimaryKeyInfo ( clazz , pd , nameConverter ) ; if ( primaryKey != null ) { if ( count != 0 ) { sb . append ( " AND " ) ; } sb . append ( MirageUtil . getColumnName ( entityOperator , clazz , pd , nameConverter ) ) ; sb . append ( " = ?" ) ; count ++ ; } } if ( count == 0 ) { if ( clazz == Map . class || clazz == HashMap . class || clazz == LinkedHashMap . class ) { sb . append ( "ID = ?" ) ; } else { PropertyDesc propertyDesc = beanDesc . getPropertyDesc ( "id" ) ; if ( propertyDesc != null && propertyDesc . getPropertyName ( ) != null && "id" . equals ( propertyDesc . getPropertyName ( ) ) ) { sb . append ( "ID = ?" ) ; } else { throw new RuntimeException ( "Primary key is not found: " + clazz . getName ( ) ) ; } } } return sb . toString ( ) ; }
Builds a select (by using the primary key) SQL from the entity class. If the entity is a Map, than 'id' is assumed as a PK.

@param entityName the entity name to select
@param beanDescFactory the bean descriptor factory
@param entityOperator the entity operator
@param clazz the entity class to select
@param nameConverter the name converter

@return Select SQL

@throws RuntimeException the entity class has no primary keys