Question about the class "VendorDatabaseIdProvider"

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about the class "VendorDatabaseIdProvider"

Junyan Wu
Recently, I read the mybatis-3 source code. In the class "VendorDatabaseIdProvider", I found this private method which was written as:

private String getDatabaseName(DataSource dataSource) throws SQLException {
    String productName = getDatabaseProductName(dataSource);
    if (this.properties != null) {
      for (Map.Entry<Object, Object> property : properties.entrySet()) {
        if (productName.contains((String) property.getKey())) {
          return (String) property.getValue();
        }
      }
      // no match, return null
      return null;
    }
    return productName;
}

Why not be written as:

private String getDatabaseName(DataSource dataSource) throws SQLException {
    String productName = getDatabaseProductName(dataSource);
    return this.properties == null ? null : properties.getProperty(productName);
}


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Question about the class "VendorDatabaseIdProvider"

Guy Rouillier-2
The original function and your suggested replacement do very different things. For example, if this.properties is null, the original code returns productName, which may or may not be null.  Your rewrite simply returns null.

--
Guy Rouillier

------ Original Message ------
From: "Junyan Wu" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 4/1/2018 10:44:17 PM
Subject: Question about the class "VendorDatabaseIdProvider"

Recently, I read the mybatis-3 source code. In the class "VendorDatabaseIdProvider", I found this private method which was written as:

private String getDatabaseName(DataSource dataSource) throws SQLException {
    String productName = getDatabaseProductName(dataSource);
    if (this.properties != null) {
      for (Map.Entry<Object, Object> property : properties.entrySet()) {
        if (productName.contains((String) property.getKey())) {
          return (String) property.getValue();
        }
      }
      // no match, return null
      return null;
    }
    return productName;
}

Why not be written as:

private String getDatabaseName(DataSource dataSource) throws SQLException {
    String productName = getDatabaseProductName(dataSource);
    return this.properties == null ? null : properties.getProperty(productName);
}


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Question about the class "VendorDatabaseIdProvider"

Junyan Wu
sorry, I didn't read carefully.

Guy Rouillier <[hidden email]> 于 2018年4月2日周一 12:43写道:
The original function and your suggested replacement do very different things. For example, if this.properties is null, the original code returns productName, which may or may not be null.  Your rewrite simply returns null.

--
Guy Rouillier

------ Original Message ------
From: "Junyan Wu" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 4/1/2018 10:44:17 PM
Subject: Question about the class "VendorDatabaseIdProvider"

Recently, I read the mybatis-3 source code. In the class "VendorDatabaseIdProvider", I found this private method which was written as:

private String getDatabaseName(DataSource dataSource) throws SQLException {
    String productName = getDatabaseProductName(dataSource);
    if (this.properties != null) {
      for (Map.Entry<Object, Object> property : properties.entrySet()) {
        if (productName.contains((String) property.getKey())) {
          return (String) property.getValue();
        }
      }
      // no match, return null
      return null;
    }
    return productName;
}

Why not be written as:

private String getDatabaseName(DataSource dataSource) throws SQLException {
    String productName = getDatabaseProductName(dataSource);
    return this.properties == null ? null : properties.getProperty(productName);
}


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.