Skip to content

Commit

Permalink
Recreating the test Excel file
Browse files Browse the repository at this point in the history
  • Loading branch information
palych-piter committed May 29, 2017
1 parent e88702e commit a602eaf
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 15 deletions.
1 change: 1 addition & 0 deletions build/libs/.gradle/2.13/taskArtifacts/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Mon May 29 17:23:29 MSK 2017
17 changes: 17 additions & 0 deletions build/libs/excel2db.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# names of input tables
input.files=test.xlsx

# db implementation classes

# postgres section
# dbConnectionImplenentation=excel2db.service.impl.DBConnectionPostgresImpl
# oracle section
dbConnectionImplenentation=excel2db.service.impl.DBConnectionOracleImpl

# postgres connection parameters
db.server=localhost
db.database=excel2db
db.port=5433
db.user=postgres
db.password=postgres

2 changes: 1 addition & 1 deletion build/resources/main/excel2db.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# names of input tables
input.files=test.xls
input.files=test.xlsx

# db implementation classes

Expand Down
26 changes: 22 additions & 4 deletions src/main/java/excel2db/excel2db.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;

import excel2db.ApplicationException;
import excel2db.service.CreateTable;
Expand Down Expand Up @@ -65,7 +67,6 @@ public static void main(String[] args) {

try {


//for profiling, to launch the VisualVM first,
// then start the application by pressing the Enter
//System.in.read();
Expand All @@ -75,19 +76,36 @@ public static void main(String[] args) {

taskExecutor = (ThreadPoolTaskExecutor) context.getBean("taskExecutor");

//check if the file list is not empty
HashSet<String> fileList = app.generateFileList.generateFileList();
if (fileList == null){
throw new Exception("File list is empty in property file");
//logger.error("Empty file list");
}

//this way we call methods for objects that is already initialized by the Spring
app.dbConnection.establishDBConnection();

// iterate through file name values in properties file,
// for each file start a new thread
for (String fileNameValue : app.generateFileList.generateFileList()) {
for (String fileNameValue : fileList) {

File fileName = new File(fileNameValue);
taskExecutor.execute(new Excel2dbTask(app, fileName));
//check if the file really exists
if (fileName.exists() == false) {
logger.error("The file " + fileNameValue + " doesn't exist");
} else {
taskExecutor.execute(new Excel2dbTask(app, fileName));
}

}

//TODO : This is just as a workaround to wait till the thread has been really started
//TODO : Need to use the ScheduledThreadPoolExecutor to customize delays on starting threads
TimeUnit.SECONDS.sleep(1);
// Wait until all threads are finished
logger.info("Waiting until active threads exist");
while (excel2db.taskExecutor.getActiveCount() != 0) {
while (taskExecutor.getActiveCount() != 0) {
}
logger.info("All threads are inactive");

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/excel2db/service/impl/GenerateFileListImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ public class GenerateFileListImpl implements GenerateFileList {
@Override
public HashSet<String> generateFileList() {

String[] fileNameArray = inputFilesList.split(",");

// hash set to eliminate duplicates
HashSet<String> fileList = new HashSet<>(Arrays.asList(fileNameArray));

HashSet<String> fileList = null;
if (!inputFilesList.isEmpty()) {
String[] fileNameArray = inputFilesList.split(",");
// hash set to eliminate duplicates
fileList = new HashSet<>(Arrays.asList(fileNameArray));
}
return fileList;

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/excel2db.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# names of input tables
input.files=test.xls
input.files=test.xlsx

# db implementation classes

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/InitInputFilesImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public void testInitInputFilesImpl() throws Exception {
excel2db app = (excel2db) context.getBean("excel2db");

//executing the test
File fileName = new File(app.initConstants.workingDir + "/test.xls");
File fileName = new File(app.initConstants.workingDir + "/test.xlsx");

//here we should initialize the sheet object
assertEquals("UnitTestSheet", app.initInputFiles.initInputFiles(fileName).getSheetName());
assertEquals("TestSheet", app.initInputFiles.initInputFiles(fileName).getSheetName());

}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/PopulateTablePostgresImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public void testPopulateTable() throws Exception {
excel2db app = (excel2db) context.getBean("excel2db");

//executing the test
File fileName = new File(app.initConstants.workingDir + "/test.xls");
File fileName = new File(app.initConstants.workingDir + "/test.xlsx");
sheet = app.initInputFiles.initInputFiles(fileName);
app.dbConnection.establishDBConnection();
app.createTable.createTable(sheet, "testTable");

//here we should initialize the sheet object
Integer numOfProcessedRows = app.populateTable.populateTable(sheet, "testTable");
assertEquals(Integer.valueOf(9), numOfProcessedRows);
assertEquals(Integer.valueOf(2), numOfProcessedRows);

}
}

0 comments on commit a602eaf

Please sign in to comment.