Created
August 4, 2011 19:02
-
-
Save Jach/1125957 to your computer and use it in GitHub Desktop.
Coding style comparison...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .... | |
public RepositoryHolder getRepositories() throws AppException { | |
final String query = "select id, repo_url from localdb.sys_network.repositories"; | |
List<Repository> repo_list = new ArrayList<Repository>(); | |
Repository master = new Repository(); | |
DB.execute(query, master, repo_list); | |
RepositoryHolder ret = new RepositoryHolder(); | |
ret.repositories = repo_list; | |
return ret; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.*; | |
// .... | |
public RepositoryHolder getRepositories() throws AppException { | |
final String query = "select id, repo_url from localdb.sys_network.repositories"; | |
List<Repository> repo_list = new ArrayList<Repository>(); | |
Connection conn = null; | |
PreparedStatement ps = null; | |
ResultSet rs = null; | |
try { | |
Connection conn = DB.getConnection(); | |
ps = conn.prepareStatement(); | |
ps.execute(); | |
rs = ps.getResultSet(); | |
while (rs.next()) { | |
Repository repo = new Repository(); | |
repo.id = rs.getInt(1); | |
repo.repo_url = rs.getString(2); | |
rep_list.add(repo); | |
} | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} finally { | |
if (conn != null) { | |
DB.releaseConnection(); | |
} | |
try { | |
if (ps != null) { | |
ps.close(); | |
} | |
} catch (SQLException ex1) { | |
ex1.printStackTrace(); | |
} | |
try { | |
if (rs != null) { | |
rs.close(); | |
} | |
} catch (SQLException ex2) { | |
ex2.printStackTrace(); | |
} | |
} | |
RepositoryHolder ret = new RepositorHolder(); | |
ret.repositories = repo_list; | |
return ret; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pretend file is Repository.java | |
import java.sql.SQLException; | |
import java.sql.ResultSet; | |
// .... | |
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) | |
@XmlRootElement(name="repository") | |
public class Repository extends DBLoader<Repository> { | |
@XmlAttribute public int id; | |
@XmlAttribute public String repo_url; | |
private Repository copy; | |
public void loadRow(ResultSet rs) throws SQLException { | |
int c = 0; | |
Repository rep = new Repository(); | |
rep.id = rs.getInt(++c); | |
rep.repo_url = rs.getString(++c); | |
copy = rep; | |
} | |
public void finalize() { | |
} | |
public Repository copy() { return copy; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pretend file is Repository.java | |
// .... | |
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) | |
@XmlRootElement(name="repository") | |
public class Repository { | |
@XmlAttribute public int id; | |
@XmlAttribute public String repo_url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+2 for Style 1.