设计 无状态的类,而不是 stateful
|
I have created a Database Abstraction Layer over PDO to refrain from creating multiple queries around my scripts which would be pretty hard to maintain. My DBAL is not very broad; It takes care of simple tasks such as INSERTING, UPDATING and SELECTING (with or without joining). It does not cover more advanced stuff such as selecting from multiple tables etc. The problem that raised with my DBAL is that it is confusing queries when there are more of the same type in one HTTP request. For example there are three select statements in my script, the first one works, the other two don't. I tried creating a Anyway, this is how I do some queries with my class: |
|
0down voteaccepted
|
Don't make it stateful. Even without looking at the code I'll tell you what's the problem: get rid of All the method calls have to be atomic, each performing all the necessary operations and returning all the requested data. While saving nothing in the class variables. As simple as that. In such a rare case when PDOStatement object have to be used further - return this very object, don't save it inside. Otherwise just return the requested data. I wold also advise to get rid of your whole DBAL, as it's written out of good intentions but I can tell for sure that implementation turns out to be less helpful but it actually makes your code worse in many aspects - readability, flexibility, maintainability. In pursue for the fictional usability, you are saving yourself only a word or two from SQL, but making whole application code unreliable. You won't listen to me, though. Some experience in maintaining applications is required to see my point. |
|
Please suggest an alternative method to simplify the query writing process without using an ORM or something similar. Is there a good DBAL based on PDO out there? – Aborted Dec 19 '13 at 22:19
|
|||
|
There is very little sense in creating a DBAL over PDO as PDO is already one. What's you're after is calledquery builder. You can find a lot of examples googleing for the term. though you don't actually need even this one too. I don't understand that strong desire of all the newbie programmers to get rid of precious SQL. – Your Common Sense Dec 20 '13 at 7:47
|
||
|
|
Accepting your answer as it includes very useful (and honest) advice. I've gotten rid of my class and start using queries all around again. I'm actually not that much of a newbie programmer, I just don't have enough time to become a professional. – Aborted Dec 20 '13 at 21:26
|
设计 无状态的类,而不是 stateful的更多相关文章
- 有状态(Stateful)与无状态(Stateless)
1.有状态(Stateful): 有数据存储功能.有状态对象(Stateful Bean),就是有实例变量的对象,可以保存数据,类里面有成员变量,而且成员变量是可变的,是非线程安全的.在不同方法调用间 ...
- 基于Volley,Gson封装支持JWT无状态安全验证和数据防篡改的GsonRequest网络请求类
这段时间做新的Android项目的client和和REST API通讯框架架构设计.使用了非常多新技术,终于的方案也相当简洁优雅.client仅仅须要传Java对象,server端返回json字符串, ...
- 有状态 无状态 stateful stateless monolithic architecture microservice architecture 单体架构
为什么游戏公司的server不愿意微服务化? - 知乎 https://www.zhihu.com/question/359630395 我大概说了,方便测试,方便维护,方便升级,服务之间松耦合,可多 ...
- SpringCloud系列三:SpringSecurity 安全访问(配置安全验证、服务消费端处理、无状态 Session 配置、定义公共安全配置程序类)
1.概念:SpringSecurity 安全访问 2.具体内容 所有的 Rest 服务最终都是暴露在公网上的,也就是说如果你的 Rest 服务属于一些你自己公司的私人业务,这样的结果会直接 导致你信息 ...
- Date类为什么设计为可变的,而不是像String一样?
首先,不得不承认,这确实是类库设计的一个错误,所以"为什么"进行了这个错误设计并没有意义.但没有事物一诞生就是完美的,我们的Java只是反应的慢了一点,再慢了一点. 更何况,Dat ...
- Flutter - Stateful(有状态) 和 stateless(无状态) widgets
Stateful(有状态) 和 stateless(无状态) widgets 有些widgets是有状态的, 有些是无状态的 如果用户与widget交互,widget会发生变化,那么它就是有状态的. ...
- http协议和web应用有状态和无状态浅析
http协议和web应用有状态和无状态浅析 (2013-10-14 10:38:06) 转载▼ 标签: it 我们通常说的web应用程序的无状态性的含义是什么呢? 直观的说,“每次的请求都是独立的 ...
- 无状态服务(stateless service)
一.定义 无状态服务(stateless service)对单次请求的处理,不依赖其他请求,也就是说,处理一次请求所需的全部信息,要么都包含在这个请求里,要么可以从外部获取到(比如说数据库),服务器本 ...
- 这个知识点不错,,学习一下先。。。无状态服务(stateless service)(转)
这样的应用,显得高级一些哟~~:) +================== http://kyfxbl.iteye.com/blog/1831869 ========================= ...
随机推荐
- Windows 系统变量大全
来源:http://blog.csdn.net/kingwolf_javascript/article/details/2477234 %ALLUSERSPROFILE% : 列出所有用户Profil ...
- rm: 无法删除 "xxxxx.o" : 输入/输出错误.
rm: 无法删除 "xxxxx.o" : 输入/输出错误. 碰到无法删除的文件,以为完蛋了,要重装. 后面重启一下就可以了
- sql查询百分号的方法
select * from [tablename] where [col] like '%100/%%' escape '/'
- 上海赛区-org.apache.ibatis.type.TypeException: JDBC requires that the JdbcType must be specified for all nullable parameters.
执行此函数的时候报错 解决方法:关闭窗口之后刷新主页面 提示: 传入到xml sql语句中的参数为null时就会出现此错误,需要仔细检查
- WPF之让ListView中的CheckBox居中显示
第一步:在资源中定义一个居中的样式: <Window.Resources> <Style x:Key="ListViewItemStyle" TargetType ...
- slf4j(simple logging facade for java)
http://www.tuicool.com/articles/IfeUfq slf4j(simple logging facade for java)是Java的简单的日志门面,它 不是具体的日 ...
- 。net MVC 序列化 反序列化
序列化 (Serialization)将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写入到临时或持久性存储区.以后,可以通过从存储区中读取或反序列化对象 ...
- Android中实现滑动翻页—使用ViewFlipper(dp和px之间进行转换)
Android中实现滑动翻页—使用ViewFlipper(dp和px之间进行转换) Android中dp和px之间进行转换 在xml布局文件中,我们既可以设置px,也可以设置dp(或者dip).一般情 ...
- HUD 1541/BIT(数状数组)
题目链接 /* 按从左到右,从下到上的顺序给出星星的坐标,计算出level为[0,n)的星星的个数. 星星的level为该星星左下边(包括自己正下方的星星,但是不包括自己)星星的个数. BIT模板题. ...
- SCRIPT7002: XMLHttpRequest: 网络错误 0x2ef3, 由于出现错误 00002ef3 
项目使用的是tomcat7 ,浏览器是ie11 突然打开浏览器发现不能获取数据了 tomcat conf server.xml 文件 <Connector port="8080&quo ...