? RenameFunction.diff
? build
? dist
? docs
? src/com/redhat/rhdb/admin/.nbattrs
? src/com/redhat/rhdb/admin/resources/.nbattrs
? src/com/redhat/rhdb/admin/resources/Resources.java
? src/com/redhat/rhdb/admin/resources/Resources_ja_JP.java
? src/com/redhat/rhdb/admin/resources/Resources_ru_RU.java
Index: ChangeLog
===================================================================
RCS file: /cvs/rhdb/src/rhdb/guitools/rhdb-admin/ChangeLog,v
retrieving revision 1.2
diff -c -r1.2 ChangeLog
*** ChangeLog	23 Dec 2003 16:50:03 -0000	1.2
--- ChangeLog	29 Dec 2003 15:19:22 -0000
***************
*** 1,3 ****
--- 1,20 ----
+ 2003-12-29  Benjamin Mar Kuck  <binary_data@hotmail.com>
+ 
+ 	* src/com/redhat/rhdb/admin/FunctionUpdate.java (renameFunction):
+ 	Add new function to rename functions.
+ 	* src/com/redhat/rhdb/admin/RenameDialog.java (doOKAction): Add
+ 	handling for renaming functions.
+ 	(RenameDialog): Add handling for putting function name, embedded
+ 	in signature, in rename dialog.
+ 	* src/com/redhat/rhdb/admin/resources/AdminResources.java: Add new
+ 	Strings.
+ 	* src/com/redhat/rhdb/admin/resources/Resources.java.in: Add new
+ 	function menu string.
+ 	* src/com/redhat/rhdb/admin/tree/FunctionNode.java (doMenuAction):
+ 	Add handling for renaming of functions.
+ 	(getName): Add new function to retrieve the name of a function.
+ 	(getNodeMenu): Add new menu option for renaming functions.
+ 
  2003-12-19  Deepak Bhole  <ibetthisidisavailable@yahoo.ca>
  
  	* src/com/redhat/rhdb/admin/AdminBackendClient.java
Index: src/com/redhat/rhdb/admin/FunctionUpdate.java
===================================================================
RCS file: /cvs/rhdb/src/rhdb/guitools/rhdb-admin/src/com/redhat/rhdb/admin/FunctionUpdate.java,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 FunctionUpdate.java
*** src/com/redhat/rhdb/admin/FunctionUpdate.java	21 Nov 2003 18:30:23 -0000	1.1.1.1
--- src/com/redhat/rhdb/admin/FunctionUpdate.java	29 Dec 2003 15:19:24 -0000
***************
*** 180,185 ****
--- 180,213 ----
  	}
  		
  	/**
+ 	 * Renames a function
+ 	 *
+ 	 * @param client The backend client.
+ 	 * @param node the invoking function node.
+ 	 * @param name the new name of the function.
+ 	 * @throws ObjectUpdateException if the function cannot be renamed.
+ 	 */
+ 
+ 	public static void renameFunction(AdminBackendClient client, FunctionNode node, String name) throws ObjectUpdateException {
+ 
+ 		String updateString = "ALTER FUNCTION ";
+ 		
+ 		updateString += AdminMiscFunctions.getDoubleQuotedIdentifier(node.getParentSchemaName()) + ".";
+ 		updateString += node.getQuotedSignature();
+ 		
+ 		updateString += " RENAME TO " + name;
+ 		
+ 		// perform the update. Any errors are passed to the parent
+ 
+ 		try {
+ 			client.performUpdate(node.getParentClusterName(), node.getParentDatabaseName(), updateString);
+ 		} catch (Exception e) {
+ 			throw new ObjectUpdateException(e.getMessage());
+ 		}	
+ 	
+ 	}
+ 
+         /**
  	 * Comments on a function
  	 *
  	 * @param client The backend client.
Index: src/com/redhat/rhdb/admin/RenameDialog.java
===================================================================
RCS file: /cvs/rhdb/src/rhdb/guitools/rhdb-admin/src/com/redhat/rhdb/admin/RenameDialog.java,v
retrieving revision 1.2
diff -c -r1.2 RenameDialog.java
*** src/com/redhat/rhdb/admin/RenameDialog.java	23 Dec 2003 16:50:03 -0000	1.2
--- src/com/redhat/rhdb/admin/RenameDialog.java	29 Dec 2003 15:19:26 -0000
***************
*** 46,58 ****
          
          // update title and name box
  		
!         // Some nodes such as Operator Classes have names embedded inside the 
!         // signature. We need to put it in the rename dialog appropriately.
  		
          String name = invocationNode.toString();
  		
          if (invocationNode instanceof OperatorClassNode) {
  			name = ((OperatorClassNode) invocationNode).getName();
          }
  
          setTitle(AdminResources.getString(AdminResources.DLG_RENAME_TITLE, objectType.toUpperCase(), name));
--- 46,61 ----
          
          // update title and name box
  		
!         // Some nodes such as Operator Classes and Functions have names embedded
!         // inside the signature. We need to put it in the rename dialog
!         // appropriately.
  		
          String name = invocationNode.toString();
  		
          if (invocationNode instanceof OperatorClassNode) {
  			name = ((OperatorClassNode) invocationNode).getName();
+         } else if (invocationNode instanceof FunctionNode) {
+                         name = ((FunctionNode) invocationNode).getName(backendClient);
          }
  
          setTitle(AdminResources.getString(AdminResources.DLG_RENAME_TITLE, objectType.toUpperCase(), name));
***************
*** 232,237 ****
--- 235,242 ----
  			GroupUpdate.renameGroup(backendClient, (GroupNode) invocationNode, quotedName);
  		else if (invocationNode instanceof UserNode)
  			UserUpdate.renameUser(backendClient, (UserNode) invocationNode, quotedName);
+ 		else if (invocationNode instanceof FunctionNode)
+ 			FunctionUpdate.renameFunction(backendClient, (FunctionNode) invocationNode, quotedName);
  
  		// Reached here => all went well
  		
Index: src/com/redhat/rhdb/admin/resources/AdminResources.java
===================================================================
RCS file: /cvs/rhdb/src/rhdb/guitools/rhdb-admin/src/com/redhat/rhdb/admin/resources/AdminResources.java,v
retrieving revision 1.2
diff -c -r1.2 AdminResources.java
*** src/com/redhat/rhdb/admin/resources/AdminResources.java	23 Dec 2003 16:50:03 -0000	1.2
--- src/com/redhat/rhdb/admin/resources/AdminResources.java	29 Dec 2003 15:19:42 -0000
***************
*** 295,300 ****
--- 295,301 ----
  	public static final String MENU_RENAME_VIEW			= "rename.view";
  	public static final String MENU_RENAME_TRIGGER			= "rename.trigger";
  	public static final String MENU_RENAME_USER = "menu.rename.user";
+ 	public static final String MENU_RENAME_FUNCTION		= "menu.rename.function";
  	public static final String MENU_REPLACE_FUNCTION			= "replace.function";
  	public static final String MENU_REPLACE_RULE		= "replace.rule";
  	public static final String MENU_REPLACE_VIEW		= "replace.view";
Index: src/com/redhat/rhdb/admin/resources/Resources.java.in
===================================================================
RCS file: /cvs/rhdb/src/rhdb/guitools/rhdb-admin/src/com/redhat/rhdb/admin/resources/Resources.java.in,v
retrieving revision 1.2
diff -c -r1.2 Resources.java.in
*** src/com/redhat/rhdb/admin/resources/Resources.java.in	23 Dec 2003 16:50:03 -0000	1.2
--- src/com/redhat/rhdb/admin/resources/Resources.java.in	29 Dec 2003 15:19:57 -0000
***************
*** 294,299 ****
--- 294,300 ----
  		{ AdminResources.MENU_RENAME_TABLE, "RENAME TABLE..."},
  		{ AdminResources.MENU_RENAME_USER, "RENAME USER..." },
  		{ AdminResources.MENU_RENAME_VIEW,      "RENAME VIEW..." },
+ 		{ AdminResources.MENU_RENAME_FUNCTION, "RENAME FUNCTION..."},
  		{ AdminResources.MENU_REPLACE_FUNCTION,     "REPLACE FUNCTION..." },
  		{ AdminResources.MENU_REPLACE_RULE,     "REPLACE RULE..." },
  		{ AdminResources.MENU_REPLACE_VIEW,     "REPLACE VIEW..." },
Index: src/com/redhat/rhdb/admin/tree/FunctionNode.java
===================================================================
RCS file: /cvs/rhdb/src/rhdb/guitools/rhdb-admin/src/com/redhat/rhdb/admin/tree/FunctionNode.java,v
retrieving revision 1.2
diff -c -r1.2 FunctionNode.java
*** src/com/redhat/rhdb/admin/tree/FunctionNode.java	23 Dec 2003 16:50:04 -0000	1.2
--- src/com/redhat/rhdb/admin/tree/FunctionNode.java	29 Dec 2003 15:20:00 -0000
***************
*** 63,68 ****
--- 63,85 ----
  	}
  
  	/**
+ 	 * Returns the name of the function
+ 	 *
+ 	 * @param client Client to the backend
+ 	 * @return String the name of the function
+ 	 */
+ 
+ 	public String getName(AdminBackendClient client) {
+                 try {
+                     String query = "SELECT proname FROM pg_proc WHERE oid=" + getOID();
+                     String[][] result = client.resultSetToStringArray(client.performSelect(getParentClusterName(), getParentDatabaseName(), query), (new ProcessLease()));
+                     return result[0][0];
+                 } catch (Exception e) {
+                     return "";
+                 }
+ 	}
+ 
+ 	/**
  	 * Returns the quoted signature of the function
  	 *
  	 * @return String the quoted signature of the function
***************
*** 105,111 ****
  	 */
  
  	public void doMenuAction(String selectedMenuCaption, AdminBackendClient client, JFrame dockWindow) throws ObjectDropException, TreeNodePopulationException, DialogRaiseException {
! 		if (selectedMenuCaption == AdminResources.getString(AdminResources.MENU_DROP_RESTRICT)) {
  			if (getDropResponse(dockWindow, DROP_TYPE_RESTRICT)) {
  				FunctionUpdate.dropFunction(client, this, ObjectUpdate.DROP_TYPE_RESTRICT);
  				refreshParent(client);
--- 122,131 ----
  	 */
  
  	public void doMenuAction(String selectedMenuCaption, AdminBackendClient client, JFrame dockWindow) throws ObjectDropException, TreeNodePopulationException, DialogRaiseException {
! 		if (selectedMenuCaption == AdminResources.getString(AdminResources.MENU_RENAME_FUNCTION)) {
! 			RenameDialog rd = new RenameDialog(dockWindow, this, client, this.getNodeType());
! 			rd.show();
!                 } else if (selectedMenuCaption == AdminResources.getString(AdminResources.MENU_DROP_RESTRICT)) {
  			if (getDropResponse(dockWindow, DROP_TYPE_RESTRICT)) {
  				FunctionUpdate.dropFunction(client, this, ObjectUpdate.DROP_TYPE_RESTRICT);
  				refreshParent(client);
***************
*** 147,152 ****
--- 167,192 ----
  	public JPopupMenu getNodeMenu(AdminBackendClient client) {
  		JPopupMenu menu = new JPopupMenu();
  
+ 		// Menu items that vary according to backend
+ 		
+ 		JMenuItem jmiRename = new JMenuItem();
+ 		jmiRename.setText(AdminResources.getString(AdminResources.MENU_RENAME_FUNCTION));
+ 		jmiRename.setEnabled(false);
+ 		
+ 		try {
+ 			
+ 			// For a consistent look, if item is not available on this version, 
+ 			// we will disable it, but still show it
+ 
+ 			if (client.getBackendVersion(this.getParentClusterName()) > 7.3) {
+ 				 jmiRename.setEnabled(true);
+ 			}
+ 
+ 		} catch (Exception e) {
+ 			// Nothing.. element will remain disabled
+ 		}
+ 		
+ 		menu.add(jmiRename);
  		menu.add(new JMenuItem(AdminResources.getString(AdminResources.MENU_DROP_RESTRICT)));
  		menu.add(new JMenuItem(AdminResources.getString(AdminResources.MENU_DROP_CASCADE)));
  		menu.add(new JMenuItem(AdminResources.getString(AdminResources.MENU_REPLACE_FUNCTION)));
