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 MGroup findGroup(String gname) throws MetaException { Connection con = null; ;/* w w w . j av a2 s . c o m*/ Statement ps = null; boolean success = false; MGroup group = null; gname = gname.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("create user error, user=" + user + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("create user error, user=" + user + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select creator from usergroup where group_name='" + gname + "'"; ResultSet groupSet = ps.executeQuery(sql); while (groupSet.next()) { group = new MGroup(); group.setCreator(groupSet.getString(1)); group.setGroupName(gname); } groupSet.close(); if (group != null) { sql = "select string_agg(tdwuser.user_name, ',') namelist from tdwuser where group_name='" + gname + "'"; ResultSet userSet = ps.executeQuery(sql); while (userSet.next()) { group.setUSER_LIST(userSet.getString(1)); } userSet.close(); } con.commit(); success = true; } catch (SQLException sqlex) { LOG.error("create user error, user=" + user + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { if (!success) { try { con.rollback(); } catch (SQLException e) { } } closeStatement(ps); closeConnection(con); } return group; }
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; Statement ps = null;// ww w . ja v a 2 s . c o m 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
@Override public boolean isTableExit(String dbName, String tblName) throws MetaException { Connection con = null; ;/*from w w w . ja v a 2s. c om*/ Statement ps = null; boolean ret = false; dbName = dbName.toLowerCase(); tblName = tblName.toLowerCase(); try { con = getSegmentConnection(dbName); } catch (MetaStoreConnectException e1) { LOG.error("check table exist error, db=" + dbName + ", tbl=" + tblName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("check table exist 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_id tbls where db_name='" + dbName + "' " + " and tbl_name='" + tblName + "'"; ResultSet tblSet = ps.executeQuery(sql); while (tblSet.next()) { ret = true; } } catch (SQLException sqlex) { LOG.error("check table exist error, db=" + dbName + ", tbl=" + tblName + ", msg=" + sqlex.getMessage()); sqlex.printStackTrace(); throw new MetaException(sqlex.getMessage()); } finally { closeStatement(ps); closeConnection(con); } return ret; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean isAUser(String userName, String passwd) throws MetaException { Connection con = null; ;//from www. j a v a 2 s. co m Statement ps = null; boolean success = false; userName = userName.toLowerCase(); passwd = passwd.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("audit error, user=" + userName + ", passwd=" + passwd + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("audit error, user=" + userName + ", passwd=" + passwd + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select user_name, passwd from tdwuser where user_name='" + userName + "'"; String actualPass = null; boolean isUserFind = false; ResultSet userSet = ps.executeQuery(sql); while (userSet.next()) { isUserFind = true; actualPass = userSet.getString(2); break; } userSet.close(); if (!isUserFind) { throw new NoSuchObjectException("can not find user:" + userName); } if (actualPass == null || !actualPass.equals(passwd)) { throw new MetaException("audit failed, password error!"); } success = true; } catch (Exception ex) { LOG.error("audit error, user=" + userName + ", passwd=" + passwd + ", msg=" + ex.getMessage()); ex.printStackTrace(); } finally { closeStatement(ps); closeConnection(con); } return success; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public List<DbPriv> getAuthOnDbsNoDistributeTransaction(String who) throws MetaException { Connection con = null; Statement ps = null;/* w w w . j a va 2 s . c o m*/ 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
@Override public boolean dropAuthOnDb(String who, String db) throws MetaException { Connection con = null; PreparedStatement ps = null;/*from w ww . j av a 2 s . c o m*/ boolean success = false; who = who.toLowerCase(); db = db.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error("drop auth on db error, who=" + who + ", db=" + db + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("drop auth on db error, who=" + who + ", db=" + db + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); ps = con.prepareStatement("delete from dbpriv where user_name=? and db_name=?"); ps.setString(1, who); ps.setString(2, db); ps.executeUpdate(); con.commit(); success = true; } catch (SQLException ex) { LOG.error("drop auth on db error, who=" + who + ", db=" + db + ", 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
public List<TblPriv> getAuthOnTblsNoDistributeTransaction(String who) throws MetaException { Connection con = null; Statement ps = null;/*w ww.j ava 2 s .c o m*/ 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; } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public boolean isPBTable(String dbName, String tableName) throws MetaException { Connection con = null; PreparedStatement ps = null;//w ww .j a v a 2 s .com dbName = dbName.toLowerCase(); tableName = tableName.toLowerCase(); try { con = getSegmentConnection(dbName); } catch (MetaStoreConnectException e1) { LOG.error("isPBTable, db=" + dbName + ", table=" + tableName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error("isPBTable error, db=" + dbName + ", table=" + tableName + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setAutoCommit(false); con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); ps = con.prepareStatement("select serde_lib" + " from tbls where db_name=? and tbl_name=?"); ps.setString(1, dbName); ps.setString(2, tableName); String serdeLib = null; boolean isTblFind = false; ResultSet tblSet = ps.executeQuery(); while (tblSet.next()) { isTblFind = true; serdeLib = tblSet.getString(1); } tblSet.close(); ps.close(); if (!isTblFind) { throw new MetaException("can not find table " + dbName + ":" + tableName); } closeStatement(ps); closeConnection(con); if (serdeLib.equals(ProtobufSerDe.class.getName())) return true; else return false; } catch (SQLException ex) { ex.printStackTrace(); closeStatement(ps); closeConnection(con); LOG.error("updatePBInfo, db=" + dbName + ", tbl=" + tableName + ", msg=" + ex.getMessage()); throw new MetaException(ex.getMessage()); } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
@Override public List<String> getJdbcTables(String dbName, String pattern) throws MetaException { Connection con; Statement ps = null;//w ww . j a v a2 s .c o m List<String> tableList = new ArrayList<String>(); dbName = dbName.toLowerCase(); pattern = pattern.toLowerCase(); try { con = getSegmentConnection(dbName); } catch (MetaStoreConnectException e1) { LOG.error("get table error, db=" + dbName + ", pattern=" + pattern + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { 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 tbl_name, tbl_type from tbls where db_name='" + dbName + "'"; } else { pattern = pattern.replace('*', '%'); sql = "select tbl_name, tbl_type from tbls where db_name='" + dbName + "'" + " and tbl_name like '" + pattern + "'"; } ResultSet tblSet = ps.executeQuery(sql); while (tblSet.next()) { String item = tblSet.getString(1) + ":" + tblSet.getString(2); tableList.add(item); } } 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 tableList; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public boolean isAUser(String userName) throws MetaException { Connection con = null; ;//from ww w . j ava2s.co m Statement ps = null; boolean success = false; userName = userName.toLowerCase(); try { con = getGlobalConnection(); } catch (MetaStoreConnectException e1) { LOG.error( "check user exist error, user=" + userName + ", passwd=" + passwd + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } catch (SQLException e1) { LOG.error( "check user exist error, user=" + userName + ", passwd=" + passwd + ", msg=" + e1.getMessage()); throw new MetaException(e1.getMessage()); } try { con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ps = con.createStatement(); String sql = "select user_name from tdwuser where user_name='" + userName + "'"; boolean isUserFind = false; ResultSet userSet = ps.executeQuery(sql); while (userSet.next()) { isUserFind = true; break; } userSet.close(); if (!isUserFind) { throw new NoSuchObjectException("can not find user:" + userName); } success = true; } catch (Exception ex) { LOG.error( "check user exist error, user=" + userName + ", passwd=" + passwd + ", msg=" + ex.getMessage()); ex.printStackTrace(); } finally { closeStatement(ps); closeConnection(con); } return success; }