提交 476448cb 编写于 作者: A Andrew Khitrin

Variables, Code format, Session termination, Some details

上级 90858b4e
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg;
public interface Breakpoint {
DebugObject<?> getObj();
BreakpointProperties getProperties();
void drop() throws DebugException;
DebugObject<?> getObj();
BreakpointProperties getProperties();
void drop() throws DebugException;
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg;
public interface BreakpointProperties {
......
......@@ -14,27 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.pldbg;
package org.jkiss.dbeaver.ext.postgresql.pldbg;
@SuppressWarnings("serial")
public class DebugException extends Exception {
public DebugException(String message, Throwable e)
{
super(message, e);
}
public DebugException(String message, Throwable e) {
super(message, e);
}
public DebugException(String message)
{
super(message);
}
public DebugException(String message) {
super(message);
}
public DebugException(Throwable e)
{
super(e);
}
public DebugException(Throwable e) {
super(e);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg;
public interface DebugObject<OBJECTID> {
OBJECTID getID();
String getName();
OBJECTID getID();
String getName();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg;
import java.sql.Connection;
import java.util.List;
public interface DebugSession<SESSIONINFO extends SessionInfo<?>,DEBUGOBJECT extends DebugObject<?>,SESSIONID> {
public interface DebugSession<SESSIONINFO extends SessionInfo<?>, DEBUGOBJECT extends DebugObject<?>, SESSIONID> {
SESSIONINFO getSessionInfo();
String getTitle();
List<? extends Breakpoint> getBreakpoints();
Breakpoint setBreakpoint(DEBUGOBJECT obj,BreakpointProperties properties) throws DebugException;
void removeBreakpoint(Breakpoint bp);
Breakpoint setBreakpoint(DEBUGOBJECT obj, BreakpointProperties properties) throws DebugException;
void removeBreakpoint(Breakpoint bp) throws DebugException;
void execContinue() throws DebugException;
void execStepInto() throws DebugException;
void execStepOver() throws DebugException;
void abort();
List<? extends Variable<?>> getVarables(String ctx);
void setVariableVal(Variable<?> variable, Object value);
List<? extends StackFrame> getStack() throws DebugException;
void abort() throws DebugException;
void close();
List<? extends Variable<?>> getVarables() throws DebugException;
void setVariableVal(Variable<?> variable, Object value) throws DebugException;
List<? extends StackFrame> getStack() throws DebugException;
SESSIONID getSessionId();
//move Stack
// move Stack
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg;
public interface SessionInfo<SESSIONID> {
SESSIONID getID();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg;
public interface StackFrame {
String getName();
String getName();
int getLevel();
int getLine();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg;
public interface Variable<T> {
T getVal();
String getName();
VariableType getType();
T getVal();
String getName();
VariableType getType();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg;
public enum VariableType { NUMBER, TEXT, DATE, BLOB }
public enum VariableType {
NUMBER, TEXT, DATE, BLOB
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg.impl;
import org.jkiss.dbeaver.ext.postgresql.pldbg.BreakpointProperties;
public class BreakpointPropertiesPostgres implements BreakpointProperties {
private final long lineNo;
private final boolean onStart;
private final long targetId;
private final boolean all;
private final boolean global;
public long getLineNo() {
return lineNo;
}
public boolean isOnStart() {
return onStart;
}
public long getTargetId() {
return targetId;
}
public boolean isAll() {
return all;
}
private final long lineNo;
private final boolean onStart;
private final long targetId;
private final boolean all;
private final boolean global;
public long getLineNo() {
return lineNo;
}
public boolean isOnStart() {
return onStart;
}
public long getTargetId() {
return targetId;
}
public boolean isAll() {
return all;
}
public boolean isGlobal() {
return global;
}
public BreakpointPropertiesPostgres(long lineNo, long targetId, boolean global) {
this.lineNo = lineNo;
this.onStart = lineNo < 0;
this.targetId = targetId;
this.all = targetId < 0;
this.global = global;
}
public BreakpointPropertiesPostgres(long lineNo, boolean global) {
this.lineNo = lineNo;
this.onStart = lineNo < 0;
this.targetId = -1;
this.all = true;
this.global = global;
}
public BreakpointPropertiesPostgres(boolean global) {
this.lineNo = -1;
this.onStart = true;
this.targetId = -1;
this.all = true;
this.global = global;
}
@Override
public String toString() {
return "BreakpointPropertiesPostgres [lineNo=" + lineNo + ", onStart=" + onStart + ", targetId=" + targetId
+ ", all=" + all + ", global=" + global + "]";
}
public boolean isGlobal() {
return global;
}
public BreakpointPropertiesPostgres(long lineNo, long targetId,boolean global) {
this.lineNo = lineNo;
this.onStart = lineNo < 0;
this.targetId = targetId;
this.all = targetId < 0;
this.global = global;
}
public BreakpointPropertiesPostgres(long lineNo,boolean global) {
this.lineNo = lineNo;
this.onStart = lineNo < 0;
this.targetId = -1;
this.all = true;
this.global = global;
}
public BreakpointPropertiesPostgres(boolean global) {
this.lineNo = -1;
this.onStart = true;
this.targetId = -1;
this.all = true;
this.global = global;
}
@Override
public String toString() {
return "BreakpointPropertiesPostgres [lineNo=" + lineNo + ", onStart=" + onStart + ", targetId=" + targetId
+ ", all=" + all + ", global=" + global + "]";
}
}
......@@ -27,179 +27,144 @@ import java.util.List;
import java.util.Map;
import org.jkiss.dbeaver.ext.postgresql.pldbg.DebugException;
import org.jkiss.dbeaver.ext.postgresql.pldbg.DebugObject;
import org.jkiss.dbeaver.ext.postgresql.pldbg.DebugSession;
import org.jkiss.dbeaver.ext.postgresql.pldbg.SessionInfo;
import org.jkiss.dbeaver.postgresql.pldbg.control.DebugManager;
/**
* @author Andrey.Hitrin
*
*/
@SuppressWarnings("nls")
public class DebugManagerPostgres implements DebugManager<Integer,Integer> {
private final Connection connection;
private static final String SQL_SESSION = "select pid,usename,application_name,state,query from pg_stat_activity";
private static final String SQL_OBJECT = "select p.oid,p.proname,u.usename as owner,n.nspname, l.lanname as lang "+
" from "+
" pg_catalog.pg_namespace n "+
" join pg_catalog.pg_proc p on p.pronamespace = n.oid "+
" join pg_user u on u.usesysid = p.proowner "+
" join pg_language l on l.oid = p. prolang "+
" where "+
" l.lanname = 'plpgsql' "+
" and p.proname like '%?nameCtx%' "+
" and u.usename like '%?userCtx%' "+
" order by "+
" n.nspname,p.proname";
private static final String SQL_CURRENT_SESSION = "select pid,usename,application_name,state,query from pg_stat_activity where pid = pg_backend_pid()";
private final Map<Integer,DebugSessionPostgres> sessions = new HashMap<Integer,DebugSessionPostgres>(1);
@Override
public SessionInfoPostgres getSessionInfo(Connection connectionTarget) throws DebugException
{
try (Statement stmt = connectionTarget.createStatement()) {
ResultSet rs = stmt.executeQuery(SQL_CURRENT_SESSION);
if (rs.next()) {
SessionInfoPostgres res = new SessionInfoPostgres(
rs.getInt("pid") ,
rs.getString("usename"),
rs.getString("application_name"),
rs.getString("state"),
rs.getString("query"));
return res;
}
throw new DebugException("Error getting session");
} catch (SQLException e) {
throw new DebugException(e);
}
}
@Override
public List<SessionInfoPostgres> getSessions() throws DebugException
{
try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery(SQL_SESSION);
List<SessionInfoPostgres> res = new ArrayList<SessionInfoPostgres>();
while (rs.next()) {
res.add(new SessionInfoPostgres(
rs.getInt("pid") ,
rs.getString("usename"),
rs.getString("application_name"),
rs.getString("state"),
rs.getString("query")));
}
return res;
} catch (SQLException e) {
throw new DebugException(e);
}
}
/**
* @param connection
*/
public DebugManagerPostgres(Connection connection)
{
super();
this.connection = connection;
}
@Override
public List<DebugObjectPostgres> getObjects(String ownerCtx,
String nameCtx) throws DebugException
{
try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery(SQL_OBJECT.replaceAll("\\?nameCtx", nameCtx).replaceAll("\\?userCtx", ownerCtx).toLowerCase());
List<DebugObjectPostgres> res = new ArrayList<DebugObjectPostgres>();
while (rs.next()) {
res.add(new DebugObjectPostgres(
rs.getInt("oid") ,
rs.getString("proname"),
rs.getString("owner"),
rs.getString("nspname"),
rs.getString("lang")));
}
return res;
} catch (SQLException e) {
throw new DebugException(e);
}
}
@Override
public DebugSession<SessionInfoPostgres, DebugObjectPostgres,Integer> getDebugSession(
Integer id) throws DebugException
{
return sessions.get(id);
}
@Override
public DebugSessionPostgres createDebugSession(Connection connectionTarget) throws DebugException
{
SessionInfoPostgres targetInfo = getSessionInfo(connectionTarget);
DebugSessionPostgres debugSession = new DebugSessionPostgres(getSessionInfo(this.connection),targetInfo ,connectionTarget);
sessions.put(targetInfo.getPid(), debugSession);
return debugSession;
}
@Override
public boolean isSessionExists(Integer id)
{
return sessions.containsKey(id);
}
@Override
public void terminateSession(Integer id) {
// TODO Auto-generated method stub
}
@Override
public List<DebugSession<?,?,Integer>> getDebugSessions() throws DebugException {
return new ArrayList<DebugSession<?,?,Integer>>(sessions.values());
}
public class DebugManagerPostgres implements DebugManager<Integer, Integer> {
private final Connection connection;
private static final String SQL_SESSION = "select pid,usename,application_name,state,query from pg_stat_activity";
private static final String SQL_OBJECT = "select p.oid,p.proname,u.usename as owner,n.nspname, l.lanname as lang "
+ " from " + " pg_catalog.pg_namespace n " + " join pg_catalog.pg_proc p on p.pronamespace = n.oid "
+ " join pg_user u on u.usesysid = p.proowner " + " join pg_language l on l.oid = p. prolang "
+ " where " + " l.lanname = 'plpgsql' " + " and p.proname like '%?nameCtx%' "
+ " and u.usename like '%?userCtx%' " + " order by " + " n.nspname,p.proname";
private static final String SQL_CURRENT_SESSION = "select pid,usename,application_name,state,query from pg_stat_activity where pid = pg_backend_pid()";
private final Map<Integer, DebugSessionPostgres> sessions = new HashMap<Integer, DebugSessionPostgres>(1);
@Override
public SessionInfoPostgres getSessionInfo(Connection connectionTarget) throws DebugException {
try (Statement stmt = connectionTarget.createStatement()) {
ResultSet rs = stmt.executeQuery(SQL_CURRENT_SESSION);
if (rs.next()) {
SessionInfoPostgres res = new SessionInfoPostgres(rs.getInt("pid"), rs.getString("usename"),
rs.getString("application_name"), rs.getString("state"), rs.getString("query"));
return res;
}
throw new DebugException("Error getting session");
} catch (SQLException e) {
throw new DebugException(e);
}
}
@Override
public List<SessionInfoPostgres> getSessions() throws DebugException {
try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery(SQL_SESSION);
List<SessionInfoPostgres> res = new ArrayList<SessionInfoPostgres>();
while (rs.next()) {
res.add(new SessionInfoPostgres(rs.getInt("pid"), rs.getString("usename"),
rs.getString("application_name"), rs.getString("state"), rs.getString("query")));
}
return res;
} catch (SQLException e) {
throw new DebugException(e);
}
}
/**
* @param connection
*/
public DebugManagerPostgres(Connection connection) {
super();
this.connection = connection;
}
@Override
public List<DebugObjectPostgres> getObjects(String ownerCtx, String nameCtx) throws DebugException {
try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery(
SQL_OBJECT.replaceAll("\\?nameCtx", nameCtx).replaceAll("\\?userCtx", ownerCtx).toLowerCase());
List<DebugObjectPostgres> res = new ArrayList<DebugObjectPostgres>();
while (rs.next()) {
res.add(new DebugObjectPostgres(rs.getInt("oid"), rs.getString("proname"), rs.getString("owner"),
rs.getString("nspname"), rs.getString("lang")));
}
return res;
} catch (SQLException e) {
throw new DebugException(e);
}
}
@Override
public DebugSession<SessionInfoPostgres, DebugObjectPostgres, Integer> getDebugSession(Integer id)
throws DebugException {
return sessions.get(id);
}
@Override
public DebugSessionPostgres createDebugSession(Connection connectionTarget) throws DebugException {
SessionInfoPostgres targetInfo = getSessionInfo(connectionTarget);
DebugSessionPostgres debugSession = new DebugSessionPostgres(getSessionInfo(this.connection), targetInfo,
connectionTarget);
sessions.put(targetInfo.getPid(), debugSession);
return debugSession;
}
@Override
public boolean isSessionExists(Integer id) {
return sessions.containsKey(id);
}
@Override
public void terminateSession(Integer id) {
DebugSessionPostgres session = sessions.get(id);
if (session != null) {
session.close();
sessions.remove(id);
}
}
@Override
public List<DebugSession<?, ?, Integer>> getDebugSessions() throws DebugException {
return new ArrayList<DebugSession<?, ?, Integer>>(sessions.values());
}
}
......@@ -14,74 +14,59 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.pldbg.impl;
import org.jkiss.dbeaver.ext.postgresql.pldbg.DebugObject;
@SuppressWarnings("nls")
public class DebugObjectPostgres implements DebugObject<Integer> {
private final Integer oid;
private final String proname;
private final String owner;
private final String schema;
private final String lang;
/**
* @param oid
* @param proname
* @param owner
* @param schema
* @param lang
*/
public DebugObjectPostgres(Integer oid, String proname, String owner,
String schema, String lang)
{
super();
this.oid = oid;
this.proname = proname;
this.owner = owner;
this.schema = schema;
this.lang = lang;
}
public String getOwner()
{
return owner;
}
public String getSchema()
{
return schema;
}
public String getLang()
{
return lang;
}
@Override
public Integer getID()
{
return oid;
}
@Override
public String getName()
{
return proname;
}
@Override
public String toString()
{
return "id:" + String.valueOf(oid) + ", name: `"+ proname + "("+lang+")" + ", user: " + owner +"(" + schema + ")";
}
private final Integer oid;
private final String proname;
private final String owner;
private final String schema;
private final String lang;
public DebugObjectPostgres(Integer oid, String proname, String owner, String schema, String lang) {
super();
this.oid = oid;
this.proname = proname;
this.owner = owner;
this.schema = schema;
this.lang = lang;
}
public String getOwner() {
return owner;
}
public String getSchema() {
return schema;
}
public String getLang() {
return lang;
}
@Override
public Integer getID() {
return oid;
}
@Override
public String getName() {
return proname;
}
@Override
public String toString() {
return "id:" + String.valueOf(oid) + ", name: `" + proname + "(" + lang + ")" + ", user: " + owner + "("
+ schema + ")";
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg.impl;
public class DebugSessionResult {
private final boolean result;
private final Exception exception;
public DebugSessionResult(boolean result, Exception exception) {
super();
this.result = result;
this.exception = exception;
}
public boolean isResult() {
return result;
}
public Exception getException() {
return exception;
}
private final boolean result;
private final Exception exception;
public DebugSessionResult(boolean result, Exception exception) {
super();
this.result = result;
this.exception = exception;
}
public boolean isResult() {
return result;
}
public Exception getException() {
return exception;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg.impl;
import java.sql.Connection;
......@@ -7,27 +24,30 @@ import java.util.concurrent.Callable;
public class DebugSessionWorker implements Callable<DebugSessionResult> {
private final Connection conn;
private String sql ="";
public void execSQL(String sqlCommand) {
this.sql = sqlCommand;
}
public DebugSessionWorker(Connection conn) {
this.conn = conn;
}
@Override
public DebugSessionResult call() throws Exception {
try (Statement stmt = conn.createStatement()) {
stmt.executeQuery(sql);
return new DebugSessionResult(true,null);
} catch (SQLException e) {
return new DebugSessionResult(false,e);
}
}
private final Connection conn;
private String sql = "";
public void execSQL(String sqlCommand)
{
this.sql = sqlCommand;
}
public DebugSessionWorker(Connection conn)
{
this.conn = conn;
}
@Override
public DebugSessionResult call() throws Exception
{
try (Statement stmt = conn.createStatement()) {
stmt.executeQuery(sql);
return new DebugSessionResult(true, null);
} catch (SQLException e) {
return new DebugSessionResult(false, e);
}
}
}
......@@ -14,74 +14,78 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.pldbg.impl;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.jkiss.dbeaver.ext.postgresql.pldbg.Breakpoint;
import org.jkiss.dbeaver.ext.postgresql.pldbg.DebugException;
@SuppressWarnings("nls")
public class PostgresBreakpoint implements Breakpoint {
private final DebugObjectPostgres obj;
private final DebugSessionPostgres session;
private final BreakpointPropertiesPostgres properties;
private static final String SQL_SET_GLOBAL = "select pldbg_set_global_breakpoint(?sessionid, ?obj, ?line, ?target)";
private static final String SQL_SET = "select pldbg_set_breakpoint(?sessionid, ?obj, ?line, ?target)";
public PostgresBreakpoint(DebugSessionPostgres session,DebugObjectPostgres obj, BreakpointPropertiesPostgres properties) throws DebugException
{
this.session = session;
this.obj = obj;
this.properties = properties;
try (Statement stmt = session.getConnection().createStatement()) {
String sqlCommand = properties.isGlobal() ? SQL_SET_GLOBAL : SQL_SET;
stmt.executeQuery(sqlCommand.replaceAll("\\?sessionid",String.valueOf(session.getSessionId()))
.replaceAll("\\?obj",String.valueOf(obj.getID()))
.replaceAll("\\?line",properties.isOnStart() ? "-1" : String.valueOf(properties.getLineNo()))
.replaceAll("\\?target",properties.isAll() ? "null" : String.valueOf(properties.getTargetId())));
} catch (SQLException e) {
throw new DebugException(e);
}
}
@Override
public DebugObjectPostgres getObj()
{
return obj;
}
@Override
public void drop() throws DebugException
{
// TODO Auto-generated method stub
}
@Override
public BreakpointPropertiesPostgres getProperties() {
return properties;
}
@Override
public String toString() {
return "PostgresBreakpoint [obj=" + obj + ", session id =" + session.getSessionId() + ", properties=" + properties + "]";
}
private final DebugObjectPostgres obj;
private final DebugSessionPostgres session;
private final BreakpointPropertiesPostgres properties;
private static final String SQL_SET_GLOBAL = "select pldbg_set_global_breakpoint(?sessionid, ?obj, ?line, ?target)";
private static final String SQL_SET = "select pldbg_set_breakpoint(?sessionid, ?obj, ?line)";
private static final String SQL_DROP = "select pldbg_drop_breakpoint(?sessionid, ?obj, ?line)";
public PostgresBreakpoint(DebugSessionPostgres session, DebugObjectPostgres obj,
BreakpointPropertiesPostgres properties) throws DebugException {
this.session = session;
this.obj = obj;
this.properties = properties;
try (Statement stmt = session.getConnection().createStatement()) {
String sqlCommand = properties.isGlobal() ? SQL_SET_GLOBAL : SQL_SET;
stmt.executeQuery(sqlCommand.replaceAll("\\?sessionid", String.valueOf(session.getSessionId()))
.replaceAll("\\?obj", String.valueOf(obj.getID()))
.replaceAll("\\?line", properties.isOnStart() ? "-1" : String.valueOf(properties.getLineNo()))
.replaceAll("\\?target", properties.isAll() ? "null"
: String.valueOf(properties.getTargetId())));
} catch (SQLException e) {
throw new DebugException(e);
}
}
@Override
public DebugObjectPostgres getObj() {
return obj;
}
@Override
public void drop() throws DebugException {
try (Statement stmt = session.getConnection().createStatement()) {
stmt.executeQuery(SQL_DROP.replaceAll("\\?sessionid", String.valueOf(session.getSessionId()))
.replaceAll("\\?obj", String.valueOf(obj.getID()))
.replaceAll("\\?line", properties.isOnStart() ? "-1" : String.valueOf(properties.getLineNo())));
} catch (SQLException e) {
throw new DebugException(e);
}
}
@Override
public BreakpointPropertiesPostgres getProperties() {
return properties;
}
@Override
public String toString() {
return "PostgresBreakpoint [obj=" + obj + ", session id =" + session.getSessionId() + ", properties="
+ properties + "]";
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg.impl;
import org.jkiss.dbeaver.ext.postgresql.pldbg.StackFrame;
public class PostgresStackFrame implements StackFrame {
private final int level;
private final String name;
private final String oid;
private final int lineNo;
private final String args;
public PostgresStackFrame(int level, String name, String oid, int lineNo, String args) {
super();
this.level = level;
this.name = name;
this.oid = oid;
this.lineNo = lineNo;
this.args = args;
}
public int getLevel() {
return level;
}
public String getOid() {
return oid;
}
public int getLineNo() {
return lineNo;
}
private final int level;
private final String name;
private final int oid;
private final int lineNo;
private final String args;
public PostgresStackFrame(int level, String name, int oid, int lineNo, String args) {
super();
this.level = level;
this.name = name;
this.oid = oid;
this.lineNo = lineNo;
this.args = args;
}
public int getLevel() {
return level;
}
public String getArgs() {
return args;
}
public int getOid() {
return oid;
}
@Override
public int getLine() {
return lineNo;
}
public String getArgs() {
return args;
}
@Override
public String getName() {
return name;
}
@Override
public String getName() {
return name;
}
@Override
public String toString() {
return "PostgresStackFrame [level=" + level + ", name=" + name + ", oid=" + oid + ", lineNo=" + lineNo
+ ", args=" + args + "]";
}
@Override
public String toString() {
return "PostgresStackFrame [level=" + level + ", name=" + name + ", oid=" + oid + ", lineNo=" + lineNo
+ ", args=" + args + "]";
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2017 Andrew Khitrin (ahitrin@gmail.com)
*
* 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.pldbg.impl;
import org.jkiss.dbeaver.ext.postgresql.pldbg.Variable;
import org.jkiss.dbeaver.ext.postgresql.pldbg.VariableType;
public class PostgresVariable implements Variable<String> {
private final String name;
private final String varclass;
private final int linenumber;
private final boolean unique;
private final boolean constant;
private final boolean notnull;
private final int oid;
private final String val;
@Override
public String getVal() {
return val;
}
@Override
public String getName() {
return name;
}
@Override
public VariableType getType() {
// TODO Auto-generated method stub
return VariableType.TEXT;
}
public PostgresVariable(String name, String varclass, int linenumber, boolean unique, boolean constant,
boolean notnull, int oid, String val) {
super();
this.name = name;
this.varclass = varclass;
this.linenumber = linenumber;
this.unique = unique;
this.constant = constant;
this.notnull = notnull;
this.oid = oid;
this.val = val;
}
public String getVarclass() {
return varclass;
}
public int getLinenumber() {
return linenumber;
}
public boolean isUnique() {
return unique;
}
public boolean isConstant() {
return constant;
}
public boolean isNotnull() {
return notnull;
}
public int getOid() {
return oid;
}
@Override
public String toString() {
return "PostgresVariable [name=" + name + ", val=" + val + ", varclass=" + varclass + ", linenumber="
+ linenumber + ", unique=" + unique + ", constant=" + constant + ", notnull=" + notnull + ", oid=" + oid
+ "]";
}
}
......@@ -19,70 +19,56 @@ package org.jkiss.dbeaver.ext.postgresql.pldbg.impl;
import org.jkiss.dbeaver.ext.postgresql.pldbg.SessionInfo;
/**
* @author Andrey.Hitrin
*
*/
@SuppressWarnings("nls")
public class SessionInfoPostgres implements SessionInfo<Integer> {
public static final String CREATE_LISTEN = "CREATE LISTEN";
final int pid;
final String user;
final String application;
final String state;
final String query;
@Override
public Integer getID()
{
return pid;
}
public SessionInfoPostgres(int pid, String user, String application,
String state, String query)
{
super();
this.pid = pid;
this.user = user;
this.application = application;
this.state = state;
this.query = query;
}
public static final String CREATE_LISTEN = "CREATE LISTEN";
final int pid;
final String user;
final String application;
final String state;
final String query;
@Override
public Integer getID() {
return pid;
}
public SessionInfoPostgres(int pid, String user, String application, String state, String query) {
super();
this.pid = pid;
this.user = user;
this.application = application;
this.state = state;
this.query = query;
}
public int getPid() {
return pid;
}
public int getPid()
{
return pid;
}
public String getUser() {
return user;
}
public String getUser()
{
return user;
}
public String getApplication() {
return application;
}
public String getApplication()
{
return application;
}
public String getState() {
return state;
}
public String getState()
{
return state;
}
public String getQuery() {
return query;
}
public String getQuery()
{
return query;
}
@Override
public String toString() {
@Override
public String toString()
{
return "pid:" + String.valueOf(pid) + ", user: " + user + ", application: `" + application + "`, state: " +state+ ", query: " + query.replace('\n', '\\') ;
}
return "pid:" + String.valueOf(pid) + ", user: " + user + ", application: `" + application + "`, state: "
+ state + ", query: " + query.replace('\n', '\\');
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册