nhl / link-move

A model-driven dynamically-configurable framework to acquire data from external sources and save it to your database.
Apache License 2.0
35 stars 15 forks source link

match by crypto doesn't work #156

Open vitalz opened 6 years ago

vitalz commented 6 years ago

Database SQL:

`CRYPTO_source_id` VARBINARY(64) NOT NULL,

Cayenne model:

<db-attribute name="CRYPTO_source_id" type="VARBINARY" isMandatory="true" length="64"/>

<obj-attribute name="sourceId" type="int" db-attribute-path="CRYPTO_source_id"/>

LinkMove match by:

.matchBy(SomeEntity.SOURCE, SomeEntity.SOURCE_ID)

There is Source ID is being encrypted column.

During targets being matched to sources process, at TargetMatcher.match(ObjectContext, Map<Object, Map<String, Object>>) no targets are being obtained:

[17/Aug/2018:05:14:26,432] bootique-job-1  INFO  o.a.c.l.JdbcEventLogger: SELECT t0.source, t0.CRYPTO_source_id /* some more fields */ FROM my_schema.some_entity t0 WHERE (t0.source = ?) AND (t0.CRYPTO_source_id = ?) [bind: 1->source:'cdn', 2->CRYPTO_source_id:1]
[17/Aug/2018:05:14:26,480] bootique-job-1  INFO  o.a.c.l.JdbcEventLogger: === returned 0 rows. - took 537 ms.

Though the according target is existing LinkMove will produce a duplicate.

vitalz commented 6 years ago

There is a workaround to implement your custom Mapper and it will match (pre-selected in memory) targets for incoming sources at @AfterTargetsMatched.

 .matchBy(new CustomMapper())
ObjectSelect.query(Custom.class).select(
    segment.getContext()
)

There is an idea that:

mapper.keyForTarget(customObj) === mapper.keyForSource(incomingSource)
@AfterTargetsMatched
public void AfterTargetsMatched(Execution exec, CreateOrUpdateSegment<Custom> segment) {
        // some code
    segment.setMatchedTargets(customTargets);
}