Github user kevdoran commented on a diff in the pull request:

    https://github.com/apache/nifi-registry/pull/10#discussion_r140024359
  
    --- Diff: 
nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/repository/BucketRepository.java
 ---
    @@ -14,38 +14,21 @@
      * See the License for the specific language governing permissions and
      * limitations under the License.
      */
    -package org.apache.nifi.registry.metadata;
    +package org.apache.nifi.registry.db.repository;
     
    -import java.util.Set;
    +import org.apache.nifi.registry.db.entity.BucketEntity;
    +import org.springframework.data.jpa.repository.Query;
    +import org.springframework.data.repository.PagingAndSortingRepository;
    +import org.springframework.data.repository.query.Param;
    +
    +import java.util.List;
     
     /**
    - * The metadata for a bucket, along with the metadata about any objects 
stored in the bucket, such as flows.
    + * Spring Data Repository for BucketEntity.
      */
    -public interface BucketMetadata {
    -
    -    /**
    -     * @return the identifier of this bucket
    -     */
    -    String getIdentifier();
    -
    -    /**
    -     * @return the name of this bucket
    -     */
    -    String getName();
    -
    -    /**
    -     * @return the timestamp of when this bucket was created
    -     */
    -    long getCreatedTimestamp();
    -
    -    /**
    -     * @return the description of this bucket
    -     */
    -    String getDescription();
    +public interface BucketRepository extends 
PagingAndSortingRepository<BucketEntity,String> {
     
    -    /**
    -     * @return the metadata about the flows that are part of this bucket
    -     */
    -    Set<FlowMetadata> getFlowMetadata();
    +    @Query("SELECT b FROM BucketEntity b WHERE LOWER(b.name) = 
LOWER(:name)")
    +    List<BucketEntity> findByName(@Param("name") String name);
    --- End diff --
    
    This can be rewritten without the `@Query` annotation just by renaming the 
method to `findByNameIgnoreCase`, and then the generated spring-data-jpa code 
will produce the query you want.
    
    The advantage is not having to write and maintain the SQL in the `@Query` 
annotation, which prevents vendor-specific SQL syntax from sneaking in over 
time. It might not be possible to avoid the `@Query` annotation for every 
repository method, for example if you need a specific query optimization that 
spring-data-jpa cannot generate. I still think limiting explicit SQL is good 
practice in order to keep open the possibility that someone might want to 
modify registry to use an alternative to H2.


---

Reply via email to