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 List<String> getPlayRoles(String userName) throws NoSuchObjectException, MetaException { Connection con = null; ;//from ww w .j a va 2 s .c o m Statement ps = null; List<String> roles = new ArrayList<String>(); userName = userName.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get roles error, msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get roles error, msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select role_name from tdwuserrole where user_name='" + userName + "'"; ResultSet roleSet = ps.executeQuery(sql); while (roleSet.next()) { roles.add(roleSet.getString(1)); } } catch (SQLException sqlex) { LOG.error("get roles error, msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return roles; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public List<String> getUsersAll() throws MetaException { Connection con = null; ;//from w w w . j av a 2 s . co m Statement ps = null; boolean success = false; List<String> users = new ArrayList<String>(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get user all error" + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get user all error" + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select user_name, group_name from tdwuser"; ResultSet userSet = ps.executeQuery(sql); while (userSet.next()) { users.add(userSet.getString(1) + " " + userSet.getString(2)); } userSet.close(); success = true; } catch (SQLException sqlex) { LOG.error("get user all error" + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } if (success == true) return users; else return null; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public String getGroupname(String userName) throws MetaException { Connection con = null; Statement ps = null;/*w w w . jav a 2 s. c om*/ String groupName = null; userName = userName.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get user group error, user=" + userName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get user group error, user=" + userName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select group_name from tdwuser where user_name='" + userName + "'"; ResultSet groupNameSet = ps.executeQuery(sql); while (groupNameSet.next()) { groupName = groupNameSet.getString(1); break; } } catch (SQLException sqlex) { LOG.error("get user group error, user=" + userName + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return groupName; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean isAUserName(String userName) throws NoSuchObjectException, MetaException { Connection con = null; Statement ps = null;//w w w . j ava2s. c o m boolean is = false; userName = userName.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("check user exist error, user=" + userName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("check user exist error, user=" + userName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select count(1) from tdwuser where user_name='" + userName + "'"; int count = 0; ResultSet uSet = ps.executeQuery(sql); while (uSet.next()) { count = uSet.getInt(1); break; } if (count == 1) { is = true; } } catch (SQLException sqlex) { LOG.error("check user exist error, user=" + userName + ", 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
public List<DbPriv> getDbAuthAllNoDistributeTransaction() throws MetaException { Connection con = null; Statement ps = null;/* www. j a v a 2 s. c o m*/ boolean success = false; List<DbPriv> dbPrivs = new ArrayList<DbPriv>(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get all user auth on dbs error, msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get all user auth on dbs error, 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, createview_priv, " + "delete_priv, drop_priv, index_priv, insert_priv, select_priv, " + "showview_priv, update_priv, db_name, user_name from dbpriv "; ResultSet dbPrivSet = ps.executeQuery(sql); while (dbPrivSet.next()) { DbPriv dbPriv = new DbPriv(); dbPriv.setAlterPriv(dbPrivSet.getBoolean(1)); dbPriv.setCreatePriv(dbPrivSet.getBoolean(2)); dbPriv.setCreateviewPriv(dbPrivSet.getBoolean(3)); dbPriv.setDeletePriv(dbPrivSet.getBoolean(4)); dbPriv.setDropPriv(dbPrivSet.getBoolean(5)); dbPriv.setIndexPriv(dbPrivSet.getBoolean(6)); dbPriv.setInsertPriv(dbPrivSet.getBoolean(7)); dbPriv.setSelectPriv(dbPrivSet.getBoolean(8)); dbPriv.setShowviewPriv(dbPrivSet.getBoolean(9)); dbPriv.setUpdatePriv(dbPrivSet.getBoolean(10)); dbPriv.setDb(dbPrivSet.getString(11)); dbPriv.setUser(dbPrivSet.getString(12)); dbPrivs.add(dbPriv); } success = true; } catch (SQLException sqlex) { LOG.error("get all user auth on dbs error, msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } if (success) { return dbPrivs; } else { return null; } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public List<TblPriv> getAuthOnAllTblsNoDistributeTransaction() throws MetaException { Connection con = null; Statement ps = null;//from ww w.j a v a2 s .co m boolean success = false; List<TblPriv> tblPrivs = new ArrayList<TblPriv>(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get user auth on all tbls error, msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get user auth on all tbls error, 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, user_name, db_name, tbl_name" + " from tblpriv"; ResultSet tblPrivSet = ps.executeQuery(sql); while (tblPrivSet.next()) { TblPriv tblPriv = new TblPriv(); tblPriv.setAlterPriv(tblPrivSet.getBoolean(1)); tblPriv.setCreatePriv(tblPrivSet.getBoolean(2)); tblPriv.setDeletePriv(tblPrivSet.getBoolean(3)); tblPriv.setDropPriv(tblPrivSet.getBoolean(4)); tblPriv.setIndexPriv(tblPrivSet.getBoolean(5)); tblPriv.setInsertPriv(tblPrivSet.getBoolean(6)); tblPriv.setSelectPriv(tblPrivSet.getBoolean(7)); tblPriv.setUpdatePriv(tblPrivSet.getBoolean(8)); tblPriv.setUser(tblPrivSet.getString(9)); tblPriv.setDb(tblPrivSet.getString(10)); tblPriv.setTbl(tblPrivSet.getString(11)); tblPrivs.add(tblPriv); } success = true; } catch (SQLException sqlex) { LOG.error("get user auth on all tbls error, msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } if (success) { return tblPrivs; } else { return null; } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public List<DbPriv> getDbAuth(String db) throws MetaException { Connection con = null; Statement ps = null;/*from w w w .j ava 2 s .c o m*/ List<DbPriv> dbPrivs = new ArrayList<DbPriv>(); db = db.toLowerCase(); try { con = getSegmentConnection(db); } catch (MetaStoreConnectException e1) { LOG.error("get auth on db error, db=" + db + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get auth on db error, db=" + db + ", 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, createview_priv, " + "delete_priv, drop_priv, index_priv, insert_priv, select_priv, " + "showview_priv, update_priv, user_name from dbpriv where db_name='" + db + "'"; ResultSet dbPrivSet = ps.executeQuery(sql); while (dbPrivSet.next()) { DbPriv dbPriv = new DbPriv(); dbPriv.setAlterPriv(dbPrivSet.getBoolean(1)); dbPriv.setCreatePriv(dbPrivSet.getBoolean(2)); dbPriv.setCreateviewPriv(dbPrivSet.getBoolean(3)); dbPriv.setDeletePriv(dbPrivSet.getBoolean(4)); dbPriv.setDropPriv(dbPrivSet.getBoolean(5)); dbPriv.setIndexPriv(dbPrivSet.getBoolean(6)); dbPriv.setInsertPriv(dbPrivSet.getBoolean(7)); dbPriv.setSelectPriv(dbPrivSet.getBoolean(8)); dbPriv.setShowviewPriv(dbPrivSet.getBoolean(9)); dbPriv.setUpdatePriv(dbPrivSet.getBoolean(10)); dbPriv.setUser(dbPrivSet.getString(11)); dbPriv.setDb(db); dbPrivs.add(dbPriv); } } catch (SQLException ex) { LOG.error("get auth on db error, db=" + db + ", msg=" + ex.getMessage()); ex.printStackTrace(); throw new MetaException(ex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return dbPrivs; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public Role getRole(String roleName) throws NoSuchObjectException, MetaException { Connection con = null; ;//from w w w .ja v a 2 s . co m Statement ps = null; Role role = null; roleName = roleName.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get role error, role=" + roleName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get role error, role=" + roleName + ", 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, createview_priv, dba_priv, " + "delete_priv, drop_priv, index_priv, insert_priv, select_priv, showview_priv, " + "update_priv, role_name from tdwrole where role_name='" + roleName + "'"; boolean isRoleFind = false; ResultSet roleSet = ps.executeQuery(sql); while (roleSet.next()) { isRoleFind = true; role = new Role(); role.setAlterPriv(roleSet.getBoolean(1)); role.setCreatePriv(roleSet.getBoolean(2)); role.setCreateviewPriv(roleSet.getBoolean(3)); role.setDbaPriv(roleSet.getBoolean(4)); role.setDeletePriv(roleSet.getBoolean(5)); role.setDropPriv(roleSet.getBoolean(6)); role.setIndexPriv(roleSet.getBoolean(7)); role.setInsertPriv(roleSet.getBoolean(8)); role.setSelectPriv(roleSet.getBoolean(9)); role.setShowviewPriv(roleSet.getBoolean(10)); role.setUpdatePriv(roleSet.getBoolean(11)); role.setRoleName(roleSet.getString(12)); break; } roleSet.close(); if (!isRoleFind) { throw new NoSuchObjectException("can not find role:" + roleName); } List<String> sonRoles = new ArrayList<String>(); role.setPlayRoles(sonRoles); } catch (SQLException sqlex) { LOG.error("revoke role error, role=" + roleName + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return role; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public User getUser(String userName) throws NoSuchObjectException, MetaException { Connection con = null; ;//w w w . jav a 2 s . c o m Statement ps = null; User user = null; userName = userName.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get user error, user=" + user + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get user error, user=" + user + ", 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, createview_priv, dba_priv, " + "delete_priv, drop_priv, index_priv, insert_priv, select_priv, showview_priv, " + "update_priv, user_name, group_name from tdwuser where tdwuser.user_name='" + userName + "'"; ResultSet userSet = ps.executeQuery(sql); boolean isUserFind = false; while (userSet.next()) { isUserFind = true; user = new User(); user.setAlterPriv(userSet.getBoolean(1)); user.setCreatePriv(userSet.getBoolean(2)); user.setCreateviewPriv(userSet.getBoolean(3)); user.setDbaPriv(userSet.getBoolean(4)); user.setDeletePriv(userSet.getBoolean(5)); user.setDropPriv(userSet.getBoolean(6)); user.setIndexPriv(userSet.getBoolean(7)); user.setInsertPriv(userSet.getBoolean(8)); user.setSelectPriv(userSet.getBoolean(9)); user.setShowviewPriv(userSet.getBoolean(10)); user.setUpdatePriv(userSet.getBoolean(11)); user.setUserName(userSet.getString(12)); user.setGroupName(userSet.getString(13)); } userSet.close(); if (!isUserFind) { throw new NoSuchObjectException("can not find user:" + userName); } sql = "select role_name from tdwuserrole where user_name='" + userName + "'"; ResultSet roleSet = ps.executeQuery(sql); List<String> roleList = new ArrayList<String>(); while (roleSet.next()) { roleList.add(roleSet.getString(1)); } roleSet.close(); user.setPlayRoles(roleList); } catch (SQLException sqlex) { LOG.error("get user error, user=" + user + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return user; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public boolean dropAuthInTblNoDistributeTransaction(String who) throws MetaException { Connection con = null; Statement ps = null;//w w w.j ava 2 s . com boolean success = false; who = who.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("drop auth in tbl error, who=" + who + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("drop auth in tbl error, who=" + who + ", 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 + "'"; ps = con.createStatement(); ps.executeUpdate(sql); con.commit(); success = true; } catch (SQLException sqlex) { LOG.error("drop auth in tbl error, who=" + who + ", 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; }