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,7 +256,9 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
options, new ByteArrayInputStream(component.googleCredentialJson().getBytes(UTF_8))); options, new ByteArrayInputStream(component.googleCredentialJson().getBytes(UTF_8)));
} }
installer.install(options); 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. // Ensure that all entity classes are loaded before command code runs.
ObjectifyService.initOfy(); ObjectifyService.initOfy();
@ -267,10 +269,12 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
// Enable Cloud SQL for command that needs remote API as they will very likely use // 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 // Cloud SQL after the database migration. Note that the DB password is stored in Datastore
// and it is already initialized above. // and it is already initialized above.
TransactionManagerFactory.setJpaTm(() -> component.nomulusToolJpaTransactionManager().get()); TransactionManagerFactory.setJpaTm(
() -> component.nomulusToolJpaTransactionManager().get());
TransactionManagerFactory.setReplicaJpaTm( TransactionManagerFactory.setReplicaJpaTm(
() -> component.nomulusToolReplicaJpaTransactionManager().get()); () -> component.nomulusToolReplicaJpaTransactionManager().get());
} }
}
command.run(); command.run();
} }