IDEMPIERE-3508 2pack: support export from text column to string column (#674)

This commit is contained in:
Carlos Ruiz 2021-05-04 16:42:17 +02:00 committed by GitHub
parent b002667750
commit 9d40f6b5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -85,6 +85,8 @@ public class PackOut
public static final int MAX_OFFICIAL_ID = MTable.MAX_OFFICIAL_ID; public static final int MAX_OFFICIAL_ID = MTable.MAX_OFFICIAL_ID;
public static final String PACKOUT_BLOB_FILE_EXTENSION = ".dat";
public static void addTextElement(TransformerHandler handler, String qName, String text, AttributesImpl atts) throws SAXException { public static void addTextElement(TransformerHandler handler, String qName, String text, AttributesImpl atts) throws SAXException {
handler.startElement("", "", qName, atts); handler.startElement("", "", qName, atts);
append(handler, text); append(handler, text);
@ -381,7 +383,7 @@ public class PackOut
*/ */
public String writeBlob(byte[] data) throws IOException { public String writeBlob(byte[] data) throws IOException {
blobCount++; blobCount++;
String fileName = blobCount + ".dat"; String fileName = blobCount + PACKOUT_BLOB_FILE_EXTENSION;
File path = new File(packageDirectory+File.separator+"blobs"+File.separator); File path = new File(packageDirectory+File.separator+"blobs"+File.separator);
path.mkdirs(); path.mkdirs();
File file = new File(path, fileName); File file = new File(path, fileName);

View File

@ -39,6 +39,9 @@ public class PoExporter {
private TransformerHandler transformerHandler; private TransformerHandler transformerHandler;
public static final String POEXPORTER_BLOB_TYPE_STRING = "string";
public static final String POEXPORTER_BLOB_TYPE_BYTEARRAY = "byte[]";
private void addTextElement(String qName, String text, AttributesImpl atts) { private void addTextElement(String qName, String text, AttributesImpl atts) {
try { try {
transformerHandler.startElement("", "", qName, atts); transformerHandler.startElement("", "", qName, atts);
@ -337,15 +340,15 @@ public class PoExporter {
PackOut packOut = ctx.packOut; PackOut packOut = ctx.packOut;
byte[] data = null; byte[] data = null;
String dataType = null; String dataType = null; // see PoFiller.isBlobOnPackinFile
String fileName = null; String fileName = null;
try { try {
if (value instanceof String) { if (value instanceof String) {
data = ((String)value).getBytes("UTF-8"); data = ((String)value).getBytes("UTF-8");
dataType = "string"; dataType = POEXPORTER_BLOB_TYPE_STRING;
} else { } else {
data = (byte[]) value; data = (byte[]) value;
dataType = "byte[]"; dataType = POEXPORTER_BLOB_TYPE_BYTEARRAY;
} }
fileName = packOut.writeBlob(data); fileName = packOut.writeBlob(data);

View File

@ -59,8 +59,10 @@ public class PoFiller{
return false; return false;
String strParts [] = value.split("[|]"); String strParts [] = value.split("[|]");
return strParts.length == 2; return ( strParts.length == 2
&& strParts[0].endsWith(PackOut.PACKOUT_BLOB_FILE_EXTENSION)
&& ( PoExporter.POEXPORTER_BLOB_TYPE_STRING.equals(strParts[1]) // see PoExporter.addBlob
|| PoExporter.POEXPORTER_BLOB_TYPE_BYTEARRAY.equals(strParts[1])));
} }
/** /**
@ -357,11 +359,15 @@ public class PoFiller{
} }
} else if (DisplayType.isLOB(info.getColumnDisplayType(index))) { } else if (DisplayType.isLOB(info.getColumnDisplayType(index))) {
setBlob(qName); setBlob(qName);
} else {
if (isBlobOnPackinFile(qName)) {
setBlob(qName);
} else { } else {
setString(qName); setString(qName);
} }
} }
} }
}
return notFounds; return notFounds;
} }
@ -410,7 +416,7 @@ public class PoFiller{
PackIn packIn = ctx.packIn; PackIn packIn = ctx.packIn;
try { try {
bytes = packIn.readBlob(fileName); bytes = packIn.readBlob(fileName);
if ("byte[]".equals(dataType)) { if (PoExporter.POEXPORTER_BLOB_TYPE_BYTEARRAY.equals(dataType)) {
data = bytes; data = bytes;
} else { } else {
data = new String(bytes, "UTF-8"); data = new String(bytes, "UTF-8");