提交 9edf59b0 编写于 作者: S serge-rider

#711 PG JSON support

上级 8b0e14f0
......@@ -100,7 +100,7 @@ public abstract class OracleContentOpaque<OPAQUE_TYPE extends Object> extends JD
} else if (opaque != null) {
preparedStatement.setObject(paramIndex, opaque);
} else {
preparedStatement.setNull(paramIndex + 1, java.sql.Types.SQLXML);
preparedStatement.setNull(paramIndex, java.sql.Types.SQLXML);
}
}
catch (IOException e) {
......
......@@ -65,7 +65,7 @@ public class OracleContentXML extends JDBCContentXML {
xmlObject);
}
} else {
preparedStatement.setNull(paramIndex + 1, java.sql.Types.SQLXML);
preparedStatement.setNull(paramIndex, java.sql.Types.SQLXML);
}
}
catch (SQLException e) {
......
......@@ -195,6 +195,7 @@
<type standard="ARRAY"/>
<type standard="STRUCT"/>
<type name="HSTORE"/>
<type name="JSONB"/>
</provider>
</extension>
......
......@@ -66,6 +66,8 @@ public class PostgreConstants {
"oid", "oid", "Row identifier", false);
public static final String TYPE_HSTORE = "hstore";
public static final String TYPE_JSON = "json";
public static final String TYPE_JSONB = "jsonb";
public static final String HANDLER_SSL = "postgre_ssl";
public static final String EC_PERMISSION_DENIED = "42501";
......
......@@ -21,6 +21,7 @@ import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.PostgreConstants;
import org.jkiss.dbeaver.ext.postgresql.PostgreUtils;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
......@@ -128,6 +129,11 @@ public class PostgreDataType extends JDBCDataType<PostgreSchema> implements Post
}
this.dataKind = JDBCDataSource.getDataKind(getName(), valueType);
if (this.dataKind == DBPDataKind.OBJECT) {
if (PostgreConstants.TYPE_JSONB.equals(name) || PostgreConstants.TYPE_JSON.equals(name)) {
this.dataKind = DBPDataKind.CONTENT;
}
}
this.ownerId = JDBCUtils.safeGetLong(dbResult, "typowner");
this.isByValue = JDBCUtils.safeGetBoolean(dbResult, "typbyval");
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model.data;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.data.JDBCContentChars;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.utils.MimeTypes;
import java.sql.SQLException;
import java.sql.Types;
/**
* JSON content
*/
public class PostgreContentJSON extends JDBCContentChars {
public PostgreContentJSON(DBPDataSource dataSource, String json)
{
super(dataSource, json);
}
@NotNull
@Override
public String getContentType()
{
return MimeTypes.TEXT_JSON;
}
@Override
public void bindParameter(
JDBCSession session,
JDBCPreparedStatement preparedStatement,
DBSTypedObject columnType,
int paramIndex)
throws DBCException
{
try {
if (data != null) {
preparedStatement.setObject(paramIndex, data, Types.OTHER);
} else {
preparedStatement.setNull(paramIndex, columnType.getTypeID());
}
}
catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
}
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.ext.postgresql.model.data;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.jdbc.data.handlers.JDBCContentValueHandler;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.sql.SQLException;
/**
* PostgreJSONValueHandler
*/
public class PostgreJSONValueHandler extends JDBCContentValueHandler {
public static final PostgreJSONValueHandler INSTANCE = new PostgreJSONValueHandler();
@Override
protected DBDContent fetchColumnValue(DBCSession session, JDBCResultSet resultSet, DBSTypedObject type, int index) throws SQLException {
String json = resultSet.getString(index);
return new PostgreContentJSON(session.getDataSource(), json);
}
@Override
public DBDContent getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy) throws DBCException
{
if (object == null) {
return new PostgreContentJSON(session.getDataSource(), null);
} else if (object instanceof PostgreContentJSON) {
return copy ? (PostgreContentJSON)((PostgreContentJSON) object).cloneValue(session.getProgressMonitor()) : (PostgreContentJSON) object;
}
return super.getValueFromObject(session, type, object, copy);
}
}
......@@ -49,10 +49,16 @@ public class PostgreValueHandlerProvider implements DBDValueHandlerProvider {
return PostgreArrayValueHandler.INSTANCE;
} else if (typeID == Types.STRUCT) {
return PostgreStructValueHandler.INSTANCE;
} else if (typedObject.getTypeName().equalsIgnoreCase(PostgreConstants.TYPE_HSTORE)) {
return PostgreHStoreValueHandler.INSTANCE;
} else {
return null;
switch (typedObject.getTypeName()) {
case PostgreConstants.TYPE_JSONB:
case PostgreConstants.TYPE_JSON:
return PostgreJSONValueHandler.INSTANCE;
case PostgreConstants.TYPE_HSTORE:
return PostgreHStoreValueHandler.INSTANCE;
default:
return null;
}
}
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.model.impl.data;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
/**
* AbstractContent
*
* @author Serge Rider
*/
public abstract class AbstractContent implements DBDContent {
protected final DBPDataSource dataSource;
protected AbstractContent(DBPDataSource dataSource)
{
this.dataSource = dataSource;
}
@Override
public void resetContents()
{
// do nothing
}
@Override
public String toString()
{
String displayString = getDisplayString(DBDDisplayFormat.UI);
return displayString == null ? DBConstants.NULL_VALUE_LABEL : displayString;
}
}
......@@ -17,43 +17,27 @@
*/
package org.jkiss.dbeaver.model.impl.jdbc.data;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.data.DBDValueCloneable;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.data.AbstractContent;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
/**
* JDBCBLOB
* JDBCContentAbstract
*
* @author Serge Rider
*/
public abstract class JDBCContentAbstract implements DBDContent, DBDValueCloneable {
protected final DBPDataSource dataSource;
public abstract class JDBCContentAbstract extends AbstractContent implements DBDValueCloneable {
protected JDBCContentAbstract(DBPDataSource dataSource)
{
this.dataSource = dataSource;
super(dataSource);
}
public abstract void bindParameter(JDBCSession session, JDBCPreparedStatement preparedStatement, DBSTypedObject columnType, int paramIndex)
throws DBCException;
@Override
public void resetContents()
{
// do nothing
}
@Override
public String toString()
{
String displayString = getDisplayString(DBDDisplayFormat.UI);
return displayString == null ? DBConstants.NULL_VALUE_LABEL : displayString;
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ import java.sql.SQLException;
public class JDBCContentChars extends JDBCContentAbstract implements DBDContentStorage, DBDContentCached {
private String originalData;
private String data;
protected String data;
public JDBCContentChars(DBPDataSource dataSource, String data) {
super(dataSource);
......
......@@ -144,7 +144,7 @@ public class JDBCContentXML extends JDBCContentLOB {
} else if (xml != null) {
preparedStatement.setSQLXML(paramIndex, xml);
} else {
preparedStatement.setNull(paramIndex + 1, java.sql.Types.SQLXML);
preparedStatement.setNull(paramIndex, java.sql.Types.SQLXML);
}
}
catch (SQLException e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册