首页 \ 问答 \ 数据库管理器类的设计模式(Design pattern for database manager class [closed])

数据库管理器类的设计模式(Design pattern for database manager class [closed])

我实现了一个类Database Manager来管理两个数据库引擎上的操作。 该类有一个私有变量databaseEngine ,它在使用类方法(删除数据库,创建数据库,运行脚本,比较,断开连接等)之前设置,并且基于此变量,类可以识别如何操作。

但是,我知道这是错的, Database Manager的方法充满了像这样的交换机案例:

public void CreateNewDatabase(String databaseName){

switch (databaseEngine){
  case "mysql":
      //Executes a prepared statement for dropping mysql database (databaseName
  break;
  case "postgres":
      //Executes a prepared statement for dropping postgres database (databaseName
  break;
...
    }
}

我需要一个很好的建议。 我想加载配置和资源文件夹中的所有内容,我的意思是,准备好的语句用于创建和删除等。如果需要支持新的数据库引擎,它将不会令人头疼,因为它只需要保存sql sripts在资源文件和配置文件中的任何其他数据。 请建议我对这种情况有用的任何设计模式。


I implemented a class Database Manager that manages operations on two database engines. The class has a private variable databaseEngine which is set before using class methods (drop database, create database, run script, compare, disconnect, etc.) and based on this variable the class recognizes how to behave.

However, and I know it's wrong, Database Manager's methods are full of switch cases like this one:

public void CreateNewDatabase(String databaseName){

switch (databaseEngine){
  case "mysql":
      //Executes a prepared statement for dropping mysql database (databaseName
  break;
  case "postgres":
      //Executes a prepared statement for dropping postgres database (databaseName
  break;
...
    }
}

I require a good advice about this. I want to load everything from configuration and resources folders, I mean, the prepared statement for creating and dropping, etc. If a new database engine needs to be supported, it won't be a headache as It would just require to save sql sripts in a resources file and any other data in a configuration file. Please, suggest me any design pattern useful for this case.


原文:https://stackoverflow.com/questions/37597207
更新时间:2023-06-01 21:06

最满意答案

OK玩弄它显示了它和jQuery日期的答案完全一样。 你以0x开头的数字部分。

  1. 在0x之后取10个数字。 例如在A2: =MID(A1, 3, 10)

  2. 将其转换为十六进制,例如A3: = HEX2DEC(A2)

  3. 除以86400,例如A4: =A3/86400

  4. 并将结果添加到1/1/1970日期。 例如= A5: =A4 + Date(1970, 1, 1)

或简而言之:

=(hex2dec(mid(a1,numstart,10))/86400) + date(1970,1,1)

numstart的1开始索引替换numstart

例如3,如果你有一个12或13位数字,如0x12345678AB,你会得到12345678AB

这与在Excel中转​​换JSON日期/日期(1388624400000)/日期类似

除了那个:

一个。 这个问题被回答错误,并且不起作用。 (我编辑它)

湾 .sql文件是通过SQL从数据库的存储过程中检索的。 虽然在他们使用jQuery返回的Ajax数据,这似乎是不同的问题。 原来他们是不同格式的相同号码。

作为补充说明,我在我的十六进制数字的开头有一个空格标记。 在我做了MID之前,我没有看到它。

注意:使用ajax返回的格式化日期(例如/ date:0x12345678ab /)时,您将numstart设置为8.如果hex2dec失败,请尝试在调用hex2dec之前将十六进制字符串转换为大写。 要调试只是把每个公式放在一个单独的单元格中,所以你会看到什么有效,什么不可行。


OK Playing around with it showed me that it's exactly the same as the jquery date answer. You take the numeric portion starting with 0x.

  1. Take the 10 digits AFTER the 0x. e.g. in A2: =MID(A1, 3, 10)

  2. Turn it into hexadecimal e.g. in A3: = HEX2DEC(A2)

  3. Divide by 86400 e.g. A4: =A3/86400

  4. And add the result to 1/1/1970 date. e.g. = A5: =A4 + Date(1970, 1, 1)

Or in short:

=(hex2dec(mid(a1,numstart,10))/86400) + date(1970,1,1)

Replace numstart with the 1-starting index of the number.

e.g. 3 if you have a 12 or 13 digit number like 0x12345678AB and you'll get 12345678AB

This is similar to the Convert JSON Date /Date(1388624400000)/ to Date in Excel

Except that:

a. The question was answered wrong and wouldn't work. (I edited it)

b. The .sql file was retrieved in a stored procedure from the database via SQL. While in the question they were using jquery returned ajax data, which seemed to differ. Turns out they're the same number with a different format.

As an added remark, I had a space mark at the beginning of my hex number. Until I did the MID on it, I didn't see that.

Note: When using ajax returned formatted dates like /date:0x12345678ab/ you'll set numstart to 8. If hex2dec fails, try turning the hex string into uppercase before calling hex2dec. To debug just put each formula in a separate cell, so you see what works and what doesn't.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。