Search in sources :

Example 6 with ResourceType

use of com.github.mgramin.sqlboot.model.resource_type.ResourceType in project sql-boot by sql-boot.

the class ViewJdbcResourceTypeTest method path.

@Test
public void path() {
    final ResourceType view = new ViewJdbcResourceType(dataSource);
    assertEquals(2, view.path().size());
    assertEquals("schema", view.path().get(0));
    assertEquals("view", view.path().get(1));
}
Also used : ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) Test(org.junit.Test)

Example 7 with ResourceType

use of com.github.mgramin.sqlboot.model.resource_type.ResourceType in project sql-boot by sql-boot.

the class ViewJdbcResourceTypeTest method read.

@Test
public void read() {
    final ResourceType view = new ViewJdbcResourceType(dataSource);
    final Stream<DbResource> views = view.read(new SqlPlaceholdersWrapper(new DbUri("view", asList("*"))));
    assertEquals(2, views.count());
}
Also used : SqlPlaceholdersWrapper(com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) Test(org.junit.Test)

Example 8 with ResourceType

use of com.github.mgramin.sqlboot.model.resource_type.ResourceType in project sql-boot by sql-boot.

the class ApiController method getListResponseEntity.

private ResponseEntity<List<DbResource>> getListResponseEntity(final HttpServletRequest request, final String connectionName, final String type) {
    final Uri uri = new SqlPlaceholdersWrapper(new DbUri(parseUri(type, request)));
    final ResourceType fsResourceTypes = new FsResourceTypes(dbConnectionList.getConnectionByName(connectionName));
    final List<DbResource> collect = fsResourceTypes.read(uri).collect(toList());
    if (collect.isEmpty()) {
        return new ResponseEntity<>(collect, HttpStatus.NO_CONTENT);
    } else {
        return new ResponseEntity<>(collect, HttpStatus.OK);
    }
}
Also used : SqlPlaceholdersWrapper(com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) ResponseEntity(org.springframework.http.ResponseEntity) FsResourceTypes(com.github.mgramin.sqlboot.model.resource_type.impl.composite.FsResourceTypes) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) Uri(com.github.mgramin.sqlboot.model.uri.Uri)

Example 9 with ResourceType

use of com.github.mgramin.sqlboot.model.resource_type.ResourceType in project sql-boot by sql-boot.

the class ApiController method getListResponseEntityHeaders.

private ResponseEntity<List<Map<String, Object>>> getListResponseEntityHeaders(final HttpServletRequest request, final String connectionName, final String path) {
    final Uri uri = new SqlPlaceholdersWrapper(new DbUri(parseUri(path, request)));
    ResourceType fsResourceTypes = new FsResourceTypes(dbConnectionList.getConnectionByName(connectionName));
    final List<Map<String, Object>> headers = fsResourceTypes.read(uri).map(DbResource::headers).collect(toList());
    if (headers.isEmpty()) {
        return new ResponseEntity<>(headers, HttpStatus.NO_CONTENT);
    } else {
        return new ResponseEntity<>(headers, HttpStatus.OK);
    }
}
Also used : SqlPlaceholdersWrapper(com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) ResponseEntity(org.springframework.http.ResponseEntity) FsResourceTypes(com.github.mgramin.sqlboot.model.resource_type.impl.composite.FsResourceTypes) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) Uri(com.github.mgramin.sqlboot.model.uri.Uri) Map(java.util.Map)

Example 10 with ResourceType

use of com.github.mgramin.sqlboot.model.resource_type.ResourceType in project sql-boot by sql-boot.

the class SchemaJdbcResourceTypeTest method read.

@Test
public void read() {
    final ResourceType schema = new SchemaJdbcResourceType(dataSource);
    final Stream<DbResource> schemas = schema.read(new SqlPlaceholdersWrapper(new DbUri("schema", asList("*"))));
    assertEquals(3, schemas.count());
}
Also used : SqlPlaceholdersWrapper(com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) Test(org.junit.Test)

Aggregations

ResourceType (com.github.mgramin.sqlboot.model.resource_type.ResourceType)22 Test (org.junit.Test)18 DbUri (com.github.mgramin.sqlboot.model.uri.impl.DbUri)16 SqlPlaceholdersWrapper (com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper)14 DbResource (com.github.mgramin.sqlboot.model.resource.DbResource)13 JdbcSqlQuery (com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery)4 GroovyTemplateGenerator (com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator)4 FsResourceTypes (com.github.mgramin.sqlboot.model.resource_type.impl.composite.FsResourceTypes)3 Uri (com.github.mgramin.sqlboot.model.uri.Uri)3 ProcedureJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.procedure.ProcedureJdbcResourceType)2 WhereWrapper (com.github.mgramin.sqlboot.model.resource_type.wrappers.list.WhereWrapper)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ResponseEntity (org.springframework.http.ResponseEntity)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BootException (com.github.mgramin.sqlboot.exceptions.BootException)1 DbConnectionList (com.github.mgramin.sqlboot.model.connection.DbConnectionList)1 MarkdownFile (com.github.mgramin.sqlboot.model.resource_type.impl.composite.md.MarkdownFile)1 SchemaJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.SchemaJdbcResourceType)1