Skip to content
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

V9 non course migration for accounts not migrating #12965

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import com.google.cloud.datastore.QueryResults;
import com.googlecode.objectify.cmd.Query;

import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;

// import jakarta.persistence.criteria.CriteriaDelete;

import teammates.client.connector.DatastoreClient;
Expand Down Expand Up @@ -126,6 +131,27 @@ private void doMigration(teammates.storage.entity.Account entity) {
* Migrates the entity.
*/
protected void migrateEntity(teammates.storage.entity.Account oldAccount) {
HibernateUtil.beginTransaction();

CriteriaBuilder cb = HibernateUtil.getCriteriaBuilder();
CriteriaQuery<teammates.storage.sqlentity.Account> cr = cb.createQuery(
teammates.storage.sqlentity.Account.class);
Root<teammates.storage.sqlentity.Account> root = cr.from(teammates.storage.sqlentity.Account.class);
cr.select(root).where(cb.equal(root.get("googleId"), oldAccount.getGoogleId()));

TypedQuery<teammates.storage.sqlentity.Account> query = HibernateUtil.createQuery(cr);


boolean isEntityInDb = query.getResultList().size() != 0;
HibernateUtil.commitTransaction();

// In db, but somehow not set as migrated.
if (isEntityInDb) {
oldAccount.setMigrated(true);
entitiesOldAccountSavingBuffer.add(oldAccount);
return;
};

teammates.storage.sqlentity.Account newAccount = new teammates.storage.sqlentity.Account(
oldAccount.getGoogleId(),
oldAccount.getName(),
Expand All @@ -136,7 +162,6 @@ protected void migrateEntity(teammates.storage.entity.Account oldAccount) {
oldAccount.setMigrated(true);
entitiesOldAccountSavingBuffer.add(oldAccount);
migrateReadNotification(oldAccount, newAccount);

}

private void migrateReadNotification(teammates.storage.entity.Account oldAccount,
Expand Down