01: /*
02: * OracleObjectCompiler.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.oracle;
13:
14: import java.sql.SQLException;
15: import java.sql.Statement;
16:
17: import workbench.db.DbObject;
18: import workbench.db.WbConnection;
19: import workbench.util.SqlUtil;
20:
21: /**
22: *
23: * @author support@sql-workbench.net
24: */
25: public class OracleObjectCompiler {
26: private WbConnection dbConnection;
27: private Statement stmt;
28: private String lastError = null;
29:
30: public OracleObjectCompiler(WbConnection conn) throws SQLException {
31: this .dbConnection = conn;
32: this .stmt = this .dbConnection.createStatement();
33: }
34:
35: public void close() {
36: if (this .stmt != null) {
37: SqlUtil.closeStatement(stmt);
38: }
39: }
40:
41: public String getLastError() {
42: return this .lastError;
43: }
44:
45: public String compileObject(DbObject object) {
46: String sql = "ALTER " + object.getObjectType() + " "
47: + object.getObjectExpression(dbConnection) + " COMPILE";
48: this .lastError = null;
49: try {
50: this .dbConnection.setBusy(true);
51: this .stmt.executeUpdate(sql);
52: return null;
53: } catch (SQLException e) {
54: return e.getMessage();
55: } finally {
56: this .dbConnection.setBusy(false);
57: }
58: }
59:
60: public static boolean canCompile(DbObject object) {
61: if (object == null)
62: return false;
63: String type = object.getObjectType();
64: return (type.equalsIgnoreCase("VIEW")
65: || type.equalsIgnoreCase("PROCEDURE")
66: || type.equalsIgnoreCase("MATERIALIZED VIEW")
67: || type.equalsIgnoreCase("FUNCTION")
68: || type.equalsIgnoreCase("PACKAGE") || type
69: .equalsIgnoreCase("TRIGGER"));
70: }
71:
72: }
|