Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/dialects_in…
Browse files Browse the repository at this point in the history
…_sub_folders
  • Loading branch information
janblok committed Dec 6, 2024
2 parents bfdc47e + c69166e commit ceb53bd
Show file tree
Hide file tree
Showing 247 changed files with 3,933 additions and 3,496 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,19 @@ deliver context-aware, reasoning applications without any vendor lock-in. :bulb:

# Stable Releases

| Release | Download/Docker Pull |
|----------------------|-----------------------------------------------------------------------------------|
| 1.4.0 | [DB2Rest-1.4.0](https://repo1.maven.org/maven2/io/9tiger/db2rest/1.4.0/db2rest-1.4.0.jar) |
| Oracle9i - 1.2.3 | [DB2Rest-Oracle9i-1.2.3](https://download.db2rest.com/db2rest-oracle9i-1.2.3.jar) |
| 1.4.0 (Docker Image) | ` docker pull kdhrubo/db2rest:v1.4.0 ` or ` docker pull kdhrubo/db2rest:latest ` |
| Release | Download/Docker Pull |
|-------------------------------------|-----------------------------------------------------------------------------------|
| 1.4.1 | [DB2Rest-1.4.1](https://download.db2rest.com/db2rest-1.4.1.jar) |
| 1.4.1 (Docker Image) | ` docker pull kdhrubo/db2rest:v1.4.1 ` or ` docker pull kdhrubo/db2rest:latest ` |
| Oracle9i - 1.2.3 <mark>Final</mark> | [DB2Rest-Oracle9i-1.2.3](https://download.db2rest.com/db2rest-oracle9i-1.2.3.jar) |


# Quick start guides

[On premise / On Virtual Machines installation guide](https://db2rest.com/docs/intro).

[Docker based installation guide](https://db2rest.com/docs/run-db2rest-on-docker).

# Building
Use `mvn verify` or `mvn clean package` , etc. from repo root folder, and pass in a value for `revision` to override the current default version in POMs:
`mvn -Drevision="1.5.4-SNAPSHOT" clean package -DskipTests`

# Testing
Running tests simply requires a Docker daemon running, where the build will automatically pull and run testcontainers for the database tests.

# Use Cases

Expand Down Expand Up @@ -100,6 +95,14 @@ Feel like contributing? That's awesome! We have a [contributing guide](https://g

Our docsite lives in a [separate repo](https://github.com/9tigerio/db2rest-web). If you're interested in contributing to the documentation, check out the docsite contribution guide.

# Building
Use `mvn verify` or `mvn clean package` , etc. from repo root folder, and pass in a value for `revision` to override the current default version in POMs:
`mvn -Drevision="1.5.4-SNAPSHOT" clean package -DskipTests`

# Testing
Running tests simply requires a Docker daemon running, where the build will automatically pull and run testcontainers for the database tests.


# Support

*Connect on Discord*
Expand All @@ -118,3 +121,5 @@ Refer to [open roadmap](https://db2rest.com/roadmap/) items.
# IDE Sponsor

![JetBrains logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)


26 changes: 26 additions & 0 deletions api-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
<version>2.2.1</version>
</dependency>

<dependency>
<groupId>com.hubspot.jinjava</groupId>
<artifactId>jinjava</artifactId>
<version>2.7.3</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
Expand Down Expand Up @@ -218,6 +224,26 @@
</resource>
</resources>
<plugins>

<plugin>
<groupId>gg.jte</groupId>
<artifactId>jte-maven-plugin</artifactId>
<version>${jte.version}</version>
<configuration>
<!-- This is the directory where your .jte files are located. -->
<sourceDirectory>${project.basedir}/src/main/resources/sql-templates</sourceDirectory>
<contentType>Plain</contentType>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,55 @@

import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;


@Slf4j
@Component
public class DatabaseContextRequestInterceptor implements AsyncHandlerInterceptor {

private final List<String> WHITE_LIST = List.of(
"/swagger-ui/**", "/v3/api-docs/**", "/actuator/**",
VERSION + "/$dbs");
private final List<String> whiteList = List.of(
"/swagger-ui/**", "/v3/api-docs/**", "/actuator/**",
VERSION + "/$dbs");

private final AntPathMatcher antPathMatcher = new AntPathMatcher();
private final AntPathMatcher antPathMatcher = new AntPathMatcher();

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
log.debug("Pre handle - {}", request.getRequestURI());
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
log.debug("Pre handle - {}", request.getRequestURI());

if(!isWhileListed(request.getRequestURI())) {
final Map<String, String> pathVariables = (Map<String, String>) request
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
if (!isWhileListed(request.getRequestURI())) {
final Map<String, String> pathVariables = (Map<String, String>) request
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

log.debug("pathVariables - {}", pathVariables);
log.debug("pathVariables - {}", pathVariables);

if(Objects.isNull(pathVariables)) throw new GenericDataAccessException("Database ID not found.");
if (Objects.isNull(pathVariables)) {
throw new GenericDataAccessException("Database ID not found.");
}

String dbId = pathVariables.get("dbId");
String dbId = pathVariables.get("dbId");

log.debug("Db identifier : {}", dbId);
log.debug("Db identifier : {}", dbId);

if(StringUtils.isNotBlank(dbId)) {
this.setTenantContext(dbId);
}
else{
log.info("DB could not be determined.");
throw new GenericDataAccessException("Database ID not found.");
}
}
if (StringUtils.isNotBlank(dbId)) {
this.setTenantContext(dbId);
} else {
log.info("DB could not be determined.");
throw new GenericDataAccessException("Database ID not found.");
}
}

return true;
}
return true;
}

private boolean isWhileListed(String uri) {
return WHITE_LIST.stream().anyMatch(w -> antPathMatcher.match(w, uri));
return whiteList.stream().anyMatch(w -> antPathMatcher.match(w, uri));
}

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
DatabaseContextHolder.clear();
}
private void setTenantContext(String tenant) {
DatabaseContextHolder.setCurrentDbId(tenant);
}
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
DatabaseContextHolder.clear();
}

private void setTenantContext(String tenant) {
DatabaseContextHolder.setCurrentDbId(tenant);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Slf4j
@Configuration
@RequiredArgsConstructor
public class JdbcConfiguration {


private final DatabaseProperties databaseProperties;
private final ObjectMapper objectMapper;


@Bean
@ConditionalOnMissingBean(DataSource.class)
public DataSource dataSource() {
Expand All @@ -78,15 +75,15 @@ private Map<Object, Object> buildDataSources() {

log.debug("Databases - {}", databaseProperties.getDatabases());

if(!databaseProperties.isRdbmsConfigured()) {
if (!databaseProperties.isRdbmsConfigured()) {
log.info("*** No RDBMS configured.");
return result;
}


for (DatabaseConnectionDetail connectionDetail : databaseProperties.getDatabases()) {

if(connectionDetail.isJdbcPresent())
if (connectionDetail.isJdbcPresent())
result.put(connectionDetail.id(), this.buildDataSource(connectionDetail));
}

Expand Down Expand Up @@ -133,8 +130,9 @@ public SqlCreatorTemplate sqlCreatorTemplate(TemplateEngine templateEngine, Jdbc
@Bean
public TemplateEngine templateEngine() {
CodeResolver codeResolver =
new ResourceCodeResolver("sql-templates", this.getClass().getClassLoader());
return TemplateEngine.create(codeResolver, ContentType.Plain);
new ResourceCodeResolver("sql-templates");
return TemplateEngine
.createPrecompiled(ContentType.Plain);
}

@Bean
Expand Down Expand Up @@ -227,7 +225,7 @@ public ExistsQueryService existsQueryService(
SqlCreatorTemplate sqlCreatorTemplate,
List<ReadProcessor> processorList,
DbOperationService dbOperationService) {
return new JdbcExistsQueryService(jdbcManager,dbOperationService, processorList, sqlCreatorTemplate);
return new JdbcExistsQueryService(jdbcManager, dbOperationService, processorList, sqlCreatorTemplate);
}

@Bean
Expand All @@ -236,7 +234,7 @@ public FindOneService findOneService(
SqlCreatorTemplate sqlCreatorTemplate,
List<ReadProcessor> processorList,
DbOperationService dbOperationService) {
return new JdbcFindOneService(jdbcManager,sqlCreatorTemplate, processorList, dbOperationService);
return new JdbcFindOneService(jdbcManager, sqlCreatorTemplate, processorList, dbOperationService);
}

@Bean
Expand Down Expand Up @@ -336,7 +334,7 @@ public FindOneController findOneController(FindOneService findOneService) {

@Bean
@ConditionalOnBean(ReadService.class)
public ReadController readController(ReadService readService, Db2RestConfigProperties configProperties) {
public ReadController readController(ReadService readService, Db2RestConfigProperties configProperties) {
return new ReadController(readService, configProperties);
}

Expand Down Expand Up @@ -381,7 +379,7 @@ public SQLTemplateController sqlTemplateController(
) {
return new SQLTemplateController(sqlTemplateExecutorService);
}

@ConditionalOnBean(JdbcManager.class)
public DbInfoController dbInfoController(JdbcManager jdbcManager) {
return new DbInfoController(jdbcManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.hubspot.jinjava.tree.parse.DefaultTokenScannerSymbols;

public class DisabledExpressionTokenScannerSymbols extends DefaultTokenScannerSymbols {
@Override
public int getExprStart() {
return 0;
}
@Override
public int getExprStart() {
return 0;
}

@Override
public int getExprEnd() {
return 0;
}
@Override
public int getExprEnd() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import com.homihq.db2rest.core.dto.CreateResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.homihq.db2rest.jdbc.rest.create;


import com.homihq.db2rest.jdbc.core.service.CreateService;
import com.homihq.db2rest.core.dto.CreateResponse;
import com.homihq.db2rest.jdbc.core.service.CreateService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -19,12 +19,13 @@ public class CreateController implements CreateRestApi {

@Override
public CreateResponse save(
String dbId, String schemaName,
String tableName,
List<String> includeColumns,
List<String> sequences,
Map<String, Object> data,
boolean tsIdEnabled) {
String dbId, String schemaName,
String tableName,
List<String> includeColumns,
List<String> sequences,
Map<String, Object> data,
boolean tsIdEnabled
) {

return createService
.save(dbId, schemaName, tableName, includeColumns, data, tsIdEnabled, sequences);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.homihq.db2rest.jdbc.rest.create;

import com.homihq.db2rest.core.dto.CreateResponse;
import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.List;
import java.util.Map;

import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;

public interface CreateRestApi {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping(VERSION + "/{dbId}/{tableName}")
CreateResponse save(@PathVariable String dbId,
@RequestHeader(name="Content-Profile", required = false) String schemaName,
@RequestHeader(name = "Content-Profile", required = false) String schemaName,
@PathVariable String tableName,
@RequestParam(name = "columns", required = false) List<String> includeColumns,
@RequestParam(name = "sequences", required = false) List<String> sequences,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.homihq.db2rest.jdbc.rest.delete;

import com.homihq.db2rest.config.Db2RestConfigProperties;
import com.homihq.db2rest.jdbc.core.service.DeleteService;
import com.homihq.db2rest.core.dto.DeleteResponse;
import com.homihq.db2rest.jdbc.core.service.DeleteService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
Expand All @@ -20,7 +20,8 @@ public DeleteResponse delete(
String dbId,
String schemaName,
String tableName,
String filter) {
String filter
) {

db2RestConfigProperties.checkDeleteAllowed(filter);

Expand Down
Loading

0 comments on commit ceb53bd

Please sign in to comment.