This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void whenFirstPageOfResourcesAreRetrieved_thenSecondPageIsNext(){ | |
Response response = givenAuth().get( paths.getFooURL()+"?page=0&size=10" ); | |
String uriToNextPage = extractURIByRel( response.getHeader( LINK ), REL_NEXT ); | |
assertEquals( paths.getFooURL()+"?page=1&size=10", uriToNextPage ); | |
} | |
@Test | |
public void whenFirstPageOfResourcesAreRetrieved_thenNoPreviousPage(){ | |
Response response = givenAuth().get( paths.getFooURL()+"?page=0&size=10" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.baeldung.web.hateoas; | |
import javax.servlet.http.HttpServletResponse; | |
import org.springframework.context.ApplicationListener; | |
import org.springframework.stereotype.Component; | |
import org.springframework.web.util.UriComponentsBuilder; | |
import com.google.common.base.Preconditions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void addLinkHeaderOnPagedResourceRetrieval( | |
UriComponentsBuilder uriBuilder, HttpServletResponse response, | |
Class clazz, int page, int totalPages, int size ){ | |
String resourceName = clazz.getSimpleName().toString().toLowerCase(); | |
uriBuilder.path( "/admin/" + resourceName ); | |
StringBuilder linkHeader = new StringBuilder(); | |
if( hasNextPage( page, totalPages ) ){ | |
String uriNextPage = constructNextPageUri( uriBuilder, page, size ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping( value = "admin/foo",params = { "page", "size" },method = GET ) | |
@ResponseBody | |
public List< Foo > findPaginated( | |
@RequestParam( "page" ) int page, @RequestParam( "size" ) int size, | |
UriComponentsBuilder uriBuilder, HttpServletResponse response ){ | |
Page< Foo > resultPage = service.findPaginated( page, size ); | |
if( page > resultPage.getTotalPages() ){ | |
throw new ResourceNotFoundException(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transactional( propagation = Propagation.REQUIRES_NEW ) | |
public class Controller{ | |
... | |
} | |
@Transactional( propagation = Propagation.MANDATORY ) | |
public class Service{ | |
... | |
} | |
@Transactional( propagation = Propagation.MANDATORY ) | |
public class DAO{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:aop="http://www.springframework.org/schema/aop" | |
xmlns:tx="http://www.springframework.org/schema/tx" | |
xsi:schemaLocation=" | |
http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd | |
http://www.springframework.org/schema/tx | |
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"> | |
<property name="entityManagerFactory" ref="myEmf" /> | |
</bean> | |
<tx:annotation-driven transaction-manager="txManager" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableTransactionManagement | |
public class PersistenceJPAConfig{ | |
@Bean | |
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(){ | |
... | |
} | |
@Bean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TransactionConfiguration( defaultRollback = true ) | |
@Transactional | |
public class TransactionalIntegrationTest{ | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.springframework.data</groupId> | |
<artifactId>spring-data-jpa</artifactId> | |
<version>1.0.2.RELEASE</version> | |
</dependency> |