-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4016 from PenghaiZhang/bugfix/escape-keyword-coun…
…t-for-oracle fix: create data migration 'RenameViewCount' to rename column "count" for Oracle
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
78 changes: 78 additions & 0 deletions
78
.../Core/com.equella.core/src/com/tle/core/institution/migration/v20221/RenameViewCount.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to The Apereo Foundation under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* The Apereo Foundation licenses this file to you under the Apache License, | ||
* Version 2.0, (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.tle.core.institution.migration.v20221; | ||
|
||
import com.google.inject.Singleton; | ||
import com.tle.core.guice.Bind; | ||
import com.tle.core.hibernate.impl.HibernateMigrationHelper; | ||
import com.tle.core.migration.AbstractHibernateSchemaMigration; | ||
import com.tle.core.migration.MigrationInfo; | ||
import com.tle.core.migration.MigrationResult; | ||
import java.util.List; | ||
import org.hibernate.Session; | ||
import org.hibernate.dialect.Oracle9iDialect; | ||
|
||
/** | ||
* This migration renames the 'count' column in the viewcount_* tables on Oracle. This was required | ||
* due to some odd naming which resulted from the original implementation with SimpleDBA. The new | ||
* naming aligns with conventional Oracle usage as well as Hibernate defaults. | ||
*/ | ||
@Bind | ||
@Singleton | ||
public class RenameViewCount extends AbstractHibernateSchemaMigration { | ||
|
||
@Override | ||
protected void executeDataMigration( | ||
HibernateMigrationHelper helper, MigrationResult result, Session session) throws Exception { | ||
// Only rename the column for when using ExtendedOracle10gDialect or ExtendedOracle9iDialect. | ||
if (helper.getExtDialect() instanceof Oracle9iDialect) { | ||
session | ||
.createNativeQuery("alter table viewcount_item rename column \"count\" to COUNT") | ||
.executeUpdate(); | ||
session | ||
.createNativeQuery("alter table viewcount_attachment rename column \"count\" to COUNT") | ||
.executeUpdate(); | ||
} | ||
} | ||
|
||
@Override | ||
protected int countDataMigrations(HibernateMigrationHelper helper, Session session) { | ||
return 1; | ||
} | ||
|
||
@Override | ||
protected List<String> getDropModifySql(HibernateMigrationHelper helper) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected List<String> getAddSql(HibernateMigrationHelper helper) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getDomainClasses() { | ||
return new Class<?>[] {}; | ||
} | ||
|
||
@Override | ||
public MigrationInfo createMigrationInfo() { | ||
return new MigrationInfo("com.tle.core.entity.services.migration.v20221.rename.view.count"); | ||
} | ||
} |