In shell mode, only do database setup once (#1686)

We were initializing ofy and JPA every time the command was run, causing shell
commands to break after 64 transactions.
This commit is contained in:
Michael Muller 2022-06-28 09:27:39 -04:00 committed by GitHub
parent 63e4f4f10a
commit eb1b283ba3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -256,20 +256,24 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
options, new ByteArrayInputStream(component.googleCredentialJson().getBytes(UTF_8)));
}
installer.install(options);
// Database setup -- we also only ever do this if "installer" is null, just so that it's
// only done once.
// Ensure that all entity classes are loaded before command code runs.
ObjectifyService.initOfy();
// Make sure we start the command with a clean cache, so that any previous command won't
// interfere with this one.
ofyTm().clearSessionCache();
// Enable Cloud SQL for command that needs remote API as they will very likely use
// Cloud SQL after the database migration. Note that the DB password is stored in Datastore
// and it is already initialized above.
TransactionManagerFactory.setJpaTm(
() -> component.nomulusToolJpaTransactionManager().get());
TransactionManagerFactory.setReplicaJpaTm(
() -> component.nomulusToolReplicaJpaTransactionManager().get());
}
// Ensure that all entity classes are loaded before command code runs.
ObjectifyService.initOfy();
// Make sure we start the command with a clean cache, so that any previous command won't
// interfere with this one.
ofyTm().clearSessionCache();
// Enable Cloud SQL for command that needs remote API as they will very likely use
// Cloud SQL after the database migration. Note that the DB password is stored in Datastore
// and it is already initialized above.
TransactionManagerFactory.setJpaTm(() -> component.nomulusToolJpaTransactionManager().get());
TransactionManagerFactory.setReplicaJpaTm(
() -> component.nomulusToolReplicaJpaTransactionManager().get());
}
command.run();