Search in sources :

Example 6 with DbUri

use of com.github.mgramin.sqlboot.model.uri.impl.DbUri 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 7 with DbUri

use of com.github.mgramin.sqlboot.model.uri.impl.DbUri 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 8 with DbUri

use of com.github.mgramin.sqlboot.model.uri.impl.DbUri in project sql-boot by sql-boot.

the class SchemaJdbcResourceType method read.

@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
    try {
        final List<DbResource> result = new ArrayList<>();
        final ResultSet columns = dataSource.getConnection().getMetaData().getSchemas(null, uri.path(0));
        final ResultSetMetaData tableMetaData = columns.getMetaData();
        final int columnsCount = tableMetaData.getColumnCount();
        while (columns.next()) {
            final String schemaName = columnsCount >= 1 ? columns.getString(1) : null;
            final Map<String, Object> properties = new LinkedHashMap<>();
            properties.put("TABLE_SCHEM", columnsCount >= 1 ? columns.getString(1) : null);
            properties.put("TABLE_CATALOG", columnsCount >= 2 ? columns.getString(2) : null);
            result.add(new DbResourceImpl(schemaName, this, new DbUri(name(), asList(schemaName)), properties));
        }
        return result.stream();
    } catch (SQLException e) {
        throw new BootException(e);
    }
}
Also used : DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) DbResourceImpl(com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ResultSetMetaData(java.sql.ResultSetMetaData) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) ResultSet(java.sql.ResultSet) BootException(com.github.mgramin.sqlboot.exceptions.BootException)

Example 9 with DbUri

use of com.github.mgramin.sqlboot.model.uri.impl.DbUri in project sql-boot by sql-boot.

the class ProcedureJdbcResourceType method read.

@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
    try {
        final List<DbResource> result = new ArrayList<>();
        final ResultSet tables = dataSource.getConnection().getMetaData().getProcedures(null, uri.path(0), uri.path(1));
        final ResultSetMetaData tableMetaData = tables.getMetaData();
        final int columnsCount = tableMetaData.getColumnCount();
        while (tables.next()) {
            final String tableSchem = columnsCount >= 2 ? tables.getString(2) : null;
            final String procedureName = columnsCount >= 3 ? tables.getString(3) : null;
            final Map<String, Object> props = new LinkedHashMap<>();
            int i = 1;
            for (String s : properties.keySet()) {
                props.put(s, columnsCount >= i ? tables.getString(i++) : null);
            }
            result.add(new DbResourceImpl(procedureName, this, new DbUri(name(), asList(tableSchem, procedureName)), props));
        }
        return result.stream();
    } catch (SQLException e) {
        throw new BootException(e);
    }
}
Also used : DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) DbResourceImpl(com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ResultSetMetaData(java.sql.ResultSetMetaData) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) ResultSet(java.sql.ResultSet) BootException(com.github.mgramin.sqlboot.exceptions.BootException)

Example 10 with DbUri

use of com.github.mgramin.sqlboot.model.uri.impl.DbUri in project sql-boot by sql-boot.

the class ColumnJdbcResourceType method read.

@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
    try {
        final List<DbResource> result = new ArrayList<>();
        final ResultSet columns = dataSource.getConnection().getMetaData().getColumns(null, uri.path(0), uri.path(1), uri.path(2));
        final ResultSetMetaData tableMetaData = columns.getMetaData();
        final int columnsCount = tableMetaData.getColumnCount();
        while (columns.next()) {
            final String schemaName = columnsCount >= 2 ? columns.getString(2) : null;
            final String tableName = columnsCount >= 3 ? columns.getString(3) : null;
            final String columnName = columnsCount >= 4 ? columns.getString(4) : null;
            final Map<String, Object> props = new LinkedHashMap<>();
            int i = 1;
            for (String s : properties.keySet()) {
                props.put(s, columnsCount >= i ? columns.getString(i++) : null);
            }
            result.add(new DbResourceImpl(columnName, this, new DbUri(name(), asList(schemaName, tableName, columnName)), props));
        }
        return result.stream();
    } catch (SQLException e) {
        throw new BootException(e);
    }
}
Also used : DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) DbResourceImpl(com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ResultSetMetaData(java.sql.ResultSetMetaData) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) ResultSet(java.sql.ResultSet) BootException(com.github.mgramin.sqlboot.exceptions.BootException)

Aggregations

DbUri (com.github.mgramin.sqlboot.model.uri.impl.DbUri)33 DbResource (com.github.mgramin.sqlboot.model.resource.DbResource)25 Test (org.junit.Test)18 ResourceType (com.github.mgramin.sqlboot.model.resource_type.ResourceType)16 SqlPlaceholdersWrapper (com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper)13 BootException (com.github.mgramin.sqlboot.exceptions.BootException)12 DbResourceImpl (com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl)12 LinkedHashMap (java.util.LinkedHashMap)12 ResultSet (java.sql.ResultSet)11 ResultSetMetaData (java.sql.ResultSetMetaData)11 SQLException (java.sql.SQLException)11 ArrayList (java.util.ArrayList)11 TableJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.table.TableJdbcResourceType)5 Uri (com.github.mgramin.sqlboot.model.uri.Uri)4 FsResourceTypes (com.github.mgramin.sqlboot.model.resource_type.impl.composite.FsResourceTypes)2 WhereWrapper (com.github.mgramin.sqlboot.model.resource_type.wrappers.list.WhereWrapper)2 JdbcSqlQuery (com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery)2 GroovyTemplateGenerator (com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator)2 Connection (java.sql.Connection)2 Map (java.util.Map)2