提交 5f842c47 编写于 作者: J jurgen

LOB editors fixed.

Oracle XML tables edit support.
上级 063230f3
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.ext.oracle.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.data.DBDPseudoAttribute;
import org.jkiss.dbeaver.model.data.DBDPseudoAttributeContainer;
......@@ -43,7 +44,7 @@ public class OracleTable extends OracleTablePhysical implements DBDPseudoAttribu
private boolean temporary;
private boolean secondary;
private boolean nested;
private OracleTableColumn objectValueAttribute;
//private OracleTableColumn objectValueAttribute;
public static class AdditionalInfo extends TableAdditionalInfo {
}
......@@ -134,27 +135,23 @@ public class OracleTable extends OracleTablePhysical implements DBDPseudoAttribu
public OracleTableColumn getAttribute(DBRProgressMonitor monitor, String attributeName) throws DBException {
// Fake XML attribute handle
if (tableType != null && tableType.getName().equals(OracleConstants.TYPE_NAME_XML) && OracleConstants.XML_COLUMN_NAME.equals(attributeName)) {
/*
for (OracleTableColumn col : CommonUtils.safeCollection(getAttributes(monitor))) {
if (col.getType() == tableType) {
return col;
}
}
*/
if (objectValueAttribute == null) {
objectValueAttribute = new OracleTableColumn(this);
objectValueAttribute.setName(OracleConstants.OBJECT_VALUE_COLUMN_NAME);
objectValueAttribute.setTypeName(tableType.getTypeName());
objectValueAttribute.setType(tableType);
objectValueAttribute.setOrdinalPosition(1);
}
return objectValueAttribute;
OracleTableColumn col = getXMLColumn(monitor);
if (col != null) return col;
}
return super.getAttribute(monitor, attributeName);
}
@Nullable
private OracleTableColumn getXMLColumn(DBRProgressMonitor monitor) throws DBException {
for (OracleTableColumn col : CommonUtils.safeCollection(getAttributes(monitor))) {
if (col.getType() == tableType) {
return col;
}
}
return null;
}
@Override
public Collection<OracleTableForeignKey> getReferences(DBRProgressMonitor monitor)
......@@ -204,14 +201,21 @@ public class OracleTable extends OracleTablePhysical implements DBDPseudoAttribu
}
@Override
protected void appendSelectSource(StringBuilder query, String tableAlias, DBDPseudoAttribute rowIdAttribute) {
protected void appendSelectSource(DBRProgressMonitor monitor, StringBuilder query, String tableAlias, DBDPseudoAttribute rowIdAttribute) {
if (tableType != null && tableType.getName().equals(OracleConstants.TYPE_NAME_XML)) {
query.append("XMLType(value(").append(tableAlias).append(").getClobval()) as XML");
if (rowIdAttribute != null) {
query.append(",").append(rowIdAttribute.translateExpression(tableAlias));
try {
OracleTableColumn xmlColumn = getXMLColumn(monitor);
if (xmlColumn != null) {
query.append("XMLType(").append(tableAlias).append(".").append(xmlColumn.getName()).append(".getClobval()) as ").append(xmlColumn.getName());
if (rowIdAttribute != null) {
query.append(",").append(rowIdAttribute.translateExpression(tableAlias));
}
return;
}
} catch (DBException e) {
log.warn(e);
}
} else {
super.appendSelectSource(query, tableAlias, rowIdAttribute);
}
super.appendSelectSource(monitor, query, tableAlias, rowIdAttribute);
}
}
......@@ -116,13 +116,7 @@ public class JDBCContentBLOB extends JDBCContentLOB {
this.storage = new TemporaryContentStorage(application, tempFile);
}
// Free blob - we don't need it anymore
try {
blob.free();
} catch (Throwable e) {
log.debug(e);
} finally {
blob = null;
}
releaseBlob();
}
return storage;
}
......@@ -131,6 +125,11 @@ public class JDBCContentBLOB extends JDBCContentLOB {
public void release()
{
releaseTempStream();
releaseBlob();
super.release();
}
private void releaseBlob() {
if (blob != null) {
try {
blob.free();
......@@ -139,7 +138,6 @@ public class JDBCContentBLOB extends JDBCContentLOB {
}
blob = null;
}
super.release();
}
private void releaseTempStream() {
......
......@@ -114,14 +114,8 @@ public class JDBCContentCLOB extends JDBCContentLOB implements DBDContent {
}
this.storage = new TemporaryContentStorage(application, tempFile);
}
// Free blob - we don't need it anymore
try {
clob.free();
} catch (Throwable e) {
log.debug(e);
} finally {
clob = null;
}
// Free lob - we don't need it anymore
releaseClob();
}
return storage;
}
......@@ -130,6 +124,11 @@ public class JDBCContentCLOB extends JDBCContentLOB implements DBDContent {
public void release()
{
releaseTempStream();
releaseClob();
super.release();
}
private void releaseClob() {
if (clob != null) {
try {
clob.free();
......@@ -138,7 +137,6 @@ public class JDBCContentCLOB extends JDBCContentLOB implements DBDContent {
}
clob = null;
}
super.release();
}
private void releaseTempStream() {
......
......@@ -46,7 +46,6 @@ public class JDBCContentXML extends JDBCContentLOB {
static final Log log = Log.getLog(JDBCContentXML.class);
private SQLXML xml;
protected Reader tmpReader;
public JDBCContentXML(DBPDataSource dataSource, SQLXML xml) {
super(dataSource);
......@@ -79,13 +78,7 @@ public class JDBCContentXML extends JDBCContentLOB {
throw new DBCException(e, dataSource);
}
// Free blob - we don't need it anymore
try {
xml.free();
} catch (Exception e) {
log.warn(e);
} finally {
xml = null;
}
releaseXML();
}
return storage;
}
......@@ -93,21 +86,21 @@ public class JDBCContentXML extends JDBCContentLOB {
@Override
public void release()
{
if (tmpReader != null) {
ContentUtils.close(tmpReader);
tmpReader = null;
}
// if (xml != null) {
// try {
// xml.free();
// } catch (Exception e) {
// log.warn(e);
// }
// xml = null;
// }
releaseXML();
super.release();
}
private void releaseXML() {
if (xml != null) {
try {
xml.free();
} catch (Exception e) {
log.warn(e);
}
xml = null;
}
}
@Override
public void bindParameter(
JDBCSession session,
......
......@@ -62,6 +62,9 @@ public class JDBCRowId implements DBDValue {
@Override
public String toString()
{
if (value == null) {
return "null";
}
return new String(value.getBytes());
}
}
......@@ -142,7 +142,7 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte
StringBuilder query = new StringBuilder(100);
query.append("SELECT ");
appendSelectSource(query, tableAlias, rowIdAttribute);
appendSelectSource(session.getProgressMonitor(), query, tableAlias, rowIdAttribute);
query.append(" FROM ").append(getFullQualifiedName());
if (tableAlias != null) {
query.append(" ").append(tableAlias); //$NON-NLS-1$
......@@ -238,7 +238,7 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte
}
}
protected void appendSelectSource(StringBuilder query, String tableAlias, DBDPseudoAttribute rowIdAttribute) {
protected void appendSelectSource(DBRProgressMonitor monitor, StringBuilder query, String tableAlias, DBDPseudoAttribute rowIdAttribute) {
if (rowIdAttribute != null) {
// If we have pseudo attributes then query gonna be more complex
query.append(tableAlias).append(".*"); //$NON-NLS-1$
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册