[英]Ruby inheritance of class and method in JDBC connection string
I have the following code snippet that generates a JDBC connection string for various databases. 我有以下代码片段,为各种数据库生成JDBC连接字符串。 In this case, Dash DB and IBM DB2.
在本例中,Dash DB和IBM DB2。 The following is the structure of the code I use to generate my connection string in DB2.
以下是我用于在DB2中生成连接字符串的代码的结构。
def connection_creation_information
@connection_creation_information ||= Class.new(JDBCConnectionCreationInformation) do
private
def connection_string_primary_params(options)
params = []
params << "currentSchema=#{options[:schema] || options[:username]}"
params << options[:jdbc_additional_params] if options[:jdbc_additional_params]
params
end
def connection_string_scheme
'db2'
end
def connection_string_params(options)
super + ';'
end
def primary_param_separator
';'
end
def base_separator
':'
end
end.new
end
Now, DashDB uses defaultSchema
to define the default schema, while in DB2, it uses currentSchema
. 现在,DashDB使用
defaultSchema
来定义默认模式,而在DB2中,它使用currentSchema
。 I am trying to minimize redundant code as much as possible, so right now, Dash DB's code inherits from DB2 using class HTDialectDashDB < HTDialectDB2
and override the one line/method that matters -- connection_string_primary_params()
我试图尽可能地减少冗余代码,所以现在,Dash DB的代码继承自DB2使用
class HTDialectDashDB < HTDialectDB2
并覆盖重要的一行/方法 - connection_string_primary_params()
In my Dash DB class, I am doing the following: 在我的Dash DB类中,我正在执行以下操作:
def connection_creation_information
@connection_creation_information ||= Class.new(JDBCConnectionCreationInformation) do
private
def connection_string_primary_params(options)
params = []
params << "defaultSchema=#{options[:schema] || options[:username]}"
params << options[:jdbc_additional_params] if options[:jdbc_additional_params]
params
end
end.new
end
However, errors are being thrown that I must implement the four other methods described in the DB2 code, which I want to avoid, because it's just redundant code. 但是,抛出的错误是我必须实现DB2代码中描述的其他四种方法,我想避免这种方法,因为它只是冗余代码。
What can I do in this case? 在这种情况下我该怎么办?
对Dash DB和DB2都使用currentSchema
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.