@Override public String getConnectionInfoMessage(String connectionToken) throws IllegalArgumentException, DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Connection conn = connMgr.getConnection(connectionToken, clientIP, userAgent); String db = ""; String user = ""; try { db = conn.getCatalog(); user = conn.getMetaData().getUserName(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } String ret = db + " as " + user; return ret; }
@Override public String createSequence( String connectionToken, int schema, String sequenceName, boolean temporary, int increment, int minValue, int maxValue, int start, int cache, boolean cycle) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Sequences sequences = new Sequences(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return sequences.create( schema, sequenceName, temporary, increment, minValue, maxValue, start, cache, cycle); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String renameItem(String connectionToken, int item, ITEM_TYPE type, String newName) throws IllegalArgumentException, DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); try { switch (type) { case FOREIGN_TABLE: ForeignTables fTables = new ForeignTables(connMgr.getConnection(connectionToken, clientIP, userAgent)); return fTables.rename(item, type, q.addQuote(newName)); case TABLE: Tables tables = new Tables(connMgr.getConnection(connectionToken, clientIP, userAgent)); return tables.rename(item, type, q.addQuote(newName)); case VIEW: case MATERIALIZED_VIEW: Views views = new Views(connMgr.getConnection(connectionToken, clientIP, userAgent)); return views.rename(item, type, newName); default: return ""; } } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String createForeignKeyConstraint( String connectionToken, int item, String constraintName, ArrayList<String> columnList, String referenceTable, ArrayList<String> referenceList) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Constraints constraints; constraints = new Constraints(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return constraints.createForeignKeyConstraint( item, constraintName, columnList, referenceTable, referenceList); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public void doLogout(String connectionToken, String source) throws DatabaseConnectionException { /*The argument source keeps a track of the origin of the doLogout call. * doLogout strictly works with three strings , viz: * WINDOW_CLOSE : pass this when logging out due to a window/tab close action * USER_INITIATED : pass this when logging out from the Disconnect button * SESSION_TIMEOUT : pass this when logging out due to timeout. */ HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); ConnectionManager connMgr = new ConnectionManager(); connMgr.closeConnection(connectionToken, clientIP, userAgent); if (request.getSession(false) != null) { if (source.equals("WINDOW_CLOSE")) { request.getSession(false).invalidate(); } else if (source.equals("USER_INITIATED") || source.equals("SESSION_TIMEOUT")) { request.getSession(false).setAttribute("dbToken", null); request.getSession(false).setAttribute("dbName", null); request.getSession(false).setAttribute("dbURL", null); request.getSession(false).setAttribute("username", null); } } }
@Override public String createRule( String connectionToken, int item, ITEM_TYPE type, String ruleName, String event, String ruleType, String definition) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Rules rules; rules = new Rules(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return rules.createRule(item, type, ruleName, event, ruleType, definition); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String createFunction( String connectionToken, int schema, String functionName, String returns, String language, ArrayList<String> paramList, String definition) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Functions funcs; funcs = new Functions(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return funcs.create(schema, functionName, returns, language, paramList, definition); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String createTrigger( String connectionToken, int item, ITEM_TYPE type, String triggerName, String event, String triggerType, String forEach, String function) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Triggers triggers = new Triggers(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return triggers.createTrigger(item, type, triggerName, event, triggerType, forEach, function); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String getList(String connectionToken, DATABASE_OBJECT_TYPE type) throws IllegalArgumentException, DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Database db; switch (type) { case DATA_TYPE: db = new Database(connMgr.getConnection(connectionToken, clientIP, userAgent)); return db.getDataTypes(); case FOREIGN_SERVER: db = new Database(connMgr.getConnection(connectionToken, clientIP, userAgent)); return db.getForeignServerList(); case SCHEMA: Schemas schemas = new Schemas(connMgr.getConnection(connectionToken, clientIP, userAgent)); return schemas.getList(); case LANGUAGE: db = new Database(connMgr.getConnection(connectionToken, clientIP, userAgent)); return db.getLanguageList(); case ROLE: db = new Database(connMgr.getConnection(connectionToken, clientIP, userAgent)); return db.getRoleList(); default: return ""; } }
@Override public String createTable( String connectionToken, int schema, String tableName, boolean unlogged, boolean temporary, String fill, ArrayList<String> col_list, HashMap<Integer, String> commentLog, ArrayList<String> col_index) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Tables tables = new Tables(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return tables.create( schema, q.addQuote(tableName), unlogged, temporary, fill, col_list, commentLog, col_index); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String createColumn( String connectionToken, int item, String columnName, String datatype, String comment, boolean not_null, String defaultval) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Columns columns; columns = new Columns(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return columns.create(item, q.addQuote(columnName), datatype, comment, not_null, defaultval); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String getItemObjectList( String connectionToken, int item, ITEM_TYPE type, ITEM_OBJECT_TYPE object) throws IllegalArgumentException, DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); try { switch (object) { case TRIGGER: Triggers triggers = new Triggers(connMgr.getConnection(connectionToken, clientIP, userAgent)); return triggers.getList(item); case COLUMN: Columns columns = new Columns(connMgr.getConnection(connectionToken, clientIP, userAgent)); return columns.getList(item); case CONSTRAINT: Constraints constraints = new Constraints(connMgr.getConnection(connectionToken, clientIP, userAgent)); return constraints.getList(item); case GRANT: Privileges priv = new Privileges(connMgr.getConnection(connectionToken, clientIP, userAgent)); return priv.getPrivileges(item, type); case INDEX: Indexes indexes = new Indexes(connMgr.getConnection(connectionToken, clientIP, userAgent)); return indexes.getList(item); case RULE: Rules rules = new Rules(connMgr.getConnection(connectionToken, clientIP, userAgent)); return rules.getList(item); case SOURCE: SourceCode sc = new SourceCode(connMgr.getConnection(connectionToken, clientIP, userAgent)); return sc.getSourceCode(item, type); case STATS: Stats stats = new Stats(connMgr.getConnection(connectionToken, clientIP, userAgent)); return stats.getList(item); default: return ""; } } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
/** * ******************************************************************************************** */ @Override public String refreshMaterializedView(String connectionToken, String schema, String viewName) throws DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Views views = new Views(connMgr.getConnection(connectionToken, clientIP, userAgent)); return views.refreshMaterializedView(schema, q.addQuote(viewName)); }
@Override public String getExplainResult(String connectionToken, String query) throws IllegalArgumentException, DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); ItemData id; id = new ItemData(connMgr.getConnection(connectionToken, clientIP, userAgent)); return id.getExplainResult(query); }
@Override public String createSchema(String connectionToken, String schemaName) throws DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Schemas schemas; schemas = new Schemas(connMgr.getConnection(connectionToken, clientIP, userAgent)); return schemas.createSchema(schemaName); }
@Override public String executeQuery(String connectionToken, String query, String queryType) throws IllegalArgumentException, DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); QueryExecutor id; id = new QueryExecutor(connMgr.getConnection(connectionToken, clientIP, userAgent)); return id.Execute(query, queryType); }
@Override public String truncate(String connectionToken, int item, ITEM_TYPE type) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Tables tables = new Tables(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return tables.truncate(item, type); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String renameItemObject( String connectionToken, int item, ITEM_TYPE type, String objectName, ITEM_OBJECT_TYPE objType, String newObjectName) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); try { switch (objType) { case COLUMN: Columns columns = new Columns(connMgr.getConnection(connectionToken, clientIP, userAgent)); return columns.rename(item, q.addQuote(objectName), q.addQuote(newObjectName)); case CONSTRAINT: Constraints constraints = new Constraints(connMgr.getConnection(connectionToken, clientIP, userAgent)); return constraints.rename(item, q.addQuote(objectName), q.addQuote(newObjectName)); case INDEX: Indexes indexes = new Indexes(connMgr.getConnection(connectionToken, clientIP, userAgent)); return indexes.rename(item, q.addQuote(objectName), q.addQuote(newObjectName)); case RULE: // A RULE can not be renamed so just return a blank string if if get // here for some reason return ""; case TRIGGER: Triggers triggers = new Triggers(connMgr.getConnection(connectionToken, clientIP, userAgent)); return triggers.rename(item, q.addQuote(objectName), q.addQuote(newObjectName)); default: return ""; } } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String getTriggerFunctionList(String connectionToken, int schema) throws IllegalArgumentException, DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Functions funcs; funcs = new Functions(connMgr.getConnection(connectionToken, clientIP, userAgent)); String funcList = funcs.getTriggerFunctionList(schema); return funcList; }
@Override public String getItemMetaData(String connectionToken, int item, ITEM_TYPE type) throws IllegalArgumentException, DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); ItemMetaData id = new ItemMetaData(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return id.getMetaData(item, type); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String dropItem(String connectionToken, int item, ITEM_TYPE type, boolean cascade) throws IllegalArgumentException, DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); try { switch (type) { case FOREIGN_TABLE: ForeignTables fTables = new ForeignTables(connMgr.getConnection(connectionToken, clientIP, userAgent)); return fTables.drop(item, cascade); case TABLE: Tables tables = new Tables(connMgr.getConnection(connectionToken, clientIP, userAgent)); return tables.drop(item, cascade); case VIEW: case MATERIALIZED_VIEW: boolean isMaterialized = false; if (type == ITEM_TYPE.MATERIALIZED_VIEW) isMaterialized = true; Views views = new Views(connMgr.getConnection(connectionToken, clientIP, userAgent)); return views.dropView(item, cascade, isMaterialized); case FUNCTION: Functions functions = new Functions(connMgr.getConnection(connectionToken, clientIP, userAgent)); return functions.dropFunction(item, cascade); case SEQUENCE: Sequences sequences = new Sequences(connMgr.getConnection(connectionToken, clientIP, userAgent)); return sequences.drop(item, cascade); case TYPE: Types types = new Types(connMgr.getConnection(connectionToken, clientIP, userAgent)); return types.dropType(item, cascade); default: return ""; } } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String createCheckConstraint( String connectionToken, int item, String constraintName, String definition) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Constraints constraints; constraints = new Constraints(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return constraints.createCheckConstraint(item, constraintName, definition); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String grant( String connectionToken, int item, ITEM_TYPE type, ArrayList<String> privileges, String grantee) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Privileges priv = new Privileges(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return priv.grant(item, type, privileges, grantee); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }
@Override public String createType( String connectionToken, String schema, String typeName, TYPE_FORM form, String baseType, String definition, ArrayList<String> attributeList) throws DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Types types; types = new Types(connMgr.getConnection(connectionToken, clientIP, userAgent)); return types.createType( connectionToken, schema, typeName, form, baseType, definition, attributeList); }
@Override public String getList(String connectionToken, int schema, ITEM_TYPE type) throws IllegalArgumentException, DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); switch (type) { case TABLE: Tables tables = new Tables(connMgr.getConnection(connectionToken, clientIP, userAgent)); return tables.getList(schema); case MATERIALIZED_VIEW: case VIEW: Views views = new Views(connMgr.getConnection(connectionToken, clientIP, userAgent)); return views.getList(schema); case FOREIGN_TABLE: ForeignTables fTables = new ForeignTables(connMgr.getConnection(connectionToken, clientIP, userAgent)); return fTables.getList(schema); case FUNCTION: Functions funcs = new Functions(connMgr.getConnection(connectionToken, clientIP, userAgent)); return funcs.getList(schema); case SEQUENCE: Sequences seqs = new Sequences(connMgr.getConnection(connectionToken, clientIP, userAgent)); return seqs.getList(schema); case TYPE: Types types = new Types(connMgr.getConnection(connectionToken, clientIP, userAgent)); return types.getList(schema); default: return ""; } }
@Override public String createForeignTable( String connectionToken, String schema, String tableName, String server, ArrayList<String> columns, HashMap<Integer, String> comments, ArrayList<String> options) throws IllegalArgumentException, DatabaseConnectionException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); ForeignTables tables; tables = new ForeignTables(connMgr.getConnection(connectionToken, clientIP, userAgent)); return tables.createForeignTable( connectionToken, schema, tableName, server, columns, comments, options); }
@Override public String createIndex( String connectionToken, int item, String indexName, INDEX_TYPE indexType, boolean isUnique, boolean isConcurrently, ArrayList<String> columnList) throws DatabaseConnectionException, PostgreSQLException { ConnectionManager connMgr = new ConnectionManager(); HttpServletRequest request = this.getThreadLocalRequest(); String clientIP = ConnectionInfo.remoteAddr(request); String userAgent = request.getHeader("User-Agent"); Indexes indexes = new Indexes(connMgr.getConnection(connectionToken, clientIP, userAgent)); try { return indexes.create(item, indexName, indexType, isUnique, isConcurrently, columnList); } catch (SQLException e) { throw new PostgreSQLException(e.getMessage()); } }