You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/10/11 03:47:43 UTC

[GitHub] [incubator-shardingsphere] Pramy commented on a change in pull request #3217: support now() for sharding value

Pramy commented on a change in pull request #3217: support now() for sharding value
URL: https://github.com/apache/incubator-shardingsphere/pull/3217#discussion_r333816398
 
 

 ##########
 File path: sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/spi/DefaultTimeService.java
 ##########
 @@ -0,0 +1,55 @@
+/*
+ * 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.shardingsphere.core.route.spi;
+
+import com.google.common.base.Optional;
+import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment;
+import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.complex.ComplexExpressionSegment;
+import org.apache.shardingsphere.core.spi.NewInstanceServiceLoader;
+
+import java.util.Collection;
+import java.util.Date;
+
+public final class DefaultTimeService implements TimeService {
+
+    private final Collection<TimeService> timeServices = NewInstanceServiceLoader.newServiceInstances(TimeService.class);
+
+    static {
+        NewInstanceServiceLoader.register(TimeService.class);
+    }
+
+    @Override
+    public Optional<Date> getTime() {
+        for (TimeService server : timeServices) {
+            Optional<Date> dateOptional = server.getTime();
+            if (dateOptional.isPresent()) {
+                return dateOptional;
+            }
+        }
+        return Optional.of(new Date());
+    }
+
+    /**
+     * judge expression.
+     * @param segment ExpressionSegment
+     * @return true or false
+     */
+    public boolean isNowExpression(final ExpressionSegment segment) {
 
 Review comment:
   thanks for your suggestion. This method is used in many places. Maybe I can create a `NowExpressionUtils` class?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services