-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement backend data field filter for H2 & Postgresql (similar to MongoDB) #3516
Changes from 7 commits
ff0854c
edf501a
07ff350
db5ddf6
d4e0c22
fd152b9
46edc02
c4255a5
a77cff4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
countDevicesOfTenantWithFilter: | | ||
SELECT COUNT(*) AS deviceCount FROM %1$s | ||
WHERE | ||
tenant_id=:tenant_id | ||
AND | ||
LOCATE(CONCAT_WS(':', :field, REPLACE(:value, '"')), REPLACE(data, '"')) | ||
OR | ||
REPLACE(data, '"') LIKE CONCAT('%%', :field, ':', REPLACE(:value, '"')) | ||
|
||
|
||
findDevicesOfTenantWithFilter: | | ||
SELECT * | ||
FROM %s | ||
WHERE | ||
tenant_id=:tenant_id | ||
AND | ||
LOCATE(CONCAT_WS(':', :field, REPLACE(:value, '"')), REPLACE(data, '"')) | ||
OR | ||
REPLACE(data, '"') LIKE CONCAT('%%', :field, ':', REPLACE(:value, '"')) | ||
ORDER BY device_id ASC | ||
LIMIT :page_size | ||
OFFSET :page_offset |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ protected Future<OperationResult<Id>> processCreateDevice(final DeviceKey key, f | |
Optional.of(r.getVersion())) | ||
) | ||
|
||
.recover(e -> Services.recover(e)); | ||
.recover(Services::recover); | ||
|
||
} | ||
|
||
|
@@ -112,7 +112,7 @@ protected Future<OperationResult<Id>> processUpdateDevice(final DeviceKey key, f | |
Optional.empty(), | ||
Optional.of(r.getVersion()))) | ||
|
||
.recover(e -> Services.recover(e)); | ||
.recover(Services::recover); | ||
|
||
} | ||
|
||
|
@@ -131,7 +131,7 @@ protected Future<Result<Void>> processDeleteDevice(final DeviceKey key, final Op | |
return Result.<Void>from(HttpURLConnection.HTTP_NO_CONTENT); | ||
} | ||
}) | ||
.recover(e -> Services.recover(e)); | ||
.recover(Services::recover); | ||
|
||
} | ||
|
||
|
@@ -141,7 +141,7 @@ protected Future<Result<Void>> processDeleteDevicesOfTenant(final String tenantI | |
return this.store | ||
.dropTenant(tenantId, span.context()) | ||
.map(r -> Result.<Void>from(HttpURLConnection.HTTP_NO_CONTENT)) | ||
.recover(e -> Services.recover(e)); | ||
.recover(Services::recover); | ||
} | ||
|
||
@Override | ||
|
@@ -151,22 +151,22 @@ protected String generateDeviceId(final String tenantId) { | |
|
||
@Override | ||
protected Future<OperationResult<SearchResult<DeviceWithId>>> processSearchDevices( | ||
final String tenantId, | ||
final int pageSize, | ||
final int pageOffset, | ||
final List<Filter> filters, | ||
final List<Sort> sortOptions, | ||
final Span span) { | ||
final String tenantId, | ||
final int pageSize, | ||
final int pageOffset, | ||
final List<Filter> filters, | ||
final List<Sort> sortOptions, | ||
final Span span) { | ||
|
||
Objects.requireNonNull(tenantId); | ||
Objects.requireNonNull(span); | ||
|
||
return store.findDevices(tenantId, pageSize, pageOffset, span.context()) | ||
.map(result -> OperationResult.ok( | ||
HttpURLConnection.HTTP_OK, | ||
result, | ||
Optional.empty(), | ||
Optional.empty())) | ||
.recover(e -> Services.recover(e)); | ||
return store.findDevices(tenantId, pageSize, pageOffset, filters, span.context()) | ||
.map(result -> OperationResult.ok( | ||
HttpURLConnection.HTTP_OK, | ||
result, | ||
Optional.empty(), | ||
Optional.empty())) | ||
.recover(Services::recover); | ||
Comment on lines
+154
to
+170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this additional indentation due to Hono's formatter configuration in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,8 +76,8 @@ enum DatabaseType { | |
} | ||
protected static final Span SPAN = NoopSpan.INSTANCE; | ||
|
||
private static final DatabaseType DEFAULT_DATABASE_TYPE = DatabaseType.H2; | ||
private static final DatabaseType DATABASE_TYPE = DatabaseType.valueOf(System.getProperty(AbstractJdbcRegistryTest.class.getSimpleName() | ||
protected static DatabaseType DEFAULT_DATABASE_TYPE = DatabaseType.H2; | ||
protected static DatabaseType DATABASE_TYPE = DatabaseType.valueOf(System.getProperty(AbstractJdbcRegistryTest.class.getSimpleName() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like these changes can be reverted as well now, can't they? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, i change it back to private final |
||
+ ".databaseType", DEFAULT_DATABASE_TYPE.name()).toUpperCase()); | ||
private static final Map<DatabaseType, JdbcDatabaseContainer<?>> DATABASE_CONTAINER_CACHE = new ConcurrentHashMap<>(); | ||
private static final String POSTGRESQL_IMAGE_NAME = System.getProperty(AbstractJdbcRegistryTest.class.getSimpleName() | ||
|
@@ -86,7 +86,7 @@ enum DatabaseType { | |
private static final AtomicLong UNIQUE_ID_GENERATOR = new AtomicLong(System.currentTimeMillis()); | ||
|
||
private static final Tracer TRACER = NoopTracerFactory.create(); | ||
private static final Path EXAMPLE_SQL_BASE = Path.of("..", "base-jdbc", "src", "main", "resources", "sql", DATABASE_TYPE.name().toLowerCase()); | ||
protected static Path EXAMPLE_SQL_BASE = Path.of("..", "base-jdbc", "src", "main", "resources", "sql", DATABASE_TYPE.name().toLowerCase()); | ||
|
||
private static final Path BASE_DIR = Path.of("target").toAbsolutePath(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 👍