List of usage examples for java.sql Connection setTransactionIsolation
void setTransactionIsolation(int level) throws SQLException;
Connection
object to the one given. From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean revokeAuthRoleSys(String role, List<String> privileges) throws NoSuchObjectException, InvalidObjectException, MetaException { Connection con = null; ;/*w w w . j a v a 2 s . c o m*/ PreparedStatement ps = null; boolean success = false; role = role.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("revoke role auth from user error , user=" + role + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("revoke role auth from user error , user=" + role + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); ps = con.prepareStatement("select alter_priv,create_priv, createview_priv, dba_priv " + ",delete_priv, drop_priv, index_priv, insert_priv, select_priv, showview_priv" + ",update_priv from tdwrole where role_name=?"); ps.setString(1, role); boolean isPrivFind = false; boolean selPriv = false; boolean insertPriv = false; boolean createPriv = false; boolean dropPriv = false; boolean deletePriv = false; boolean alterPriv = false; boolean updatePriv = false; boolean indexPriv = false; boolean showViewPriv = false; boolean createViewPriv = false; boolean dbaPriv = false; ResultSet userSet = ps.executeQuery(); while (userSet.next()) { isPrivFind = true; alterPriv = userSet.getBoolean(1); createPriv = userSet.getBoolean(2); createViewPriv = userSet.getBoolean(3); dbaPriv = userSet.getBoolean(4); deletePriv = userSet.getBoolean(5); dropPriv = userSet.getBoolean(6); indexPriv = userSet.getBoolean(7); insertPriv = userSet.getBoolean(8); selPriv = userSet.getBoolean(9); showViewPriv = userSet.getBoolean(10); updatePriv = userSet.getBoolean(11); break; } userSet.close(); ps.close(); if (!isPrivFind) { throw new NoSuchObjectException("can not find user:" + role); } for (String priv : privileges) { if (priv.equals("TOK_SELECT_PRI")) { selPriv = false; } else if (priv.equals("TOK_INSERT_PRI")) { insertPriv = false; } else if (priv.equals("TOK_CREATE_PRI")) { createPriv = false; } else if (priv.equals("TOK_DROP_PRI")) { dropPriv = false; } else if (priv.equals("TOK_DELETE_PRI")) { deletePriv = false; } else if (priv.equals("TOK_ALTER_PRI")) { alterPriv = false; } else if (priv.equals("TOK_UPDATE_PRI")) { updatePriv = false; } else if (priv.equals("TOK_INDEX_PRI")) { indexPriv = false; } else if (priv.equals("TOK_CREATEVIEW_PRI")) { createViewPriv = false; } else if (priv.equals("TOK_SHOWVIEW_PRI")) { showViewPriv = false; } else if (priv.equals("TOK_DBA_PRI")) { dbaPriv = false; } else if (priv.equals("TOK_ALL_PRI")) { selPriv = false; insertPriv = false; createPriv = false; dropPriv = false; deletePriv = false; alterPriv = false; updatePriv = false; indexPriv = false; createViewPriv = false; showViewPriv = false; } else { throw new InvalidObjectException("Privilege does not exist: " + priv); } } ps = con.prepareStatement( "update tdwrole set alter_priv=?, create_priv=?, createview_priv=?, dba_priv=?," + " delete_priv=?, drop_priv=?, index_priv=?, insert_priv=?, select_priv=?, showview_priv=?," + " update_priv=? where role_name=?"); ps.setBoolean(1, alterPriv); ps.setBoolean(2, createPriv); ps.setBoolean(3, createViewPriv); ps.setBoolean(4, dbaPriv); ps.setBoolean(5, deletePriv); ps.setBoolean(6, dropPriv); ps.setBoolean(7, indexPriv); ps.setBoolean(8, insertPriv); ps.setBoolean(9, selPriv); ps.setBoolean(10, showViewPriv); ps.setBoolean(11, updatePriv); ps.setString(12, role); ps.executeUpdate(); con.commit(); success = true; } catch (SQLException ex) { LOG.error("revoke auth from role error , user=" + role + ", msg=" + ex.getMessage()); ex.printStackTrace(); throw new MetaException(ex.getMessage()); } finally { if (!success) { try { con.rollback(); } catch (SQLException e) { } } closeStatement(ps); closeConnection(con); } return success; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public TblPriv getAuthOnTbl(String who, String db, String tbl) throws MetaException { boolean success = false; Connection con; Statement ps = null;/*ww w.j a v a 2s .com*/ TblPriv tblPriv = null; who = who.toLowerCase(); db = db.toLowerCase(); tbl = tbl.toLowerCase(); try { con = getSegmentConnection(db); } catch (MetaStoreConnectException e1) { LOG.error("get user table auth error, db=" + db + ", tbl=" + tbl + ", who=" + who + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get user table auth error, db=" + db + ", tbl=" + tbl + ", who=" + who + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select alter_priv, create_priv, delete_priv " + ",drop_priv, index_priv, insert_priv, select_priv, update_priv" + " from tblpriv where user_name='" + who + "' and db_name='" + db + "' and tbl_name='" + tbl + "'"; ResultSet tblSet = ps.executeQuery(sql); while (tblSet.next()) { tblPriv = new TblPriv(); tblPriv.setAlterPriv(tblSet.getBoolean(1)); tblPriv.setCreatePriv(tblSet.getBoolean(2)); tblPriv.setDeletePriv(tblSet.getBoolean(3)); tblPriv.setDropPriv(tblSet.getBoolean(4)); tblPriv.setIndexPriv(tblSet.getBoolean(5)); tblPriv.setInsertPriv(tblSet.getBoolean(6)); tblPriv.setSelectPriv(tblSet.getBoolean(7)); tblPriv.setUpdatePriv(tblSet.getBoolean(8)); tblPriv.setDb(db); tblPriv.setTbl(tbl); tblPriv.setUser(who); break; } con.commit(); success = true; } catch (SQLException sqlex) { LOG.error("get user table auth error, db=" + db + ", tbl=" + tbl + ", who=" + who + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return tblPriv; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean revokeAuthSys(String userName, List<String> privileges) throws NoSuchObjectException, InvalidObjectException, MetaException { Connection con = null; ;//from ww w. j av a 2s . c o m PreparedStatement ps = null; boolean success = false; userName = userName.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("revoke auth from user error , user=" + userName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("revoke auth from user error , user=" + userName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); ps = con.prepareStatement("select alter_priv,create_priv, createview_priv, dba_priv " + ",delete_priv, drop_priv, index_priv, insert_priv, select_priv, showview_priv" + ",update_priv from tdwuser where user_name=?"); ps.setString(1, userName); boolean isPrivFind = false; boolean selPriv = false; boolean insertPriv = false; boolean createPriv = false; boolean dropPriv = false; boolean deletePriv = false; boolean alterPriv = false; boolean updatePriv = false; boolean indexPriv = false; boolean showViewPriv = false; boolean createViewPriv = false; boolean dbaPriv = false; ResultSet userSet = ps.executeQuery(); while (userSet.next()) { isPrivFind = true; alterPriv = userSet.getBoolean(1); createPriv = userSet.getBoolean(2); createViewPriv = userSet.getBoolean(3); dbaPriv = userSet.getBoolean(4); deletePriv = userSet.getBoolean(5); dropPriv = userSet.getBoolean(6); indexPriv = userSet.getBoolean(7); insertPriv = userSet.getBoolean(8); selPriv = userSet.getBoolean(9); showViewPriv = userSet.getBoolean(10); updatePriv = userSet.getBoolean(11); break; } userSet.close(); ps.close(); if (!isPrivFind) { throw new NoSuchObjectException("can not find user:" + userName); } for (String priv : privileges) { if (priv.equals("TOK_SELECT_PRI")) { selPriv = false; } else if (priv.equals("TOK_INSERT_PRI")) { insertPriv = false; } else if (priv.equals("TOK_CREATE_PRI")) { createPriv = false; } else if (priv.equals("TOK_DROP_PRI")) { dropPriv = false; } else if (priv.equals("TOK_DELETE_PRI")) { deletePriv = false; } else if (priv.equals("TOK_ALTER_PRI")) { alterPriv = false; } else if (priv.equals("TOK_UPDATE_PRI")) { updatePriv = false; } else if (priv.equals("TOK_INDEX_PRI")) { indexPriv = false; } else if (priv.equals("TOK_CREATEVIEW_PRI")) { createViewPriv = false; } else if (priv.equals("TOK_SHOWVIEW_PRI")) { showViewPriv = false; } else if (priv.equals("TOK_DBA_PRI")) { dbaPriv = false; } else if (priv.equals("TOK_ALL_PRI")) { selPriv = false; insertPriv = false; createPriv = false; dropPriv = false; deletePriv = false; alterPriv = false; updatePriv = false; indexPriv = false; createViewPriv = false; showViewPriv = false; } else { throw new InvalidObjectException("Privilege does not exist: " + priv); } } ps = con.prepareStatement( "update tdwuser set alter_priv=?, create_priv=?, createview_priv=?, dba_priv=?," + " delete_priv=?, drop_priv=?, index_priv=?, insert_priv=?, select_priv=?, showview_priv=?," + " update_priv=? where user_name=?"); ps.setBoolean(1, alterPriv); ps.setBoolean(2, createPriv); ps.setBoolean(3, createViewPriv); ps.setBoolean(4, dbaPriv); ps.setBoolean(5, deletePriv); ps.setBoolean(6, dropPriv); ps.setBoolean(7, indexPriv); ps.setBoolean(8, insertPriv); ps.setBoolean(9, selPriv); ps.setBoolean(10, showViewPriv); ps.setBoolean(11, updatePriv); ps.setString(12, userName); ps.executeUpdate(); con.commit(); success = true; } catch (SQLException ex) { LOG.error("revoke auth from user error , user=" + userName + ", msg=" + ex.getMessage()); ex.printStackTrace(); throw new MetaException(ex.getMessage()); } finally { if (!success) { try { con.rollback(); } catch (SQLException e) { } } closeStatement(ps); closeConnection(con); } return success; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean isView(String dbName, String tblName) throws NoSuchObjectException, MetaException { Connection con = null; Statement ps = null;// ww w.j a v a2s . c o m boolean success = false; boolean is = false; dbName = dbName.toLowerCase(); tblName = tblName.toLowerCase(); try { con = getSegmentConnection(dbName); } catch (MetaStoreConnectException e1) { LOG.error( "check is a view error error, db=" + dbName + ", tbl=" + tblName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error( "check is a view error error, db=" + dbName + ", tbl=" + tblName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select tbl_type from tbls where db_name='" + dbName + "' and tbl_name='" + tblName + "'"; String type = null; boolean isTblFind = false; ResultSet tSet = ps.executeQuery(sql); while (tSet.next()) { type = tSet.getString(1); isTblFind = true; break; } if (!isTblFind) { LOG.error("check is a view error error, db=" + dbName + ", tbl=" + tblName); throw new NoSuchObjectException("can not find table/view:" + dbName + ", tbl=" + tblName); } if (type != null && type.equalsIgnoreCase("VIRTUAL_VIEW")) { is = true; } success = true; } catch (SQLException sqlex) { LOG.error("check is a view error error, db=" + dbName + ", tbl=" + tblName + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return is; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public void addTblProps(String dbName, String tblName, String modifyUser, Map<String, String> props) throws InvalidOperationException, MetaException { Connection con; PreparedStatement ps = null;//from w w w . j a v a 2 s . c om boolean success = false; dbName = dbName.toLowerCase(); tblName = tblName.toLowerCase(); try { con = getSegmentConnection(dbName); } catch (MetaStoreConnectException e1) { LOG.error("add table props error, db=" + dbName + ", tbl=" + tblName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("add table props error, db=" + dbName + ", tbl=" + tblName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); ps = con.prepareStatement("select tbls.tbl_id from tbls where " + "tbls.db_name=? and tbls.tbl_name=?"); ps.setString(1, dbName); ps.setString(2, tblName); boolean isTblFind = false; long tblID = 0; ResultSet tblSet = ps.executeQuery(); while (tblSet.next()) { isTblFind = true; tblID = tblSet.getLong(1); } tblSet.close(); ps.close(); if (!isTblFind) { throw new MetaException("can not find table " + dbName + ":" + tblName); } ps = con.prepareStatement( "select param_key, param_value from table_params where tbl_id=? and param_type='TBL'"); ps.setLong(1, tblID); ResultSet paramSet = ps.executeQuery(); Map<String, String> oldParamMap = new HashMap<String, String>(); while (paramSet.next()) { oldParamMap.put(paramSet.getString(1), paramSet.getString(2)); } paramSet.close(); ps.close(); Map<String, String> needUpdateMap = new HashMap<String, String>(); Map<String, String> needAddMap = new HashMap<String, String>(); for (Entry<String, String> entry : props.entrySet()) { if (oldParamMap.containsKey(entry.getKey())) { needUpdateMap.put(entry.getKey(), entry.getValue()); } else { needAddMap.put(entry.getKey(), entry.getValue()); } } if (oldParamMap.containsKey("last_modified_time")) { needUpdateMap.put("last_modified_time", String.valueOf(System.currentTimeMillis() / 1000)); } else { needAddMap.put("last_modified_time", String.valueOf(System.currentTimeMillis() / 1000)); } if (oldParamMap.containsKey("last_modified_by")) { needUpdateMap.put("last_modified_by", modifyUser); } else { needAddMap.put("last_modified_by", modifyUser); } if (!needUpdateMap.isEmpty()) { ps = con.prepareStatement("update table_params set param_value=? where " + " tbl_id=? and param_type='TBL' and param_key=?"); for (Entry<String, String> entry : needUpdateMap.entrySet()) { ps.setString(1, entry.getValue()); ps.setLong(2, tblID); ps.setString(3, entry.getKey()); ps.addBatch(); } ps.executeBatch(); ps.close(); } if (!needAddMap.isEmpty()) { ps = con.prepareStatement("insert into table_params(tbl_id, param_type, " + "param_key, param_value) values(?,?,?,?)"); for (Map.Entry<String, String> entry : needAddMap.entrySet()) { ps.setLong(1, tblID); ps.setString(2, "TBL"); ps.setString(3, entry.getKey()); ps.setString(4, entry.getValue()); ps.addBatch(); } ps.executeBatch(); ps.close(); } con.commit(); success = true; } catch (SQLException ex) { LOG.error("add table props error, db=" + dbName + ", tbl=" + tblName + ", msg=" + ex.getMessage()); throw new MetaException(ex.getMessage()); } finally { if (!success) { try { con.rollback(); } catch (SQLException e) { } } closeStatement(ps); closeConnection(con); } return; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean dropAuthOnTbl(String who, String db, String tbl) throws MetaException { Connection con = null; ;//from ww w . j av a 2 s .c o m Statement ps = null; boolean success = false; who = who.toLowerCase(); db = db.toLowerCase(); tbl = tbl.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("drop auth on tbl error, who=" + who + ", db=" + db + ", tbl=" + tbl + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("drop auth on tbl error, who=" + who + ", db=" + db + ", tbl=" + tbl + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); String sql = "delete from tblpriv where user_name='" + who + "' and db_name='" + db + "' and tbl_name='" + tbl + "'"; ps = con.createStatement(); ps.executeUpdate(sql); con.commit(); success = true; } catch (SQLException sqlex) { LOG.error("drop auth on tbl error, who=" + who + ", db=" + db + ", tbl=" + tbl + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { if (!success) { try { con.rollback(); } catch (SQLException e) { } } closeStatement(ps); closeConnection(con); } return success; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public Map<String, TableInfo> getTableWithTypeWithParams(String dbName, String pattern) throws MetaException { // TODO Auto-generated method stub Connection con; Statement ps = null;/*ww w . ja va2s. c om*/ Map<String, TableInfo> tblInfoMap = new TreeMap<String, TableInfo>(); dbName = dbName.toLowerCase(); pattern = pattern.toLowerCase(); try { con = getSegmentConnection(dbName); } catch (MetaStoreConnectException e1) { // TODO Auto-generated catch block LOG.error("get table error, db=" + dbName + ", pattern=" + pattern + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { // TODO Auto-generated catch block LOG.error("get table error, db=" + dbName + ", pattern=" + pattern + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = null; if (pattern == null || pattern.isEmpty() || pattern.equals(".*") || pattern.equals("*")) { sql = "select create_time, tbl_type, tbl_name, tbl_owner, pri_part_type, tbl_comment from tbls where db_name='" + dbName + "'"; } else { pattern = pattern.replace('*', '%'); sql = "select create_time, tbl_type, tbl_name, tbl_owner, pri_part_type, tbl_comment from tbls where db_name='" + dbName + "'" + " and tbl_name like '" + pattern + "'"; } ResultSet tblSet = ps.executeQuery(sql); TableInfo info = null; Map<String, String> params = null; String priPartType = null; while (tblSet.next()) { //System.out.println("########################table name is " + tblSet.getString(3)); info = new TableInfo(); params = new HashMap<String, String>(); info.setCreateTime(tblSet.getString(1)); params.put("tbl_type", tblSet.getString(2)); info.setOwner(tblSet.getString(4)); priPartType = tblSet.getString(5); if (priPartType == null) { params.put("is_part_table", "no"); } else { params.put("is_part_table", "yes"); } info.setComment(tblSet.getString(6)); info.setTblParams(params); tblInfoMap.put(tblSet.getString(3), info); } } catch (SQLException sqlex) { LOG.error("get table error, db=" + dbName + ", pattern=" + pattern + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return tblInfoMap; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public Map<String, TableInfo> getTableWithTypeWithKeyWord(String dbName, String keyWord) throws MetaException { // TODO Auto-generated method stub Connection con; Statement ps = null;/* w ww .j a v a 2 s . c om*/ Map<String, TableInfo> tblInfoMap = new TreeMap<String, TableInfo>(); dbName = dbName.toLowerCase(); //pattern = pattern.toLowerCase(); try { con = getSegmentConnection(dbName); } catch (MetaStoreConnectException e1) { // TODO Auto-generated catch block LOG.error("get table error, db=" + dbName + ", key word=" + keyWord + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { // TODO Auto-generated catch block LOG.error("get table error, db=" + dbName + ", key word=" + keyWord + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = null; sql = "select create_time, tbl_type, tbl_name, tbl_owner, pri_part_type, tbl_comment from tbls where db_name='" + dbName + "'"; if (keyWord != null) { sql += " and (tbl_name ilike '%" + keyWord + "%' or tbl_comment ilike '%" + keyWord + "%')"; } ResultSet tblSet = ps.executeQuery(sql); TableInfo info = null; Map<String, String> params = null; String priPartType = null; while (tblSet.next()) { //System.out.println("########################table name is " + tblSet.getString(3)); info = new TableInfo(); params = new HashMap<String, String>(); info.setCreateTime(tblSet.getString(1)); params.put("tbl_type", tblSet.getString(2)); info.setOwner(tblSet.getString(4)); priPartType = tblSet.getString(5); if (priPartType == null) { params.put("is_part_table", "no"); } else { params.put("is_part_table", "yes"); } info.setComment(tblSet.getString(6)); info.setTblParams(params); tblInfoMap.put(tblSet.getString(3), info); } } catch (SQLException sqlex) { LOG.error("get table error, db=" + dbName + ", key word=" + keyWord + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return tblInfoMap; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public void modifyTableComment(String dbName, String tblName, String comment) throws InvalidOperationException, MetaException { Connection con = null; PreparedStatement ps = null;// ww w . j a v a 2s . com boolean success = false; dbName = dbName.toLowerCase(); tblName = tblName.toLowerCase(); try { con = getSegmentConnection(dbName); } catch (MetaStoreConnectException e1) { LOG.error("alter table comment error, db=" + dbName + ", tbl=" + tblName + ", comment=" + comment + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("alter table comment error, db=" + dbName + ", tbl=" + tblName + ", comment=" + comment + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); ps = con.prepareStatement("select tbl_id from tbls where db_name=? and tbl_name=?"); long tblID = 0; boolean isTblFind = false; ps.setString(1, dbName); ps.setString(2, tblName); ResultSet tSet = ps.executeQuery(); while (tSet.next()) { tblID = tSet.getLong(1); isTblFind = true; break; } tSet.close(); ps.close(); if (!isTblFind) { LOG.error("alter table comment error, db=" + dbName + ", tbl=" + tblName + ", comment=" + comment); throw new MetaException("can not find table " + dbName + ":" + tblName); } ps = con.prepareStatement("update tbls set tbl_comment=? where tbl_id=?"); ps.setString(1, comment); ps.setLong(2, tblID); ps.executeUpdate(); con.commit(); success = true; } catch (SQLException sqlex) { LOG.error("alter table comment error, db=" + dbName + ", tbl=" + tblName + ", comment=" + comment + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { if (!success) { try { con.rollback(); } catch (SQLException e) { } } closeStatement(ps); closeConnection(con); } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean revokeRoleFromRole(String roleName, List<String> roles) throws NoSuchObjectException, InvalidObjectException, MetaException { Connection con = null; ;/*from w ww . j ava 2s.c om*/ PreparedStatement ps = null; boolean success = false; roleName = roleName.toLowerCase(); List<String> roleLowerCase = new ArrayList<String>(roles.size()); for (String role : roles) { roleLowerCase.add(role.toLowerCase()); } try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("revoke role error, role=" + roleName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("revoke role error, role=" + roleName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); ps = con.prepareStatement("select role_name from tdwrole where role_name=?"); ps.setString(1, roleName.toLowerCase()); boolean isRoleFind = false; ResultSet roleSet = ps.executeQuery(); while (roleSet.next()) { isRoleFind = true; break; } roleSet.close(); ps.close(); if (!isRoleFind) { throw new NoSuchObjectException("can not find role:" + roleName); } ps = con.prepareStatement("delete from tdwsonrole where role_name=? and sonrole_name=?"); for (String role : roles) { ps.setString(1, roleName.toLowerCase()); ps.setString(2, role.toLowerCase()); ps.addBatch(); } ps.executeBatch(); con.commit(); success = true; } catch (SQLException sqlex) { LOG.error("revoke role error, role=" + roleName + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { if (!success) { try { con.rollback(); } catch (SQLException e) { } } closeStatement(ps); closeConnection(con); } return success; }