Skip to content

Commit

Permalink
Updates to CSV code to avoid java heap space errors.
Browse files Browse the repository at this point in the history
Change-Id: Idce3cf04e0e0806ef32d87cd1e380e4e860db7fd
  • Loading branch information
adufilie committed Oct 31, 2012
1 parent 391d118 commit d78ee98
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 145 deletions.
51 changes: 23 additions & 28 deletions WeaveAdmin/src/AdminConsole.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
*/
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#7B96B6" creationComplete="handleCreationComplete()" creationPolicy="all" xmlns:managers="weave.ui.admin.managers.*" xmlns:admin="weave.ui.admin.*" xmlns:ui="weave.ui.*">
<mx:Script>
<![CDATA[
import flash.desktop.Clipboard;
import flash.desktop.ClipboardFormats;
import weave.ui.DraggablePanel;
import weave.ui.TranslationPanel;
]]>
</mx:Script>
<!-- cornerRadius="0" -->
<mx:Panel
headerHeight="25"
Expand Down Expand Up @@ -106,26 +97,30 @@

<mx:Script>
<![CDATA[
import weave.ui.SessionStateEditor;
import weave.api.reportError;
import weave.api.WeaveAPI;
import weave.data.CSVParser;
import flash.desktop.Clipboard;
import flash.desktop.ClipboardFormats;
import mx.binding.utils.BindingUtils;
import mx.controls.Alert;
import mx.controls.TextArea;
import mx.managers.PopUpManager;
import weave.Strings;
import weave.Weave;
import weave.api.WeaveAPI;
import weave.api.reportError;
import weave.services.AdminInterface;
import weave.services.WeaveAdminService;
import weave.ui.DraggablePanel;
import weave.ui.SessionStateEditor;
import weave.ui.TranslationPanel;
import weave.ui.WeaveProgressBar;
import weave.ui.admin.LoginPopup;
import weave.ui.admin.WizardPanel;
import weave.ui.admin.wizards.CSVImportWizard;
import weave.ui.admin.wizards.SHPImportWizard;
import weave.ui.admin.wizards.SQLImportWizard;
import weave.utils.VectorUtils;
import mx.binding.utils.BindingUtils;
import mx.controls.Alert;
import mx.controls.TextArea;
import mx.managers.PopUpManager;
import weave.Strings;
import weave.Weave;
import weave.services.AdminInterface;
import weave.services.WeaveAdminService;
import weave.ui.WeaveProgressBar;
import weave.ui.admin.LoginPopup;
import weave.ui.admin.WizardPanel;
import weave.ui.admin.wizards.CSVImportWizard;
import weave.ui.admin.wizards.SHPImportWizard;
import weave.ui.admin.wizards.SQLImportWizard;
SessionStateEditor.getInstance(); // adds keyboard shortcut f8 to open console
Expand Down
6 changes: 0 additions & 6 deletions WeaveAdmin/src/weave/services/WeaveAdminService.as
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,6 @@ package weave.services
//query.addAsyncResponder(alertResult);
return query;
}
public function getCSVStringData(csvFile:String):DelayedAsyncInvocation
{
var query:DelayedAsyncInvocation = invokeAdminService("getCSVStringData", arguments);
//query.addAsyncResponder(alertResult);
return query;
}
public function listDBFFileColumns(dbfFileName:String):DelayedAsyncInvocation
{
var query:DelayedAsyncInvocation = invokeAdminService("listDBFFileColumns", arguments);
Expand Down
1 change: 0 additions & 1 deletion WeaveAdmin/src/weave/ui/admin/wizards/CSVImportWizard.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
finishEnabled = false;
AdminInterface.instance.service.getCSVColumnNames(tableName).addAsyncResponder(handleGetCSVColumnNames,handleCSVFault,tableName);
// AdminInterface.instance.service.getCSVStringData(tableName).addAsyncResponder(handleGetCSVStringData,handleCSVFault);
csvFileNameInput.text = tableName;
tableName = tableName.substring(0,tableName.lastIndexOf("."));
Expand Down
8 changes: 4 additions & 4 deletions WeaveMobileClient/.actionScriptProperties
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark_dmv.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_dmv.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_flashflexkit.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/air/applicationupdater_ui.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/air/airframework.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/air/applicationupdater_ui.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_flashflexkit.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_agent.swc" useDefaultLinkType="false"/>
</excludedEntries>
</libraryPathEntry>
Expand Down Expand Up @@ -93,10 +93,10 @@
<flashCatalyst validateFlashCatalystCompatibility="false"/>
<buildTargets>
<buildTarget buildTargetName="com.adobe.flexide.multiplatform.ios.platform" iosSettingsVersion="1" provisioningFile="d:/Dropbox/weave-mobile/Sanjay_Weave_IOS.mobileprovision" releasePackageType="ipa-ad-hoc">
<multiPlatformSettings enabled="true" includePlatformLibs="false" platformID="com.adobe.flexide.multiplatform.ios.platform" version="2"/>
<airSettings airCertificatePath="D:/Dropbox/weave-mobile/iphone_dev.p12" airTimestamp="true" version="1">
<airExcludes/>
</airSettings>
<multiPlatformSettings enabled="true" includePlatformLibs="false" platformID="com.adobe.flexide.multiplatform.ios.platform" version="2"/>
<actionScriptSettings version="1"/>
</buildTarget>
<buildTarget buildTargetName="com.qnx.flexide.multiplatform.qnx.platform">
Expand All @@ -107,10 +107,10 @@
<actionScriptSettings version="1"/>
</buildTarget>
<buildTarget androidSettingsVersion="1" buildTargetName="com.adobe.flexide.multiplatform.android.platform">
<multiPlatformSettings enabled="true" includePlatformLibs="false" platformID="com.adobe.flexide.multiplatform.android.platform" version="2"/>
<airSettings airCertificatePath="d:/Dropbox/weave-mobile/my-mobile-cert.p12" airTimestamp="true" version="1">
<airExcludes/>
</airSettings>
<multiPlatformSettings enabled="true" includePlatformLibs="false" platformID="com.adobe.flexide.multiplatform.android.platform" version="2"/>
<actionScriptSettings version="1"/>
</buildTarget>
<buildTarget buildTargetName="default">
Expand Down
81 changes: 12 additions & 69 deletions WeaveServices/src/weave/servlets/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ public AttributeColumnInfo[] testAllQueries(String connectionName, String passwo

if (sqlParams != null && sqlParams.length() > 0)
{
String[] sqlParamsArray = CSVParser.defaultParser.parseCSV(sqlParams)[0];
String[] sqlParamsArray = CSVParser.defaultParser.parseCSV(sqlParams, true)[0];
result = SQLConfigUtils.getRowSetFromQuery(config, attributeColumnInfo.connection, query, sqlParamsArray);
}
else
Expand Down Expand Up @@ -1076,7 +1076,7 @@ public String[] getCSVColumnNames(String csvFile) throws RemoteException
{
BufferedReader in = new BufferedReader(new FileReader(new File(uploadPath, csvFile)));
String header = in.readLine();
String[][] rows = CSVParser.defaultParser.parseCSV(header);
String[][] rows = CSVParser.defaultParser.parseCSV(header, true);
headerLine = rows[0];
}
catch (FileNotFoundException e)
Expand All @@ -1088,32 +1088,6 @@ public String[] getCSVColumnNames(String csvFile) throws RemoteException
throw new RemoteException(e.getMessage());
}

/*
* Old code
*
try
{
String csvData = org.apache.commons.io.FileUtils.readFileToString(new File(uploadPath, csvFile));
// Read first line only (header line).
int index = csvData.indexOf("\r");
int index2 = csvData.indexOf("\n");
if (index2 < index && index2 >= 0)
index = index2;
String header = index < 0 ? csvData : csvData.substring(0, index);
csvData = null; // don't need this in memory anymore
String[][] rows = CSVParser.defaultParser.parseCSV(header);
headerLine = rows[0];
}
catch (FileNotFoundException e)
{
throw new RemoteException(e.getMessage());
}
catch (Exception e)
{
throw new RemoteException(e.getMessage());
}
*/

return headerLine;
}

Expand Down Expand Up @@ -1147,9 +1121,7 @@ public Boolean checkKeyColumnForCSVImport(String csvFile,String keyColumn,String
}
}

String csvData = org.apache.commons.io.FileUtils.readFileToString(new File(uploadPath, csvFile));

String[][] rows = CSVParser.defaultParser.parseCSV(csvData);
String[][] rows = CSVParser.defaultParser.parseCSV(new File(uploadPath, csvFile), true);

HashMap<String, Boolean> map = new HashMap<String, Boolean>();

Expand Down Expand Up @@ -1208,35 +1180,6 @@ public Boolean checkKeyColumnForCSVImport(String csvFile,String keyColumn,String

return isUnique;
}


/**
* Read a csv file and return the csv data string .
*
* @param A csv file name
*
* @return the csv data string
*
*/
public String getCSVStringData(String csvFile) throws RemoteException
{
String csvString = null;

try
{
csvString = org.apache.commons.io.FileUtils.readFileToString(new File(uploadPath, csvFile));
}
catch (FileNotFoundException e)
{
throw new RemoteException(e.getMessage());
}
catch (Exception e)
{
throw new RemoteException(e.getMessage());
}

return csvString;
}

public String[] listDBFFileColumns(String dbfFileName) throws RemoteException
{
Expand Down Expand Up @@ -1431,9 +1374,7 @@ synchronized public String importCSV(String connectionName, String password, Str

boolean ignoreKeyColumnQueries = false;

String csvData = org.apache.commons.io.FileUtils.readFileToString(new File(uploadPath, csvFile),"ISO-8859-1");

String[][] rows = CSVParser.defaultParser.parseCSV(csvData);
String[][] rows = CSVParser.defaultParser.parseCSV(new File(uploadPath, csvFile), true);

if (rows.length == 0)
throw new RemoteException("CSV file is empty: " + csvFile);
Expand Down Expand Up @@ -1611,10 +1552,7 @@ synchronized public String importCSV(String connectionName, String password, Str
}
// save modified CSV
// BufferedWriter out = new BufferedWriter(new FileWriter(formatted_CSV_path));
File out = new File(formatted_CSV_path);

String temp = SQLUtils.generateCSV(conn, rows);
org.apache.commons.io.FileUtils.writeStringToFile(out, temp, "ISO-8859-1");
SQLUtils.generateCSV(conn, rows, new File(formatted_CSV_path));

// Import the CSV file into SQL.
// Drop the table if it exists.
Expand Down Expand Up @@ -1725,6 +1663,7 @@ synchronized private String addConfigDataTable(
String[] filterColumnNames
) throws RemoteException
{
String failMessage = String.format("Failed to add DataTable \"%s\" to the configuration.\n", configDataTableName);
if (sqlColumnNames == null || sqlColumnNames.length == 0)
throw new RemoteException("No columns were found.");
ConnectionInfo info = config.getConnectionInfo(connectionName);
Expand Down Expand Up @@ -1855,11 +1794,15 @@ synchronized private String addConfigDataTable(
}
catch (SQLException e)
{
throw new RemoteException(String.format("Failed to add DataTable \"%s\" to the configuration.\n", configDataTableName), e);
throw new RemoteException(failMessage, e);
}
catch (RemoteException e)
{
throw new RemoteException(String.format("Failed to add DataTable \"%s\" to the configuration.\n", configDataTableName), e);
throw new RemoteException(failMessage, e);
}
catch (IOException e)
{
throw new RemoteException(failMessage, e);
}

return String.format("DataTable \"%s\" was added to the configuration with %s generated attribute column queries.\n", configDataTableName, titles.size());
Expand Down
4 changes: 2 additions & 2 deletions WeaveServices/src/weave/servlets/DataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public WeaveRecordList getRows(String keyType, String[] keysArray) throws Remote
SQLResult result;
if (sqlParams != null && sqlParams.length() > 0)
{
String[] sqlParamsArray = CSVParser.defaultParser.parseCSV(sqlParams)[0];
String[] sqlParamsArray = CSVParser.defaultParser.parseCSV(sqlParams, true)[0];
result = SQLConfigUtils.getRowSetFromQuery(config, info.connection, sqlQuery, sqlParamsArray);
}
else
Expand Down Expand Up @@ -364,7 +364,7 @@ public AttributeColumnDataWithKeys getAttributeColumn(Map<String, String> params

if (sqlParams != null && sqlParams.length() > 0)
{
String[] args = CSVParser.defaultParser.parseCSV(sqlParams)[0];
String[] args = CSVParser.defaultParser.parseCSV(sqlParams, true)[0];
result = SQLConfigUtils.getRowSetFromQuery(config, info.connection, dataWithKeysQuery, args);
}
else
Expand Down
2 changes: 1 addition & 1 deletion WeaveServices/src/weave/servlets/GenericServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ else if (expectedArgTypes[index] == boolean.class || expectedArgTypes[index] ==
}
else if (expectedArgTypes[index] == String[].class || expectedArgTypes[index] == List.class)
{
String[][] table = CSVParser.defaultParser.parseCSV((String)value);
String[][] table = CSVParser.defaultParser.parseCSV((String)value, true);
if (table.length == 0)
value = new String[0]; // empty
else
Expand Down
9 changes: 2 additions & 7 deletions WeaveServices/src/weave/tests/TestCSV.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.File;

import org.apache.commons.io.FileUtils;
import weave.utils.CSVParser;

public class TestCSV
Expand All @@ -33,13 +32,9 @@ public static void main(String[] args) throws Exception
{
File file = new File("src/weave/tests/test.csv");
System.out.println(file.getAbsolutePath());
String csvData = FileUtils.readFileToString(file);

System.out.println(csvData);
System.out.println();

System.out.println("parseCSV(csvData)");
String[][] parsedRows = CSVParser.defaultParser.parseCSV(csvData);
String[][] parsedRows = CSVParser.defaultParser.parseCSV(file, true);
for (int i = 0; i < parsedRows.length; i++)
{
for (int j = 0; j < parsedRows[i].length; j++)
Expand All @@ -48,7 +43,7 @@ public static void main(String[] args) throws Exception
System.out.println("Compare these results with Microsoft Excel\n");

System.out.println("parseCSV(csvData, false), parseCSVToken, createCSVToken, parseCSVToken");
String[][] rows = CSVParser.defaultParser.parseCSV(csvData, true); // assuming this isn't sql server
String[][] rows = CSVParser.defaultParser.parseCSV(file, true); // assuming this isn't sql server
for (int i = 0; i < rows.length; i++)
{
for (int j = 0; j < rows[i].length; j++)
Expand Down
Loading

0 comments on commit d78ee98

Please sign in to comment.