Search in sources :

Example 1 with DBPEvent

use of org.jkiss.dbeaver.model.DBPEvent in project dbeaver by serge-rider.

the class CompileHandler method compileUnit.

public static boolean compileUnit(DBRProgressMonitor monitor, DBCCompileLog compileLog, OracleSourceObject unit) throws DBCException {
    final DBEPersistAction[] compileActions = unit.getCompileActions();
    if (ArrayUtils.isEmpty(compileActions)) {
        return true;
    }
    try (JDBCSession session = DBUtils.openUtilSession(monitor, unit.getDataSource(), "Compile '" + unit.getName() + "'")) {
        boolean success = true;
        for (DBEPersistAction action : compileActions) {
            final String script = action.getScript();
            compileLog.trace(script);
            if (monitor.isCanceled()) {
                break;
            }
            try {
                try (DBCStatement dbStat = session.prepareStatement(DBCStatementType.QUERY, script, false, false, false)) {
                    dbStat.executeStatement();
                }
                action.handleExecute(session, null);
            } catch (DBCException e) {
                action.handleExecute(session, e);
                throw e;
            }
            if (action instanceof OracleObjectPersistAction) {
                if (!logObjectErrors(session, compileLog, unit, ((OracleObjectPersistAction) action).getObjectType())) {
                    success = false;
                }
            }
        }
        final DBSObjectState oldState = unit.getObjectState();
        unit.refreshObjectState(monitor);
        if (unit.getObjectState() != oldState) {
            unit.getDataSource().getContainer().fireEvent(new DBPEvent(DBPEvent.Action.OBJECT_UPDATE, unit));
        }
        return success;
    }
}
Also used : JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBSObjectState(org.jkiss.dbeaver.model.struct.DBSObjectState) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBPEvent(org.jkiss.dbeaver.model.DBPEvent) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) OracleObjectPersistAction(org.jkiss.dbeaver.ext.oracle.model.OracleObjectPersistAction)

Example 2 with DBPEvent

use of org.jkiss.dbeaver.model.DBPEvent in project dbeaver by serge-rider.

the class OracleUtils method normalizeSourceName.

public static String normalizeSourceName(OracleSourceObject object, boolean body) {
    try {
        String source = body ? ((DBPScriptObjectExt) object).getExtendedDefinitionText(null) : object.getObjectDefinitionText(null);
        if (source == null) {
            return null;
        }
        java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(object.getSourceType() + (body ? "\\s+BODY" : "") + "\\s(\\s*)([\\w$\\.]+)[\\s\\(]+", java.util.regex.Pattern.CASE_INSENSITIVE);
        final Matcher matcher = pattern.matcher(source);
        if (matcher.find()) {
            String objectName = matcher.group(2);
            if (objectName.indexOf('.') == -1) {
                if (!objectName.equalsIgnoreCase(object.getName())) {
                    object.setName(DBObjectNameCaseTransformer.transformObjectName(object, objectName));
                    object.getDataSource().getContainer().fireEvent(new DBPEvent(DBPEvent.Action.OBJECT_UPDATE, object));
                }
                //.substring(0, matcher.start(1)) + object.getSchema().getName() + "." + objectName + source.substring(matcher.end(2));
                return source;
            }
        }
        return source.trim();
    } catch (DBException e) {
        log.error(e);
        return null;
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) Matcher(java.util.regex.Matcher) DBPEvent(org.jkiss.dbeaver.model.DBPEvent) Pattern(java.util.regex.Pattern)

Aggregations

DBPEvent (org.jkiss.dbeaver.model.DBPEvent)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DBException (org.jkiss.dbeaver.DBException)1 OracleObjectPersistAction (org.jkiss.dbeaver.ext.oracle.model.OracleObjectPersistAction)1 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)1 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)1 DBSObjectState (org.jkiss.dbeaver.model.struct.DBSObjectState)1