27 Ekim 2017 Cuma

SpringData QueryDslPredicateExecutor Sınıfı - Repository Sınıfı İçindir

Giriş
Şu satırı dahil ederiz.
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
Repository sınıfımız bu sınıftan kalıtır
Örnek
Şöyle yaparız
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;

import com.abhicodes.querydsldynamicquery.entity.Post;

@Repository
public interface PostRepository extends JpaRepository<Post, Integer>, 
  QuerydslPredicateExecutor<Post> {

}

findAll metodu
Örnek
Şöyle yaparız.
public interface SomeRepository extends JpaRepository<Some, Long>,
  PagingAndSortingRepository<Some, Long>, QueryDslPredicateExecutor<Some>{

}
Query dsl kullanarak şöyle yaparız.
@Controller
class SomeController {

  private final SomeRepository repository;

  @RequestMapping(value = "/", method = RequestMethod.GET)
  String index(Model model,
               @QuerydslPredicate(root = Some.class) Predicate predicate,
               Pageable pageable) {

    model.addAttribute("data", repository.findAll(predicate, pageable));
    return "index";
  }
}

24 Ekim 2017 Salı

TcpNetClientConnectionFactory Sınıfı

setTcpSocketFactorySupport metodu
Şöyle yaparız.
private static final int SERIALIZER_HEADER_SIZE = 2;

@Bean
public ByteArrayLengthHeaderSerializer byteArrayLengthHeaderSerializer() {
  return new ByteArrayLengthHeaderSerializer(SERIALIZER_HEADER_SIZE);
}

@Bean
public AbstractClientConnectionFactory tcpClientConnectionFactory() {
  TcpNetClientConnectionFactory connFactory =
    new TcpNetClientConnectionFactory(props.getUrl(), props.getPort());
  connFactory.setSerializer(byteArrayLengthHeaderSerializer());
  connFactory.setDeserializer(byteArrayLengthHeaderSerializer());
  connFactory.setSoTimeout(props.getSoTimeout());

  if (props.isUseSSL()) {
    connFactory.setTcpSocketFactorySupport(new DefaultTcpNetSSLSocketFactorySupport(()-> {
      return SSLContext.getDefault();
    }));
  }

  return connFactory;
}