Search in sources :

Example 26 with DbUri

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

the class FkJdbcResourceTypeTest method read.

@Test
public void read() {
    final ResourceType fk = new FkJdbcResourceType(dataSource);
    final Stream<DbResource> foreignKeys = fk.read(new SqlPlaceholdersWrapper(new DbUri("fk", asList("*"))));
    assertEquals(1, foreignKeys.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 27 with DbUri

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

the class ChildTableJdbcResourceTypeTest method read.

@Test
public void read() {
    final ResourceType pk = new ChildTableJdbcResourceType(dataSource);
    final Stream<DbResource> primaryKeys = pk.read(new SqlPlaceholdersWrapper(new DbUri("child_table", asList("*"))));
    assertEquals(1, primaryKeys.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 28 with DbUri

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

the class SqlResourceTypeTest method read2.

@Test
public void read2() {
    final String sql = "select * from (select table_schema as \"@table_schema\", table_name as \"@table_name\", column_name as \"@column_name\"" + "from information_schema.columns)";
    ResourceType type = new WhereWrapper(new SqlResourceType(new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator(sql)), asList("column")));
    assertEquals(8, type.read(new DbUri("column/main_schema.users")).count());
}
Also used : DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) JdbcSqlQuery(com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) GroovyTemplateGenerator(com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator) WhereWrapper(com.github.mgramin.sqlboot.model.resource_type.wrappers.list.WhereWrapper) Test(org.junit.Test)

Example 29 with DbUri

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

the class SqlResourceTypeTest method read.

@Test
public void read() throws Exception {
    final String sql = "select * from (select table_schema as \"@table_schema\", table_name as \"@table_name\" " + "from information_schema.tables)";
    final ResourceType type = new WhereWrapper(new SqlResourceType(new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator(sql)), asList("table")));
    assertEquals(3, type.read(new DbUri("table/m.column")).count());
}
Also used : DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) JdbcSqlQuery(com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) GroovyTemplateGenerator(com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator) WhereWrapper(com.github.mgramin.sqlboot.model.resource_type.wrappers.list.WhereWrapper) Test(org.junit.Test)

Example 30 with DbUri

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

the class DbUriTest method test.

private void test(String uriString, String jsonExpected) throws BootException {
    Uri uri = new DbUri(uriString);
    assertEquals(uriString, uri.toString());
    assertEquals(new JsonWrapper(new DbUri(uriString)).toString(), jsonExpected);
}
Also used : DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) JsonWrapper(com.github.mgramin.sqlboot.model.uri.wrappers.JsonWrapper) Uri(com.github.mgramin.sqlboot.model.uri.Uri) DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri)

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