Project

General

Profile

« Previous | Next » 

Revision 4400

Added by daigle over 15 years ago

Handle ignoring oracle errors when we try to delete an object that doesn't exist. Also, add parsing for sql script with pl/sql.

View differences:

DBAdmin.java
772 772
			for (String sqlStatement : sqlCommands) {
773 773
				Statement statement = connection.createStatement();
774 774
				logMetacat.debug("executing sql: " + sqlStatement);
775
				statement.execute(sqlStatement);
775
				try {
776
					statement.execute(sqlStatement);
777
				} catch (SQLException sqle) {
778
					// Oracle complains if we try and drop a sequence (ORA-02289) or a 
779
					// trigger (ORA-04098/ORA-04080) or a table/view (ORA-00942) or and index (ORA-01418) 
780
					// that does not exist.  We don't care if this happens.
781
					if (sqlStatement.toUpperCase().startsWith("DROP") && 
782
							(sqle.getMessage().contains("ORA-02289") ||
783
							 sqle.getMessage().contains("ORA-04098") ||
784
							 sqle.getMessage().contains("ORA-04080") ||
785
							 sqle.getMessage().contains("ORA-00942"))) {
786
						logMetacat.warn("did not process sql drop statement: " + sqle.getMessage());
787
					} else {
788
						throw sqle;
789
					}
790
				}
776 791
			}
777 792
			connection.commit();
778 793
			
......
822 837
			// Read in file
823 838
			String fileLine;
824 839
			while ((fileLine = reader.readLine()) != null) {
840
				String endChar = ";";
825 841
				String trimmedLine = fileLine.trim();
826 842

  
827 843
				// get the first word on the line
......
830 846
					firstWord = trimmedLine.substring(0, trimmedLine
831 847
							.indexOf(' '));
832 848
				}
833
				if (firstWord.endsWith(";")) {
834
					firstWord = firstWord.substring(0, firstWord.indexOf(';'));
849
				if (firstWord.endsWith(endChar)) {
850
					firstWord = firstWord.substring(0, firstWord.indexOf(endChar));
835 851
				}
836 852

  
837 853
				// if the first word is a known sql command, start creating a
838 854
				// sql statement.
839 855
				if (sqlCommandSet.contains(firstWord.toUpperCase())) {
840
					String sqlStatement = trimmedLine;
856
					String sqlStatement = "";
841 857

  
842
					// if this ends with ; it is a single line statement. Add to
843
					// command vector and process next line.
844
					if (trimmedLine.endsWith(";")) {
845
						sqlCommands.add(sqlStatement);
846
						continue;
847
					}
848

  
849 858
					// keep reading lines until we find one that is not a
850
					// comment and ends with ;
851
					String innerLine;
852
					while ((innerLine = reader.readLine()) != null) {
853
						String trimmedInnerLine = innerLine.trim();
859
					// comment and ends with endChar
860
					do {
861
						String trimmedInnerLine = fileLine.trim();
862
						
863
						// if there is a BEGIN or DECLARE statement, we are now in plsql and we're 
864
						// using the '/' character as our sql end delimiter.
865
						if (trimmedInnerLine.toUpperCase().equals("BEGIN")  ||
866
								trimmedInnerLine.toUpperCase().startsWith("BEGIN ")  ||
867
								trimmedInnerLine.toUpperCase().equals("DECLARE")  ||
868
								trimmedInnerLine.toUpperCase().startsWith("DECLARE ")) {
869
							endChar = "/";
870
						}
871
						
854 872
						// ignore comments and empty lines
855 873
						if (trimmedInnerLine.matches("^$")
856 874
								|| trimmedInnerLine.matches("^\\*.*")
......
863 881
							trimmedInnerLine = trimmedInnerLine.substring(0,
864 882
									trimmedInnerLine.indexOf("--")).trim();
865 883
						}
866
						sqlStatement += " " + trimmedInnerLine;
867
						if (trimmedInnerLine.endsWith(";")) {
884
						if (sqlStatement.length() > 0) {
885
							sqlStatement += " ";
886
						}
887
						sqlStatement += trimmedInnerLine;
888
						if (trimmedInnerLine.endsWith(endChar)) {
889
							sqlStatement = 
890
								sqlStatement.substring(0, sqlStatement.length() - 1);
868 891
							sqlCommands.add(sqlStatement);
869 892
							break;
870 893
						}
871
					}
894
					} while ((fileLine = reader.readLine()) != null);
872 895
				}
873 896
			}
874 897
		} finally {

Also available in: Unified diff