JDBCTemplate simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results.
http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jdbc/core/JdbcTemplate.html
Here are two methods, the 2nd one is using JDBCTemplate from Srping, you can see the code are more simple and clear:
/** * LoadUsers using JDBC. * @param dataSource * @return */ public ListloadUserJDBC(DataSource dataSource) { List users = new ArrayList (); Connection conn = null; try { conn = dataSource.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement("SELECT ID, EMAIL, LOGIN_NAME, NAME FROM ACCT_USER"); ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { User user = new User(); users.add(user); user.setId(rs.getInt("id")); user.setName(rs.getString("name")); System.out.println(user); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { if(conn != null) { try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return users; } /** * Load users using Spring JDBCTemplate. * @param jdbcTemplate * @return */ public java.util.List doJDBCTempQuery(JdbcTemplate jdbcTemplate) { String queryUsers = "SELECT ID, EMAIL, LOGIN_NAME, NAME FROM ACCT_USER"; java.util.List users = jdbcTemplate.query(queryUsers, new ParameterizedRowMapper () { @Override public User mapRow(ResultSet rs, int arg1) throws SQLException { User user = new User(); user.setId(rs.getInt(1)); user.setName(rs.getString(4)); return user; } }); return users; }
And here is a example to define the template bean:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/mini-liguoliang.com" />
<property name="username" value="root" />
<property name="password" value="pw" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
<constructor-arg ref="dataSource"></constructor-arg>
</bean>
Here is a simple example about configuration of Spring3 and Hibernate4.
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/mini-liguoliang.com" />
<property name="username" value="root" />
<property name="password" value="password" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="com.liguoliang.spring.po"></property>
<property name="hibernateProperties">
<props>
<prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<context:component-scan base-package="com.liguoliang.spring"></context:component-scan>
package com.liguoliang.spring.po; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @Entity @javax.persistence.Table(name="ACCT_USER") public class User { @javax.persistence.Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String name; private String login_name; public String getLogin_name() { return login_name; } public void setLogin_name(String login_name) { this.login_name = login_name; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String toString() { return "User - " + name + " [" + id + "]"; } }
Note the annotation: @Entity
package com.liguoliang.spring; import java.io.File; import java.util.Date; import javax.persistence.Entity; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate4.SessionFactoryUtils; import org.springframework.stereotype.Repository; import com.liguoliang.spring.po.User; @Repository public class UserHibernateDAO { private SessionFactory sessionFactory; @Autowired public UserHibernateDAO(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public User getUserByID(int id) { Session session = SessionFactoryUtils.openSession(sessionFactory); return (User) session.get(User.class, id); } }
We need a hibernateBean instance:
package com.liguoliang.spring.web; @Controller @RequestMapping(value="/spring/user") public class ControllerUser { @Autowired private UserHibernateDAO userHibernateDAO; @RequestMapping(value={"", "list"}) public String list(Model model) { // We just print the user info in the console. System.out.println("userName: " + userHibernateDAO.getUserByID(10).toString()); return "userList"; } }
When list() is called, user with the id ’10’ will be loaded by the hibernateDAO, and printed in the console.
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
Figure 9.2 Data Access Object sequence diagram
The BusinessObject represents the data client. It is the object that requires access to the data source to obtain and store data. A BusinessObject may be implemented as a session bean, entity bean, or some other Java object, in addition to a servlet or helper bean that accesses the data source.
The DataAccessObject is the primary object of this pattern. The DataAccessObject abstracts the underlying data access implementation for the BusinessObject to enable transparent access to the data source. The BusinessObject also delegates data load and store operations to the DataAccessObject.
This represents a data source implementation. A data source could be a database such as an RDBMS, OODBMS, XML repository, flat file system, and so forth. A data source can also be another system (legacy/mainframe), service (B2B service or credit card bureau), or some kind of repository (LDAP).
This represents a Transfer Object used as a data carrier. The DataAccessObject may use a Transfer Object to return data to the client. The DataAccessObject may also receive the data from the client in a Transfer Object to update the data in the data source.
Apache Flex is an application framework for easily building Flash-based applications for mobile devices, the browser and desktop. Summary: A large community is losing momentum as it waits for Adobe to complete the source code transition and infrastructure.
Here are the latest flex news from Apache Flex:
The Apache Flex Project has received the entire Flex Framework. This includes all components that were completed in Adobe’s 4.6.0 release and a few others. Essentially if you take the existing compiler to the frameworks code, you would get what amounts to the current Adobe release.
The automation framework that was a part of the Adobe Flex 4.6.0 framework is close to being donated, but has not been signed off yet. We expect this in the coming weeks.
The Apache Flex Project has received the “mxmlc Flex Compiler”. This means we can now make changes to the existing compiler that shipped with Adobe’s 4.6.0. This will allow us to make bug-fixes and small optimizations while we wait for the new “Falcon” compiler.
The testing framework that Adobe used known as Mustela has been donated. This will allow us to make changes to the compiler and framework while still maintaining compatibility with the previous versions. There are a series of tests that still need to be written, but at least the framework is there.
The Apache Flex team has created a set of build scripts so that anybody can easily build their own copy of the framework. Apache ANT scripts will be officially supported, but other developers have offered to make build scripts for Maven.
Pre-compiled builds have been created and posted. They are not the ‘official’ 4.8.0 version yet, but they are getting close. You can download them and put them in your Flash Builder or IntelliJ SDKs directory and see how they look with your existing projects today. This is a parity release to the current Adobe 4.6.0 release.
Apache committers have begun donating various components to the framework, including an FXGImage component, some collections classes, some major work around validation, busy indicators for non-mobile components, and some navigators. These components have not been integrated into the trunk (the main project), but you should expect to see some of them in the future.
Lots of work is happening around localization and internationalization. A bunch of new locales have been submitted with more on the way.
A team has formed to build what amounts to an automated installer for Apache Flex SDK. This is an AIR application that will allow a user to do a single-click install of the SDK, and integrate it into Flash Builder 4.6.0 (and possibly other IDEs).
Check-in tests and the button tests for Mustella are up and working. Jenkins Continuous Integration is up and running as well.
http://incubator.apache.org/flex/index.html
PHP has a shell_exec command: “Execute command via shell and return the complete output as a string ” http://php.net/manual/en/function.shell-exec.php
And here is a project: http://phpshell.sourceforge.net/
PHP Shell is a shell wrapped in a PHP script. It’s a tool you can use to execute arbitrary shell-commands or browse the filesystem on your remote webserver. This replaces, to a degree, a normal telnet connection, and to a lesser degree a SSH connection.
You use it for administration and maintenance of your website, which is often much easier to do if you can work directly on the server. For example, you could use PHP Shell to unpack and move big files around. All the normal command line programs like ps, free, du, df, etc… can be used.
Download and config phpShell,, and then upload to your server, then you can run shell!
http://phpshell.sourceforge.net/
Crucible is a tool that facilitates code review. It can be as valuable to organisations that already have a formal inspection process as it is to teams that don’t review at all.
Regular peer review is a proven process with demonstrable return on investment (ROI). The benefits vary from team to team but commonly include:
- Identifying bugs and defects early.
- Sharing expertise and encouraging knowledge transfer.
- Improving system-wide knowledge.
- Encouraging adherence to internal standards and style conventions.
- Identifying individual strengths and weaknesses.
In my previous post “Link code change list and issue with FishEye and JIRA 关联代码变更与Issue/BacklogItem’’, test report a bug, and I submit my code change, and linked the code changes to the issue. and now, we need to review the codes I submitted before.
In the left tree, there are the codes need to be review, click one:
Then mark as ‘Complete’
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.