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/22 09:14:02 UTC

[GitHub] [incubator-shardingsphere] terrymanu commented on a change in pull request #3343: Implement MySQL time service

terrymanu commented on a change in pull request #3343: Implement MySQL time service
URL: https://github.com/apache/incubator-shardingsphere/pull/3343#discussion_r337399920
 
 

 ##########
 File path: sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/spi/MySQLTimeService.java
 ##########
 @@ -0,0 +1,81 @@
+/*
+ * 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 javax.sql.DataSource;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Date;
+import java.util.Properties;
+
+/**
+ * Time service for SPI.
+ *
+ * @author chenchuangliu
+ */
+public final class MySQLTimeService implements TimeService {
+
+    private static DataSource dataSource;
+
+    static {
+        init();
+    }
+
+    @Override
+    public Date getTime() {
+        if (null != dataSource) {
+            try (Connection connection = dataSource.getConnection()) {
+                Statement statement = connection.createStatement();
+                ResultSet resultSet = statement.executeQuery("select now()");
 
 Review comment:
   Please use try with resource here. A standard JDBC process is use two try with resource to handle Connection and ResultSet

----------------------------------------------------------------
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