List of usage examples for org.apache.commons.dbutils QueryRunner update
public int update(String sql, Object... params) throws SQLException
From source file:org.codesearch.commons.database.DBAccessImpl.java
/** * {@inheritDoc}//from ww w .jav a 2 s.c o m */ @Override public synchronized void setAnalysisDataForFile(String filePath, String repository, AstNode binaryIndex, List<Usage> usages, List<String> types, List<String> imports) throws DatabaseAccessException { int fileId = ensureThatRecordExists(filePath, repository); int repoId = getRepoIdForRepoName(repository); QueryRunner run = new QueryRunner(dataSource); try { // Clears all types set for the file in a previous indexing process run.update(STMT_CLEAR_TYPES_FOR_FILE, fileId); // Clears all imports set for the file in a previous indexing procedure run.update(STMT_CLEAR_IMPORTS_FOR_FILE, fileId); // Sets the Binary index and the usages for the file run.update(STMT_SET_BINARY_INDEX_AND_USAGES_FOR_FILE, binaryIndex, usages, fileId); // Sets the types for the file, if any if (!(types.isEmpty())) { // extends the insert into statement by one line for each type in the list of types StringBuilder statement = new StringBuilder(STMT_CREATE_TYPES_FOR_FILE); String[] params = new String[types.size()]; for (int i = 0; i < types.size(); i++) { statement.append("(?, ").append(fileId).append(", ").append(repoId).append("),"); params[i] = types.get(i); } statement.deleteCharAt(statement.length() - 1); run.update(statement.toString(), (Object[]) params); } // Sets the imports for the file, if any if (!imports.isEmpty()) { // first build the import statement by adding all values StringBuilder importString = new StringBuilder(STMT_SET_IMPORTS_FOR_FILE); String[] params = new String[imports.size()]; for (int i = 0; i < imports.size(); i++) { importString.append("(").append(fileId).append(", ?),"); params[i] = imports.get(i); } importString.deleteCharAt(importString.length() - 1); run.update(importString.toString(), (Object[]) params); } } catch (SQLException ex) { throw new DatabaseAccessException("SQLException while trying to access the database\n" + ex); } }
From source file:org.dbmfs.DatabaseAccessor.java
/** * ??.<br>//from www . ja v a2s . c o m * * @return ??? */ public void createTable(DDLFolder folder, String tableName) throws Exception { try { QueryRunner qr = new QueryRunner(); int createRet = qr.update(injectConn, folder.getCreateSQL(tableName)); } catch (SQLException se) { se.printStackTrace(); throw se; } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:org.gaixie.jibu.JibuTestSupport.java
/** * ????/*from w ww. j a va 2 s . c o m*/ * ?? */ protected void clearTable() { Connection conn = null; try { conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); run.update(conn, "DELETE from schema_changes"); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); System.out.println(e.getMessage()); } }
From source file:org.gaixie.jibu.security.dao.SchemaCreate.java
private StringBuilder handleLine(StringBuilder command, String line, QueryRunner run, Connection conn) throws SQLException { String trimmedLine = line.trim(); if (isComment(trimmedLine)) { //System.out.println(command); } else if (trimmedLine.endsWith(";")) { command.append(line.substring(0, line.lastIndexOf(";"))); command.append(" "); run.update(conn, command.toString()); command.setLength(0);//from www . jav a2 s .c om } else if (trimmedLine.length() > 0) { command.append(line); command.append(" \n"); } return command; }
From source file:org.gaixie.jibu.security.service.AuthorityServiceTest.java
@Before public void setup() throws Exception { authService = getInjector().getInstance(AuthorityService.class); roleService = getInjector().getInstance(RoleService.class); userService = getInjector().getInstance(UserService.class); userService.add(new User("Administrator", "admin", "123456", "jibu.gaixie@gmail.com", true)); authService.add(new Authority("sec.ast-v-auth1", "/ast-v-auth1.z")); authService.add(new Authority("sec.ast-v-auth2", "/ast-v-auth2.z")); authService.add(new Authority("sec.ast-v-auth3", "/ast-v-auth3.z")); // ??(value.length <5)?????? authService.add(new Authority("ci", "/ast-v-auth1.z?ci=addUser")); userService.add(new User("ast-v-user1", "ast-v-user1", "123456", "ast-v-user1@x.xxx", true)); /*//from w w w . j a va 2 s .c o m * * ROLE_BASE * |-----ROLE_ADMIN * | * |-----ast-v-role1 * | |------ast-v-role2 * |-----ast-v-role3 */ // ? Role Connection conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); run.update(conn, "INSERT INTO roles (name,description,lft,rgt) values ('ROLE_BASE','ROLE_BASE',1,2)"); DbUtils.commitAndClose(conn); Role parent = roleService.get("ROLE_BASE"); roleService.add(new Role("ROLE_ADMIN", "ROLE_ADMIN"), parent); roleService.add(new Role("ast-v-role1", "ast-v-role1"), parent); roleService.add(new Role("ast-v-role3", "ast-v-role3"), parent); parent = roleService.get("ast-v-role1"); roleService.add(new Role("ast-v-role2", "ast-v-role2"), parent); /* ???? * ROLE_BASE * |-----ROLE_ADMIN * | * |-----ast-v-role1 <==> (/ast-v-auth1.z ) (/ast-v-auth1.z?ci=addUser) * | |------ast-v-role2 * |-----ast-v-role3 <==> (/ast-v-auth2.z ) */ Authority auth = authService.get("/ast-v-auth1.z"); Role role = roleService.get("ast-v-role1"); roleService.bind(role, auth); auth = authService.get("/ast-v-auth1.z?ci=addUser"); roleService.bind(role, auth); auth = authService.get("/ast-v-auth2.z"); role = roleService.get("ast-v-role3"); roleService.bind(role, auth); /* ast-v-role2, admin ROLE_ADMIN * ROLE_BASE * |-----ROLE_ADMIN <==> (admin) * | * |-----ast-v-role1 * | |------ast-v-role2 <==> (ast-v-user1) * |-----ast-v-role3 */ role = roleService.get("ast-v-role2"); User user = userService.get("ast-v-user1"); roleService.bind(role, user); role = roleService.get("ROLE_ADMIN"); user = userService.get("admin"); roleService.bind(role, user); }
From source file:org.gaixie.jibu.security.service.AuthorityServiceTest.java
@After public void tearDown() { Connection conn = null;//from w ww . jav a2s. c o m try { conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); run.update(conn, "DELETE from role_authority_map "); run.update(conn, "DELETE from user_role_map"); run.update(conn, "DELETE from roles"); run.update(conn, "DELETE from authorities "); run.update(conn, "DELETE from userbase"); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); System.out.println(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.LoginServiceTest.java
@Test(expected = TokenException.class) public void testTokenExpired() throws Exception { Token token = loginService.generateToken("admin"); Assert.assertNotNull(token);//w ww. j a va2 s . c om // token(?)token long time = Calendar.getInstance().getTimeInMillis(); Timestamp ts = new Timestamp(time); Token tk = new Token(); tk.setExpiration(ts); Connection conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); String s = SQLBuilder.beanToSQLClause(tk, ","); String sql = "Update tokens " + SQLBuilder.getSetClause(s) + " where value = '" + token.getValue() + "'"; run.update(conn, sql); DbUtils.commitAndClose(conn); loginService.resetPassword(token.getValue(), "654321"); }
From source file:org.gaixie.jibu.security.service.LoginServiceTest.java
@After public void tearDown() { Connection conn = null;//from ww w .ja v a2s . co m try { conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); run.update(conn, "DELETE from tokens"); run.update(conn, "DELETE from userbase"); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); System.out.println(e.getMessage()); } }
From source file:org.gaixie.jibu.security.service.RoleServiceTest.java
@Before public void setup() throws Exception { roleService = getInjector().getInstance(RoleService.class); Connection conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); run.update(conn, "INSERT INTO roles (name,description,lft,rgt) values ('ROLE_BASE','ROLE_BASE',1,2)"); DbUtils.commitAndClose(conn);//from www . j a va 2 s.co m }
From source file:org.gaixie.jibu.security.service.RoleServiceTest.java
@After public void tearDown() { Connection conn = null;//ww w . j a v a2s .c om try { conn = ConnectionUtils.getConnection(); QueryRunner run = new QueryRunner(); run.update(conn, "DELETE from roles"); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); System.out.println(e.getMessage()); } }