Skip to content

Commit 6f6244d

Browse files
authored
Merge pull request #3 from hakan-agdere-sap/feature/additional-updates-1-1
Documentation update and a bugfix
2 parents 48c3d68 + 9a09d2e commit 6f6244d

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

commercedbsync/src/com/sap/cx/boosters/commercedbsync/processors/impl/IndexAlignerPostProcessor.java

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void process(final CopyContext context)
3737
final DataRepository dataTargetRepository = migrationContext.getDataTargetRepository();
3838
final String indiciesSQL = generateAlterTablesSql(migrationContext);
3939
indiciesSQL.lines().forEach(indexSQL -> {
40-
if(StringUtils.isNotBlank(indexSQL))
40+
if (StringUtils.isNotBlank(indexSQL))
4141
{
4242
LOG.info("Executing {}", indexSQL);
4343
try
@@ -56,37 +56,47 @@ public void process(final CopyContext context)
5656

5757
private String generateAlterTablesSql(final MigrationContext migrationContext)
5858
{
59-
final Database sourceDatabase = migrationContext.getDataSourceRepository().asDatabase();
60-
final DataRepository dataTargetRepository = migrationContext.getDataTargetRepository();
61-
final Database targetDatabase = dataTargetRepository.asDatabase();
62-
final Set<String> excludedIndices = getExcludedIndicies();
63-
64-
for (final String copiedTable : migrationContext.getIncludedTables())
59+
String alterTablesSql = "";
60+
try
6561
{
66-
final Table sourceTable = sourceDatabase.findTable(copiedTable);
67-
final Table targetTable = targetDatabase.findTable(copiedTable);
68-
if (sourceTable != null && targetTable != null)
62+
final Database sourceDatabase = migrationContext.getDataSourceRepository().asDatabase();
63+
final DataRepository dataTargetRepository = migrationContext.getDataTargetRepository();
64+
final Database targetDatabase = dataTargetRepository.asDatabase();
65+
final Set<String> excludedIndices = getExcludedIndicies();
66+
67+
for (final String copiedTable : migrationContext.getIncludedTables())
6968
{
70-
final Index[] sourceTableIndices = sourceTable.getIndices();
71-
final Index[] targetTableIndices = targetTable.getIndices();
72-
for (final Index sourceTableIndex : sourceTableIndices)
69+
final Table sourceTable = sourceDatabase.findTable(copiedTable);
70+
final Table targetTable = targetDatabase.findTable(copiedTable);
71+
if (sourceTable != null && targetTable != null)
7372
{
74-
if (!ArrayUtils.contains(targetTableIndices, sourceTableIndex)
75-
&& !excludedIndices.contains((sourceTable.getName() + "." + sourceTableIndex.getName()).toLowerCase()))
73+
final Index[] sourceTableIndices = sourceTable.getIndices();
74+
final Index[] targetTableIndices = targetTable.getIndices();
75+
for (final Index sourceTableIndex : sourceTableIndices)
7676
{
77-
LOG.debug("Found missing index {} for {}", sourceTableIndex, copiedTable);
78-
targetTable.addIndex(sourceTableIndex);
77+
if (!ArrayUtils.contains(targetTableIndices, sourceTableIndex)
78+
&& !excludedIndices.contains((sourceTable.getName() + "." + sourceTableIndex.getName()).toLowerCase()))
79+
{
80+
LOG.debug("Found missing index {} for {}", sourceTableIndex, copiedTable);
81+
targetTable.addIndex(sourceTableIndex);
82+
}
7983
}
8084
}
85+
else
86+
{
87+
LOG.warn("Table {} is not found one of the databases: source[{}], target[{}]", copiedTable, sourceTable,
88+
targetTable);
89+
}
8190
}
82-
else
83-
{
84-
LOG.warn("Table {} is not found one of the databases: source[{}], target[{}]", copiedTable, sourceTable, targetTable);
85-
}
91+
92+
alterTablesSql = dataTargetRepository.asPlatform().getAlterTablesSql(targetDatabase);
93+
LOG.debug("Generated alter table sql for missing indexes: {}", alterTablesSql);
94+
}
95+
catch (final Exception e)
96+
{
97+
LOG.error("Alter table generation failed", e);
8698
}
8799

88-
final String alterTablesSql = dataTargetRepository.asPlatform().getAlterTablesSql(targetDatabase);
89-
LOG.debug("Generated alter table sql for missing indexes: {}", alterTablesSql);
90100
return alterTablesSql;
91101
}
92102

docs/configuration/CONFIGURATION-GUIDE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ For example with media filtered just for the images folder is possible to achiev
7474
migration.data.view.t.medias.enabled=true # enable view generation
7575
# If you are joining more than one tables in the where clause then use a columnPrefix label
7676
migration.data.view.t.medias.columnPrefix=item_t1
77-
# name `v_medias` is generated due to default name pattern value v_%s. No need to configure
78-
migration.data.view.t.medias.joinWhereClause=FROM medias item_t1 JOIN mediafolders item_t2 ON item_t1.p_folder = item_t2.PK WHERE (item_t2.p_qualifier like 'images')
77+
# The joinWhereClause is used within view definition. i.e. CREATE VIEW v_media AS SELECT * FROM {joinWhereClause}
78+
# name `v_medias` is generated due to default name pattern value v_%s as the view name so no need to configure it for joinWhereClause
79+
migration.data.view.t.medias.joinWhereClause=medias item_t1 JOIN mediafolders item_t2 ON item_t1.p_folder = item_t2.PK WHERE (item_t2.p_qualifier like 'images')
7980
```
8081

8182
Output for that will be like this:

0 commit comments

Comments
 (0)