Skip to content

Commit

Permalink
how to use the library as a simple sql query catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Jul 10, 2024
1 parent e3ad245 commit c0003d8
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- README Chapter explaining how to use the library as a simple sql query catalog.

### Changed

- fj-version set to 8.6.2
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,29 @@ XLS/XLSX Formats needs *Apache POI* dependency, which is *NOT* automatically inc
<version>${poi-version}</version>
</dependency>
```

### 3.0 Usage As SQL Catalog

Create the xml catalog :

```xml
<query-catalog-config bean-mode="bean-xml-full">

<query-catalog id="sample-catalog-alt">
<query id="Q001ALT" outputFormat="csv" csvSeparator=";" outputFile="target/catalog_test_001.csv">
<sql>SELECT * FROM test_export</sql>
</query>
</query-catalog>

</query-catalog-config>
```

Access the catalog :

```java
QueryConfigCatalog catalog = QueryConfigCatalog.loadQueryConfigCatalogSafe("cl://sample/query-catalog-sample-alt.xml");
QueryConfig queryConfig = catalog.getListMap( "sample-catalog-alt" ).get( "Q001ALT" );
logger.info( "query config : {}, sql : {}", queryConfig, queryConfig.getSql() );
```

A full example is available in the [JUNIT](src/test/java/test/org/fugerit/java/query/export/tool/TestCatalogAlt.java) .
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package test.org.fugerit.java.query.export.tool;

import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.util.collection.ListMapStringKey;
import org.fugerit.java.query.export.catalog.QueryConfig;
import org.fugerit.java.query.export.catalog.QueryConfigCatalog;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

public class TestCatalogAlt extends TestBase {

@Test
public void testCatalogAlt() throws IOException, SQLException {
QueryConfigCatalog catalog = QueryConfigCatalog.loadQueryConfigCatalogSafe("cl://sample/query-catalog-sample-alt.xml");
QueryConfig queryConfig = catalog.getListMap( "sample-catalog-alt" ).get( "Q001ALT" );
logger.info( "query config : {}, sql : {}", queryConfig, queryConfig.getSql() );
Assert.assertEquals( "SELECT * FROM test_export", queryConfig.getSql() );
}

}
9 changes: 9 additions & 0 deletions src/test/resources/sample/query-catalog-sample-alt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<query-catalog-config bean-mode="bean-xml-full">

<query-catalog id="sample-catalog-alt">
<query id="Q001ALT" outputFormat="csv" csvSeparator=";" outputFile="target/catalog_test_001.csv">
<sql>SELECT * FROM test_export</sql>
</query>
</query-catalog>

</query-catalog-config>

0 comments on commit c0003d8

Please sign in to comment.