[ 
https://issues.apache.org/jira/browse/GOBBLIN-1697?focusedWorklogId=808414&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-808414
 ]

ASF GitHub Bot logged work on GOBBLIN-1697:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Sep/22 18:58
            Start Date: 13/Sep/22 18:58
    Worklog Time Spent: 10m 
      Work Description: ZihanLi58 commented on code in PR #3549:
URL: https://github.com/apache/gobblin/pull/3549#discussion_r969984910


##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/spec_store/MysqlSpecStoreWithUpdate.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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 org.apache.gobblin.runtime.spec_store;
+
+import com.google.common.base.Charsets;
+import com.typesafe.config.Config;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import org.apache.gobblin.runtime.api.FlowSpec;
+import org.apache.gobblin.runtime.api.Spec;
+import org.apache.gobblin.runtime.api.SpecSerDe;
+
+
+public class MysqlSpecStoreWithUpdate extends MysqlSpecStore{
+  // In this case, when we try to insert but key is existed, we will throw 
exception
+  protected static final String INSERT_STATEMENT_WITHOUT_UPDATE = "INSERT INTO 
%s (spec_uri, flow_group, flow_name, template_uri, "
+      + "user_to_proxy, source_identifier, destination_identifier, schedule, 
tag, isRunImmediately, owning_group, spec, spec_json) "
+      + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+  public MysqlSpecStoreWithUpdate(Config config, SpecSerDe specSerDe) throws 
IOException {
+    super(config, specSerDe);
+  }
+
+  /** Bundle all changes following from schema differences against the base 
class. */
+  protected class SpecificSqlStatementsWithUpdate extends 
SpecificSqlStatements {
+    public void completeUpdatePreparedStatement(PreparedStatement statement, 
Spec spec, long version) throws
+                                                                               
                          SQLException {
+      FlowSpec flowSpec = (FlowSpec) spec;
+      URI specUri = flowSpec.getUri();
+
+      int i = 0;
+
+      statement.setBlob(++i, new 
ByteArrayInputStream(MysqlSpecStoreWithUpdate.this.specSerDe.serialize(flowSpec)));
+      statement.setString(++i, new 
String(MysqlSpecStoreWithUpdate.this.specSerDe.serialize(flowSpec), 
Charsets.UTF_8));
+      statement.setString(++i, specUri.toString());
+      statement.setLong(++i, version);
+    }
+
+    @Override
+    protected String getTablelessInsertStatement() { return 
INSERT_STATEMENT_WITHOUT_UPDATE; }
+  }
+
+  @Override
+  protected SqlStatements createSqlStatements() {
+    return new SpecificSqlStatementsWithUpdate();
+  }
+
+  @Override
+  // TODO: fix to obey the `SpecStore` contract of returning the *updated* 
`Spec`
+  public Spec updateSpecImpl(Spec spec) throws IOException {
+    updateSpecImpl(spec, Long.MAX_VALUE);
+    return spec;
+  }
+
+  @Override
+  // TODO: fix to obey the `SpecStore` contract of returning the *updated* 
`Spec`
+  public Spec updateSpecImpl(Spec spec, long version) throws IOException {
+    withPreparedStatement(this.sqlStatements.updateStatement, statement -> {
+      
((SpecificSqlStatementsWithUpdate)this.sqlStatements).completeUpdatePreparedStatement(statement,
 spec, version);

Review Comment:
   it's a timestamp which is acting as versioning, I added the comments to 
explain that





Issue Time Tracking
-------------------

    Worklog Id:     (was: 808414)
    Time Spent: 40m  (was: 0.5h)

> Have a separate resource handler to rely on CDC stream to do message 
> forwarding
> -------------------------------------------------------------------------------
>
>                 Key: GOBBLIN-1697
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-1697
>             Project: Apache Gobblin
>          Issue Type: Improvement
>            Reporter: Zihan Li
>            Priority: Major
>          Time Spent: 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to