List of usage examples for java.sql Connection TRANSACTION_READ_COMMITTED
int TRANSACTION_READ_COMMITTED
To view the source code for java.sql Connection TRANSACTION_READ_COMMITTED.
Click Source Link
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean isARole(String roleName) throws MetaException { Connection con = null;/*from w w w. j a v a 2 s .com*/ ; Statement ps = null; boolean success = false; roleName = roleName.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("check role error, role=" + roleName + ", passwd=" + passwd + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("check role error, role=" + roleName + ", passwd=" + passwd + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select role_name from tdwrole where role_name='" + roleName + "'"; boolean isRoleFind = false; ResultSet userSet = ps.executeQuery(sql); while (userSet.next()) { isRoleFind = true; break; } userSet.close(); if (!isRoleFind) { throw new NoSuchObjectException("can not find user:" + roleName); } success = true; } catch (Exception ex) { LOG.error("check role error, role=" + roleName + ", passwd=" + passwd + ", msg=" + ex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return success; }
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 .j a v a 2 s.c om ; 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 List<String> getRolesAll() throws MetaException { Connection con = null;//from www . j av a 2s.c om ; Statement ps = null; List<String> roles = new ArrayList<String>(); 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 tdwrole"; 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 DbPriv getAuthOnDb(String who, String db) throws MetaException { Connection con = null;/*from w w w. ja va 2 s . c om*/ Statement ps = null; DbPriv dbPriv = null; who = who.toLowerCase(); db = db.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get auth on db error, db=" + db + ", forwho=" + who + ", msg=" + e1.getMessage()); throw new MetaException("can not find db:" + db); } catch (SQLException e1) { LOG.error("get auth on db error, db=" + db + ", forwho=" + 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, createview_priv, " + "delete_priv, drop_priv, index_priv, insert_priv, select_priv, " + "showview_priv, update_priv from dbpriv where user_name='" + who + "' and db_name='" + db + "'"; ResultSet dbPrivSet = ps.executeQuery(sql); while (dbPrivSet.next()) { 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(db); dbPriv.setUser(who); break; } } catch (SQLException ex) { LOG.error("get auth on db error, db=" + db + ", forwho=" + who + ", msg=" + ex.getMessage()); ex.printStackTrace(); throw new MetaException(ex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return dbPriv; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public List<DbPriv> getDbAuth(String db) throws MetaException { Connection con = null;//ww w . ja va 2 s . com Statement ps = null; 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
public List<DbPriv> getAuthOnDbsNoDistributeTransaction(String who) throws MetaException { Connection con = null;//from w ww. j av a 2s .com Statement ps = null; boolean success = false; List<DbPriv> dbPrivs = new ArrayList<DbPriv>(); who = who.toLowerCase(); success = false; try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get user auth on dbs error, user=" + who + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get user auth on dbs error, user=" + 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, createview_priv, " + "delete_priv, drop_priv, index_priv, insert_priv, select_priv, " + "showview_priv, update_priv, db_name from dbpriv where user_name='" + who + "' order by db_name asc"; 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(who); dbPrivs.add(dbPriv); } success = true; } catch (SQLException sqlex) { LOG.error("get user auth on dbs error, user=" + who + ", 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<DbPriv> getDbAuthAllNoDistributeTransaction() throws MetaException { Connection con = null;//from w w w . ja v a 2 s . co m Statement ps = null; 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
@Override public TblPriv getAuthOnTbl(String who, String db, String tbl) throws MetaException { boolean success = false; Connection con;/*from ww w. j a v a 2 s .c o m*/ Statement ps = null; 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 List<TblPriv> getTblAuth(String db, String tbl) throws MetaException { boolean success = false; Connection con;//from w w w .jav a2 s. c om Statement ps = null; List<TblPriv> tblPrivs = new ArrayList<TblPriv>(); db = db.toLowerCase(); tbl = tbl.toLowerCase(); try { con = getSegmentConnection(db); } catch (MetaStoreConnectException e1) { LOG.error("get table auth error, db=" + db + ", tbl=" + tbl + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get table auth error, db=" + db + ", tbl=" + tbl + ", 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" + " from tblpriv where db_name='" + db + "' and tbl_name='" + tbl + "'"; ResultSet tblSet = ps.executeQuery(sql); while (tblSet.next()) { TblPriv 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(tblSet.getString(9)); tblPrivs.add(tblPriv); } success = true; } catch (SQLException sqlex) { LOG.error("get table auth error, db=" + db + ", tbl=" + tbl + ", 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
public List<TblPriv> getAuthOnTblsNoDistributeTransaction(String who) throws MetaException { Connection con = null;/* ww w. j a va 2 s.co m*/ Statement ps = null; boolean success = false; List<TblPriv> tblPrivs = new ArrayList<TblPriv>(); who = who.toLowerCase(); success = false; try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("get user auth on tbls error, user=" + who + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("get user auth on tbls error, user=" + 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, db_name, tbl_name" + " from tblpriv where user_name='" + who + "' order by db_name asc, tbl_name asc"; 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.setDb(tblPrivSet.getString(9)); tblPriv.setTbl(tblPrivSet.getString(10)); tblPriv.setUser(who); tblPrivs.add(tblPriv); } success = true; } catch (SQLException sqlex) { LOG.error("get user auth on tbls error, user=" + who + ", msg=" + sqlex.getMessage()); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } if (success) { return tblPrivs; } else { return null; } }