dengzhhu653 commented on code in PR #4194:
URL: https://github.com/apache/hive/pull/4194#discussion_r1171273793
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java:
##########
@@ -5665,6 +5678,212 @@ private String getGuidFromDB() throws MetaException {
return null;
}
+ @Override
+ public boolean runInTransaction(Runnable exec) throws MetaException {
+ boolean success = false;
+ Transaction tx = null;
+ try {
+ if (openTransaction()) {
+ exec.run();
+ success = commitTransaction();
+ }
+ } catch (Exception e) {
+ LOG.warn("Metastore operation failed", e);
+ } finally {
+ rollbackAndCleanup(success, null);
+ }
+ return success;
+ }
+
+ @Override
+ public boolean dropProperties(String key) throws MetaException {
+ boolean success = false;
+ Transaction tx = null;
+ Query query = null;
+ try {
+ if (openTransaction()) {
+ query = pm.newQuery(MMetastoreDBProperties.class, "this.propertyKey ==
key");
+ query.declareParameters("java.lang.String key");
+ Collection<MMetastoreDBProperties> properties =
(Collection<MMetastoreDBProperties>) query.execute(key);
+ if (!properties.isEmpty()) {
+ pm.deletePersistentAll(properties);
+ }
+ success = commitTransaction();
+ }
+ } catch (Exception e) {
+ LOG.warn("Metastore property drop failed", e);
+ } finally {
+ rollbackAndCleanup(success, query);
+ }
+ return success;
+ }
+
+ @Override
+ public MMetastoreDBProperties putProperties(String key, String value, String
description, byte[] content) throws MetaException {
+ boolean success = false;
+ try {
+ if (openTransaction()) {
+ //pm.currentTransaction().setOptimistic(false);
+ // fetch first to determine new vs update
+ MMetastoreDBProperties properties = doGetProperties(key, null);
+ final boolean newInstance;
+ if (properties == null) {
+ newInstance = true;
+ properties = new MMetastoreDBProperties();
+ properties.setPropertykey(key);
+ } else {
+ newInstance = false;
+ }
+ properties.setDescription(description);
+ properties.setPropertyValue(value);
+ properties.setPropertyContent(content);
+ LOG.debug("Attempting to add property {} for the metastore db", key);
+ properties.setDescription("Metastore property "
+ + (newInstance ? "created" : "updated")
+ + " " +
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd
HH:mm:ss.SSS")));
+ if (newInstance) {
+ pm.makePersistent(properties);
+ }
+ success = commitTransaction();
+ if (success) {
+ LOG.info("Metastore property {} created successfully", key);
+ return properties;
+ }
+ }
+ } catch (Exception e) {
+ LOG.warn("Metastore property save failed", e);
+ } finally {
+ rollbackAndCleanup(success, null);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean renameProperties(String mapKey, String newKey) throws
MetaException {
+ boolean success = false;
+ Transaction tx = null;
+ Query query = null;
Review Comment:
there is a `QueryWrapper` that can wrap the Query, it makes
try-with-resources easy to use for `Query`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]