Skip to content
Snippets Groups Projects
Unverified Commit 8cf84d4d authored by Martin Weise's avatar Martin Weise
Browse files

Implemented sorting for data endpoint, ref #120, closes #120

parent 0d9fe9a5
No related branches found
No related tags found
3 merge requests!81New stable release,!47Resolve "Show error messages from response",!42Fixed the query service tests
Showing
with 78 additions and 141 deletions
...@@ -95,27 +95,36 @@ public class TableDataEndpoint { ...@@ -95,27 +95,36 @@ public class TableDataEndpoint {
@NotNull @PathVariable("tableId") Long tableId, @NotNull @PathVariable("tableId") Long tableId,
@RequestParam(required = false) Instant timestamp, @RequestParam(required = false) Instant timestamp,
@RequestParam(required = false) Long page, @RequestParam(required = false) Long page,
@RequestParam(required = false) Long size) @RequestParam(required = false) Long size,
@RequestParam(required = false) String sortBy,
@RequestParam(required = false) Boolean sortDesc)
throws TableNotFoundException, DatabaseNotFoundException, DatabaseConnectionException, throws TableNotFoundException, DatabaseNotFoundException, DatabaseConnectionException,
ImageNotSupportedException, TableMalformedException, PaginationException, ContainerNotFoundException, ImageNotSupportedException, TableMalformedException, PaginationException, ContainerNotFoundException,
QueryStoreException { QueryStoreException, SortDataException {
if ((page == null && size != null) || (page != null && size == null)) { if ((page == null && size != null) || (page != null && size == null)) {
log.error("Cannot perform pagination with only one of page/size set."); log.error("Cannot perform pagination with only one of page/size set.");
log.debug("invalid pagination specification, one of page/size is null, either both should be null or none."); log.debug("invalid pagination specification, one of page/size is null, either both should be null or none.");
throw new PaginationException("Invalid pagination parameters"); throw new PaginationException("Invalid pagination parameters");
} }
if (page != null && page < 0) { if (page != null && page < 0) {
throw new PaginationException("Page number cannot be lower than 0"); log.error("Failed to paginate: page number cannot be lower than 0");
throw new PaginationException("Failed to paginate");
} }
if (size != null && size <= 0) { if (size != null && size <= 0) {
throw new PaginationException("Page number cannot be lower or equal to 0"); log.error("Failed to paginate: page number cannot be lower or equal to 0");
throw new PaginationException("Failed to paginate");
}
if ((sortBy != null && sortDesc == null) || (sortBy == null && sortDesc != null)) {
log.error("Failed to sort: both sortBy and sortDesc must be present or absent");
throw new SortDataException("Failed to sort");
} }
/* fixme query store maybe not created, create it through running findAll() */ /* fixme query store maybe not created, create it through running findAll() */
storeService.findAll(id, databaseId); storeService.findAll(id, databaseId);
final BigInteger count = queryService.count(id, databaseId, tableId, timestamp); final BigInteger count = queryService.count(id, databaseId, tableId, timestamp);
final HttpHeaders headers = new HttpHeaders(); final HttpHeaders headers = new HttpHeaders();
headers.set("FDA-COUNT", count.toString()); headers.set("FDA-COUNT", count.toString());
final QueryResultDto response = queryService.findAll(id, databaseId, tableId, timestamp, page, size); final QueryResultDto response = queryService.findAll(id, databaseId, tableId, timestamp, page, size, sortBy,
sortDesc);
return ResponseEntity.ok() return ResponseEntity.ok()
.headers(headers) .headers(headers)
.body(response); .body(response);
......
...@@ -78,21 +78,22 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -78,21 +78,22 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
@Test @Test
public void getAll_succeeds() throws TableNotFoundException, DatabaseConnectionException, TableMalformedException, public void getAll_succeeds() throws TableNotFoundException, DatabaseConnectionException, TableMalformedException,
DatabaseNotFoundException, ImageNotSupportedException, PaginationException, ContainerNotFoundException, QueryStoreException { DatabaseNotFoundException, ImageNotSupportedException, PaginationException, ContainerNotFoundException,
QueryStoreException, SortDataException {
/* test */ /* test */
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, null, null, null); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, null, null, null, null, null);
} }
@Test @Test
public void findAll_noPagination_succeeds() throws TableNotFoundException, DatabaseConnectionException, public void findAll_noPagination_succeeds() throws TableNotFoundException, DatabaseConnectionException,
TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException, PaginationException, TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException, PaginationException,
ContainerNotFoundException, QueryStoreException { ContainerNotFoundException, QueryStoreException, SortDataException {
final Long page = null; final Long page = null;
final Long size = null; final Long size = null;
/* test */ /* test */
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size, null, null);
} }
@Test @Test
...@@ -102,7 +103,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -102,7 +103,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(PaginationException.class, () -> { assertThrows(PaginationException.class, () -> {
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size, null, null);
}); });
} }
...@@ -113,7 +114,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -113,7 +114,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(PaginationException.class, () -> { assertThrows(PaginationException.class, () -> {
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size, null, null);
}); });
} }
...@@ -124,7 +125,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -124,7 +125,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(PaginationException.class, () -> { assertThrows(PaginationException.class, () -> {
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size, null, null);
}); });
} }
...@@ -135,7 +136,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -135,7 +136,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(PaginationException.class, () -> { assertThrows(PaginationException.class, () -> {
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size, null, null);
}); });
} }
...@@ -146,7 +147,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -146,7 +147,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(PaginationException.class, () -> { assertThrows(PaginationException.class, () -> {
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size, null, null);
}); });
} }
...@@ -157,7 +158,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -157,7 +158,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(PaginationException.class, () -> { assertThrows(PaginationException.class, () -> {
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size, null, null);
}); });
} }
...@@ -168,19 +169,19 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -168,19 +169,19 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(PaginationException.class, () -> { assertThrows(PaginationException.class, () -> {
dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size); dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1_CREATED, page, size, null, null);
}); });
} }
@Test @Test
public void getAllTotal_succeeds() throws TableNotFoundException, DatabaseConnectionException, public void getAllTotal_succeeds() throws TableNotFoundException, DatabaseConnectionException,
TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException,
PaginationException, ContainerNotFoundException, QueryStoreException { PaginationException, ContainerNotFoundException, QueryStoreException, SortDataException {
final Instant timestamp = Instant.now(); final Instant timestamp = Instant.now();
/* test */ /* test */
final ResponseEntity<QueryResultDto> response = dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, final ResponseEntity<QueryResultDto> response = dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID,
TABLE_1_ID, timestamp, null, null); TABLE_1_ID, timestamp, null, null, null, null);
assertNotNull(response); assertNotNull(response);
assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(HttpStatus.OK, response.getStatusCode());
} }
...@@ -188,12 +189,12 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { ...@@ -188,12 +189,12 @@ public class TableDataEndpointUnitTest extends BaseUnitTest {
@Test @Test
public void getAllCount_succeeds() throws TableNotFoundException, DatabaseConnectionException, public void getAllCount_succeeds() throws TableNotFoundException, DatabaseConnectionException,
TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException,
PaginationException, ContainerNotFoundException, QueryStoreException { PaginationException, ContainerNotFoundException, QueryStoreException, SortDataException {
final Instant timestamp = Instant.now(); final Instant timestamp = Instant.now();
/* test */ /* test */
final ResponseEntity<QueryResultDto> response = dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID, final ResponseEntity<QueryResultDto> response = dataEndpoint.getAll(CONTAINER_1_ID, DATABASE_1_ID,
TABLE_1_ID, timestamp, null, null); TABLE_1_ID, timestamp, null, null, null, null);
assertNotNull(response); assertNotNull(response);
assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue(response.getHeaders().containsKey("FDA-COUNT")); assertTrue(response.getHeaders().containsKey("FDA-COUNT"));
......
...@@ -152,7 +152,7 @@ public class QueryServiceIntegrationTest extends BaseUnitTest { ...@@ -152,7 +152,7 @@ public class QueryServiceIntegrationTest extends BaseUnitTest {
/* test */ /* test */
final QueryResultDto result = queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, Instant.now(), final QueryResultDto result = queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, Instant.now(),
null, null); null, null, null, null);
assertEquals(3, result.getResult().size()); assertEquals(3, result.getResult().size());
assertEquals(BigInteger.valueOf(1L), result.getResult().get(0).get(COLUMN_1_1_NAME)); assertEquals(BigInteger.valueOf(1L), result.getResult().get(0).get(COLUMN_1_1_NAME));
assertEquals(toInstant("2008-12-01"), result.getResult().get(0).get(COLUMN_1_2_NAME)); assertEquals(toInstant("2008-12-01"), result.getResult().get(0).get(COLUMN_1_2_NAME));
......
...@@ -138,7 +138,7 @@ public class QueryServiceUnitTest extends BaseUnitTest { ...@@ -138,7 +138,7 @@ public class QueryServiceUnitTest extends BaseUnitTest {
.thenReturn(Optional.of(TABLE_1)); .thenReturn(Optional.of(TABLE_1));
/* test */ /* test */
queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, Instant.now(), page, size); queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, Instant.now(), page, size, null, null);
} }
@Test @Test
...@@ -154,7 +154,7 @@ public class QueryServiceUnitTest extends BaseUnitTest { ...@@ -154,7 +154,7 @@ public class QueryServiceUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(TableNotFoundException.class, () -> { assertThrows(TableNotFoundException.class, () -> {
queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, Instant.now(), page, size); queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, Instant.now(), page, size, null, null);
}); });
} }
...@@ -171,7 +171,7 @@ public class QueryServiceUnitTest extends BaseUnitTest { ...@@ -171,7 +171,7 @@ public class QueryServiceUnitTest extends BaseUnitTest {
/* test */ /* test */
assertThrows(DatabaseNotFoundException.class, () -> { assertThrows(DatabaseNotFoundException.class, () -> {
queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, Instant.now(), page, size); queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, Instant.now(), page, size, null, null);
}); });
} }
...@@ -205,7 +205,7 @@ public class QueryServiceUnitTest extends BaseUnitTest { ...@@ -205,7 +205,7 @@ public class QueryServiceUnitTest extends BaseUnitTest {
.thenReturn(Optional.of(TABLE_1)); .thenReturn(Optional.of(TABLE_1));
/* test */ /* test */
queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, null, null, null); queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, null, null, null, null, null);
} }
@Test @Test
...@@ -221,7 +221,7 @@ public class QueryServiceUnitTest extends BaseUnitTest { ...@@ -221,7 +221,7 @@ public class QueryServiceUnitTest extends BaseUnitTest {
.thenReturn(Optional.of(TABLE_1)); .thenReturn(Optional.of(TABLE_1));
/* test */ /* test */
queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, timestamp, null, null); queryService.findAll(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, timestamp, null, null, null, null);
} }
} }
package at.tuwien.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public class SortDataException extends Exception {
public SortDataException(String msg) {
super(msg);
}
public SortDataException(String msg, Throwable thr) {
super(msg, thr);
}
public SortDataException(Throwable thr) {
super(thr);
}
}
...@@ -168,7 +168,8 @@ public interface QueryMapper { ...@@ -168,7 +168,8 @@ public interface QueryMapper {
"';"; "';";
} }
default String tableToRawFindAllQuery(Table table, Instant timestamp, Long size, Long page) default String tableToRawFindAllQuery(Table table, Instant timestamp, Long size, Long page, String sortBy,
Boolean sortDesc)
throws ImageNotSupportedException { throws ImageNotSupportedException {
/* param check */ /* param check */
if (!table.getDatabase().getContainer().getImage().getRepository().equals("mariadb")) { if (!table.getDatabase().getContainer().getImage().getRepository().equals("mariadb")) {
...@@ -192,6 +193,14 @@ public interface QueryMapper { ...@@ -192,6 +193,14 @@ public interface QueryMapper {
.append("` FOR SYSTEM_TIME AS OF TIMESTAMP'") .append("` FOR SYSTEM_TIME AS OF TIMESTAMP'")
.append(LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna"))) .append(LocalDateTime.ofInstant(timestamp, ZoneId.of("Europe/Vienna")))
.append("'"); .append("'");
if (sortBy != null && sortDesc != null) {
/* sorting requested */
query.append(" ORDER BY ")
.append("`")
.append(sortBy)
.append("` ")
.append(sortDesc ? "DESC" : "ASC");
}
if (size != null && page != null) { if (size != null && page != null) {
log.trace("pagination size/limit of {}", size); log.trace("pagination size/limit of {}", size);
query.append(" LIMIT ") query.append(" LIMIT ")
......
package at.tuwien.querystore;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
import java.time.Instant;
@Data
@Entity
@javax.persistence.Table(name = "qs_column")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EntityListeners(AuditingEntityListener.class)
public class Column implements Serializable {
@Id
@EqualsAndHashCode.Include
@GeneratedValue(generator = "column-sequence")
@GenericGenerator(
name = "column-sequence",
strategy = "enhanced-sequence",
parameters = @org.hibernate.annotations.Parameter(name = "sequence_name", value = "qs_column_seq")
)
private Long id;
@javax.persistence.Column(nullable = false)
private Long tid;
@javax.persistence.Column(nullable = false)
private Long dbid;
@javax.persistence.Column(nullable = false, updatable = false)
@CreatedDate
private Instant created;
@javax.persistence.Column(name = "last_modified")
@LastModifiedDate
private Instant lastModified;
}
...@@ -62,9 +62,6 @@ public class Query implements Serializable { ...@@ -62,9 +62,6 @@ public class Query implements Serializable {
@CreatedDate @CreatedDate
private Instant created; private Instant created;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
private List<Table> tables;
@javax.persistence.Column(name = "last_modified") @javax.persistence.Column(name = "last_modified")
@LastModifiedDate @LastModifiedDate
private Instant lastModified; private Instant lastModified;
......
package at.tuwien.querystore;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.time.Instant;
import java.util.List;
@Data
@Entity
@javax.persistence.Table(name = "qs_tables")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EntityListeners(AuditingEntityListener.class)
public class Table implements Serializable {
@Id
@EqualsAndHashCode.Include
@GeneratedValue(generator = "table-sequence")
@GenericGenerator(
name = "table-sequence",
strategy = "enhanced-sequence",
parameters = @org.hibernate.annotations.Parameter(name = "sequence_name", value = "qs_tables_seq")
)
private Long id;
@javax.persistence.Column(nullable = false)
private Long dbid;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
private List<Column> columns;
@javax.persistence.Column(nullable = false, updatable = false)
@CreatedDate
private Instant created;
@javax.persistence.Column(name = "last_modified")
@LastModifiedDate
private Instant lastModified;
}
...@@ -39,6 +39,8 @@ public interface QueryService { ...@@ -39,6 +39,8 @@ public interface QueryService {
* @param timestamp The given time. * @param timestamp The given time.
* @param page The page. * @param page The page.
* @param size The page size. * @param size The page size.
* @param sortBy The column after which should be sorted.
* @param sortDesc The direction it should be sorted, if true the column is sorted Z to A, if false otherwise.
* @return The select all data result * @return The select all data result
* @throws ContainerNotFoundException The container was not found in the metadata database. * @throws ContainerNotFoundException The container was not found in the metadata database.
* @throws TableNotFoundException The table was not found in the metadata database. * @throws TableNotFoundException The table was not found in the metadata database.
...@@ -48,7 +50,7 @@ public interface QueryService { ...@@ -48,7 +50,7 @@ public interface QueryService {
* @throws DatabaseConnectionException The connection to the remote database was unsuccessful. * @throws DatabaseConnectionException The connection to the remote database was unsuccessful.
*/ */
QueryResultDto findAll(Long containerId, Long databaseId, Long tableId, Instant timestamp, QueryResultDto findAll(Long containerId, Long databaseId, Long tableId, Instant timestamp,
Long page, Long size) throws TableNotFoundException, DatabaseNotFoundException, Long page, Long size, String sortBy, Boolean sortDesc) throws TableNotFoundException, DatabaseNotFoundException,
ImageNotSupportedException, DatabaseConnectionException, TableMalformedException, PaginationException, ImageNotSupportedException, DatabaseConnectionException, TableMalformedException, PaginationException,
ContainerNotFoundException; ContainerNotFoundException;
......
...@@ -3,9 +3,7 @@ package at.tuwien.service.impl; ...@@ -3,9 +3,7 @@ package at.tuwien.service.impl;
import at.tuwien.entities.container.image.ContainerImageEnvironmentItem; import at.tuwien.entities.container.image.ContainerImageEnvironmentItem;
import at.tuwien.entities.container.image.ContainerImageEnvironmentItemType; import at.tuwien.entities.container.image.ContainerImageEnvironmentItemType;
import at.tuwien.entities.database.Database; import at.tuwien.entities.database.Database;
import at.tuwien.querystore.Column;
import at.tuwien.querystore.Query; import at.tuwien.querystore.Query;
import at.tuwien.querystore.Table;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
...@@ -60,9 +58,7 @@ public abstract class HibernateConnector { ...@@ -60,9 +58,7 @@ public abstract class HibernateConnector {
.setProperty("hibernate.c3p0.max_size", String.valueOf(MAX_SIZE)) .setProperty("hibernate.c3p0.max_size", String.valueOf(MAX_SIZE))
.setProperty("hibernate.c3p0.acquire_increment", String.valueOf(INCREMENT_SIZE)) .setProperty("hibernate.c3p0.acquire_increment", String.valueOf(INCREMENT_SIZE))
.setProperty("hibernate.c3p0.timeout", String.valueOf(TIMEOUT)) .setProperty("hibernate.c3p0.timeout", String.valueOf(TIMEOUT))
.addAnnotatedClass(Query.class) .addAnnotatedClass(Query.class);
.addAnnotatedClass(Table.class)
.addAnnotatedClass(Column.class);
return configuration.buildSessionFactory(); return configuration.buildSessionFactory();
} }
......
...@@ -49,7 +49,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService ...@@ -49,7 +49,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService
} }
@Override @Override
@Transactional @Transactional(readOnly = true)
public QueryResultDto execute(Long containerId, Long databaseId, ExecuteStatementDto statement) public QueryResultDto execute(Long containerId, Long databaseId, ExecuteStatementDto statement)
throws DatabaseNotFoundException, ImageNotSupportedException, QueryMalformedException { throws DatabaseNotFoundException, ImageNotSupportedException, QueryMalformedException {
/* find */ /* find */
...@@ -87,11 +87,11 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService ...@@ -87,11 +87,11 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService
} }
@Override @Override
@Transactional @Transactional(readOnly = true)
public QueryResultDto findAll(Long containerId, Long databaseId, Long tableId, Instant timestamp, Long page, public QueryResultDto findAll(Long containerId, Long databaseId, Long tableId, Instant timestamp, Long page,
Long size) throws TableNotFoundException, DatabaseNotFoundException, Long size, String sortBy, Boolean sortDesc) throws TableNotFoundException,
ImageNotSupportedException, DatabaseConnectionException, TableMalformedException, PaginationException, DatabaseNotFoundException, ImageNotSupportedException, DatabaseConnectionException, TableMalformedException,
ContainerNotFoundException { PaginationException, ContainerNotFoundException {
/* find */ /* find */
final Database database = databaseService.find(databaseId); final Database database = databaseService.find(databaseId);
final Table table = tableService.find(databaseId, tableId); final Table table = tableService.find(databaseId, tableId);
...@@ -102,7 +102,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService ...@@ -102,7 +102,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService
log.debug("opened hibernate session in {} ms", System.currentTimeMillis() - startSession); log.debug("opened hibernate session in {} ms", System.currentTimeMillis() - startSession);
session.beginTransaction(); session.beginTransaction();
final NativeQuery<?> query = session.createSQLQuery(queryMapper.tableToRawFindAllQuery(table, timestamp, size, final NativeQuery<?> query = session.createSQLQuery(queryMapper.tableToRawFindAllQuery(table, timestamp, size,
page)); page, sortBy, sortDesc));
final int affectedTuples; final int affectedTuples;
try { try {
affectedTuples = query.executeUpdate(); affectedTuples = query.executeUpdate();
...@@ -128,7 +128,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService ...@@ -128,7 +128,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService
} }
@Override @Override
@Transactional @Transactional(readOnly = true)
public BigInteger count(Long containerId, Long databaseId, Long tableId, Instant timestamp) public BigInteger count(Long containerId, Long databaseId, Long tableId, Instant timestamp)
throws DatabaseNotFoundException, TableNotFoundException, throws DatabaseNotFoundException, TableNotFoundException,
TableMalformedException, ImageNotSupportedException { TableMalformedException, ImageNotSupportedException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment