Created
September 11, 2012 12:54
-
-
Save nshaw/3698233 to your computer and use it in GitHub Desktop.
Fix ServiceComponentLocalServiceImpl handling of indexes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomServiceComponentLocalServiceImpl extends | |
ServiceComponentLocalServiceImpl { | |
@Override | |
public void upgradeDB( | |
ClassLoader classLoader, String buildNamespace, long buildNumber, | |
boolean buildAutoUpgrade, ServiceComponent previousServiceComponent, | |
String tablesSQL, String sequencesSQL, String indexesSQL) | |
throws Exception { | |
DB db = DBFactoryUtil.getDB(); | |
if (previousServiceComponent == null) { | |
if (_log.isInfoEnabled()) { | |
_log.info("Running " + buildNamespace + " SQL scripts"); | |
} | |
db.runSQLTemplateString(tablesSQL, true, false); | |
db.runSQLTemplateString(sequencesSQL, true, false); | |
db.runSQLTemplateString(indexesSQL, true, false); | |
} | |
else if (buildAutoUpgrade) { | |
if (_log.isInfoEnabled()) { | |
_log.info( | |
"Upgrading " + buildNamespace + | |
" database to build number " + buildNumber); | |
} | |
if (!tablesSQL.equals(previousServiceComponent.getTablesSQL())) { | |
if (_log.isInfoEnabled()) { | |
_log.info("Upgrading database with tables.sql"); | |
} | |
db.runSQLTemplateString(tablesSQL, true, false); | |
upgradeModels(classLoader); | |
} | |
if (!sequencesSQL.equals( | |
previousServiceComponent.getSequencesSQL())) { | |
if (_log.isInfoEnabled()) { | |
_log.info("Upgrading database with sequences.sql"); | |
} | |
db.runSQLTemplateString(sequencesSQL, true, false); | |
} | |
// CUSTOM begin | |
// run indexes.sql, if tables were upgraded, since all indexes are | |
// dropped during upgrade and are never recreated | |
if (!indexesSQL.equals(previousServiceComponent.getIndexesSQL()) | |
|| !tablesSQL.equals(previousServiceComponent.getTablesSQL())) { | |
// CUSTOM end | |
if (_log.isInfoEnabled()) { | |
_log.info("Upgrading database with indexes.sql"); | |
} | |
db.runSQLTemplateString(indexesSQL, true, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment