-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6a0647a
commit a687624
Showing
21 changed files
with
596 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
....ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreServerOutputReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* DBeaver - Universal Database Manager | ||
* Copyright (C) 2010-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jkiss.dbeaver.ext.postgresql.model; | ||
|
||
import org.jkiss.code.NotNull; | ||
import org.jkiss.code.Nullable; | ||
import org.jkiss.dbeaver.ext.postgresql.PostgreConstants; | ||
import org.jkiss.dbeaver.model.exec.DBCExecutionContext; | ||
import org.jkiss.dbeaver.model.exec.output.DBCServerOutputReaderExt; | ||
import org.jkiss.dbeaver.model.exec.output.DBCOutputSeverity; | ||
import org.jkiss.dbeaver.model.exec.output.DBCOutputWriter; | ||
import org.jkiss.dbeaver.model.impl.AsyncServerOutputReader; | ||
import org.jkiss.utils.BeanUtils; | ||
|
||
import java.util.Arrays; | ||
|
||
public class PostgreServerOutputReader extends AsyncServerOutputReader implements DBCServerOutputReaderExt { | ||
private static final String PSQL_WARNING_CLASS = "org.postgresql.util.PSQLWarning"; | ||
private static final String PSQL_WARNING_GET_SERVER_ERROR_MESSAGE_METHOD = "getServerErrorMessage"; | ||
private static final String SERVER_ERROR_MESSAGE_GET_SEVERITY_METHOD = "getSeverity"; | ||
|
||
@NotNull | ||
@Override | ||
public DBCOutputSeverity[] getSupportedSeverities(@NotNull DBCExecutionContext context) { | ||
final PostgreDataSource dataSource = (PostgreDataSource) context.getDataSource(); | ||
final PostgreSetting setting = dataSource.getSetting(PostgreConstants.OPTION_CLIENT_MIN_MESSAGES); | ||
final PostgreOutputSeverity[] values = PostgreOutputSeverity.values(); | ||
|
||
if (setting != null) { | ||
for (int i = 0; i < values.length; i++) { | ||
if (values[i].name().equalsIgnoreCase(setting.getValue())) { | ||
return Arrays.copyOfRange(values, i, values.length); | ||
} | ||
} | ||
} | ||
|
||
return values; | ||
} | ||
|
||
@Override | ||
protected void dumpWarning(@NotNull DBCOutputWriter output, @NotNull Throwable warning) { | ||
output.println(getSeverity(warning), warning.getMessage()); | ||
} | ||
|
||
@Nullable | ||
private static DBCOutputSeverity getSeverity(@NotNull Throwable warning) { | ||
if (!PSQL_WARNING_CLASS.equals(warning.getClass().getName())) { | ||
return null; | ||
} | ||
try { | ||
final Object obj = BeanUtils.invokeObjectMethod(warning, PSQL_WARNING_GET_SERVER_ERROR_MESSAGE_METHOD); | ||
final String severity = (String) BeanUtils.invokeObjectMethod(obj, SERVER_ERROR_MESSAGE_GET_SEVERITY_METHOD); | ||
return PostgreOutputSeverity.valueOf(severity); | ||
} catch (Throwable ignored) { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
private enum PostgreOutputSeverity implements DBCOutputSeverity { | ||
DEBUG("Debug"), | ||
LOG("Log"), | ||
NOTICE("Notice"), | ||
WARNING("Warning"), | ||
ERROR("Error"), | ||
INFO("Info"); | ||
|
||
private final String name; | ||
|
||
PostgreOutputSeverity(@NotNull String name) { | ||
this.name = name; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ns/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/exec/output/DBCOutputSeverity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* DBeaver - Universal Database Manager | ||
* Copyright (C) 2010-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jkiss.dbeaver.model.exec.output; | ||
|
||
import org.jkiss.dbeaver.model.DBPNamedObject; | ||
|
||
public interface DBCOutputSeverity extends DBPNamedObject { | ||
} |
25 changes: 25 additions & 0 deletions
25
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/exec/output/DBCOutputWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* DBeaver - Universal Database Manager | ||
* Copyright (C) 2010-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jkiss.dbeaver.model.exec.output; | ||
|
||
import org.jkiss.code.Nullable; | ||
|
||
public interface DBCOutputWriter { | ||
void println(@Nullable DBCOutputSeverity severity, @Nullable String message); | ||
|
||
void flush(); | ||
} |
Oops, something went wrong.