[dbmodel]ModelSqlSelectService添加LOB占位符查询支持

This commit is contained in:
datagear 2019-05-05 20:21:47 +08:00
parent d6ba49ab93
commit d3abb218ac
1 changed files with 115 additions and 0 deletions

View File

@ -4,6 +4,7 @@
package org.datagear.dbmodel;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
@ -17,6 +18,8 @@ import org.datagear.model.Model;
import org.datagear.model.Property;
import org.datagear.model.support.MU;
import org.datagear.model.support.PropertyModel;
import org.datagear.persistence.columnconverter.LOBConversionContext;
import org.datagear.persistence.columnconverter.LOBConversionContext.LOBConversionSetting;
import org.datagear.persistence.support.AbstractModelDataAccessObject;
import org.datagear.persistence.support.UUID;
@ -28,11 +31,85 @@ import org.datagear.persistence.support.UUID;
*/
public class ModelSqlSelectService extends AbstractModelDataAccessObject
{
public static final byte[] DEFAULT_BLOB_TO_BYTES_PLACEHOLDER = new byte[] { 0x00 };
/** BLOB文件存储目录 */
private File blobFileManagerDirectory;
/** BLOB转文件的占位符名称 */
private String blobToFilePlaceholderName;
/** BLOB转字节数组的占位符 */
private byte[] blobToBytesPlaceholder = DEFAULT_BLOB_TO_BYTES_PLACEHOLDER;
/** CLOB的取左最大长度 */
private int clobLeftLength = 250;
/** 完全加载大对象数据的最大行号从1开始小于1表示全都占位符加载 */
private int fullLoadingLobMaxRow = 0;
public ModelSqlSelectService()
{
super();
}
public ModelSqlSelectService(File blobFileManagerDirectory, String blobToFilePlaceholderName)
{
super();
this.blobFileManagerDirectory = blobFileManagerDirectory;
this.blobToFilePlaceholderName = blobToFilePlaceholderName;
}
public File getBlobFileManagerDirectory()
{
return blobFileManagerDirectory;
}
public void setBlobFileManagerDirectory(File blobFileManagerDirectory)
{
this.blobFileManagerDirectory = blobFileManagerDirectory;
}
public String getBlobToFilePlaceholderName()
{
return blobToFilePlaceholderName;
}
public void setBlobToFilePlaceholderName(String blobToFilePlaceholderName)
{
this.blobToFilePlaceholderName = blobToFilePlaceholderName;
}
public byte[] getBlobToBytesPlaceholder()
{
return blobToBytesPlaceholder;
}
public void setBlobToBytesPlaceholder(byte[] blobToBytesPlaceholder)
{
this.blobToBytesPlaceholder = blobToBytesPlaceholder;
}
public int getClobLeftLength()
{
return clobLeftLength;
}
public void setClobLeftLength(int clobLeftLength)
{
this.clobLeftLength = clobLeftLength;
}
public int getFullLoadingLobMaxRow()
{
return fullLoadingLobMaxRow;
}
public void setFullLoadingLobMaxRow(int fullLoadingLobMaxRow)
{
this.fullLoadingLobMaxRow = fullLoadingLobMaxRow;
}
/**
* 读取SQL的查询结果集
*
@ -131,11 +208,25 @@ public class ModelSqlSelectService extends AbstractModelDataAccessObject
moveToPrevious(rs, startRow);
LOBConversionSetting contextLOBConversionSetting = LOBConversionContext.get();
LOBConversionSetting fullLoadingLOBConversionSetting = getFullLoadingLOBConversionSetting();
LOBConversionSetting placeholderLoadingLOBConversionSetting = getPlaceholderLoadingLOBConversionSetting();
LOBConversionSetting prevLOBConversionSetting = null;
for (int row = startRow; row < startRow + fetchSize; row++)
{
if (!rs.next())
break;
LOBConversionSetting myLOBConversionSetting = (row <= this.fullLoadingLobMaxRow
? fullLoadingLOBConversionSetting
: placeholderLoadingLOBConversionSetting);
if (prevLOBConversionSetting != myLOBConversionSetting)
{
LOBConversionContext.set(myLOBConversionSetting);
prevLOBConversionSetting = myLOBConversionSetting;
}
Object data = model.newInstance();
for (int j = 1; j <= columnCount; j++)
@ -155,6 +246,8 @@ public class ModelSqlSelectService extends AbstractModelDataAccessObject
datas.add(data);
}
LOBConversionContext.set(contextLOBConversionSetting);
modelSqlResult.setDatas(datas);
return modelSqlResult;
@ -243,6 +336,28 @@ public class ModelSqlSelectService extends AbstractModelDataAccessObject
return new StatementResultSetPair(st, rs);
}
/**
* 获取完全加载LOB的{@linkplain LOBConversionSetting}
*
* @return
*/
protected LOBConversionSetting getFullLoadingLOBConversionSetting()
{
return new LOBConversionSetting();
}
/**
* 获取占位符加载LOB的{@linkplain LOBConversionSetting}
*
* @return
*/
protected LOBConversionSetting getPlaceholderLoadingLOBConversionSetting()
{
File blobToFilePlaceholder = new File(this.blobFileManagerDirectory, this.blobToFilePlaceholderName);
return new LOBConversionSetting(blobToFilePlaceholder, this.blobToBytesPlaceholder, this.clobLeftLength);
}
/**
* {@linkplain Statement}{@linkplain ResultSet}封装类
*