Skip to content

Commit 760d67d

Browse files
Merge pull request #6 from vbhavsingh/master
To dump large data sets into files
2 parents add314b + 95e25c7 commit 760d67d

File tree

4 files changed

+82
-19
lines changed

4 files changed

+82
-19
lines changed

bin/sql-dumper.jar

3.58 MB
Binary file not shown.

pom.xml

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,61 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
64

7-
<groupId>de.bernhard-schlegel</groupId>
8-
<artifactId>sql_dumper</artifactId>
9-
<version>0.0.3</version>
5+
<groupId>de.bernhard-schlegel</groupId>
6+
<artifactId>sql_dumper</artifactId>
7+
<version>0.0.3</version>
108

11-
<dependencies>
12-
</dependencies>
9+
<dependencies>
10+
<dependency>
11+
<groupId>com.github.noraui</groupId>
12+
<artifactId>ojdbc7</artifactId>
13+
<version>12.1.0.2</version>
14+
</dependency>
15+
</dependencies>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-jar-plugin</artifactId>
22+
<configuration>
23+
<archive>
24+
<manifest>
25+
<mainClass>sqldump.Main</mainClass>
26+
</manifest>
27+
<manifestEntries>
28+
</manifestEntries>
29+
</archive>
30+
</configuration>
31+
</plugin>
32+
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-shade-plugin</artifactId>
36+
<version>2.4.3</version>
37+
<executions>
38+
<execution>
39+
<phase>package</phase>
40+
<goals>
41+
<goal>shade</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
<configuration>
46+
<finalName>sql-dumper</finalName>
47+
<filters>
48+
<filter>
49+
<artifact>*:*</artifact>
50+
<excludes>
51+
<exclude>META-INF/*.SF</exclude>
52+
<exclude>META-INF/*.DSA</exclude>
53+
<exclude>META-INF/*.RSA</exclude>
54+
</excludes>
55+
</filter>
56+
</filters>
57+
</configuration>
58+
</plugin>
59+
</plugins>
60+
</build>
1361
</project>

src/main/java/sqldump/SQLDump.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public void run(String[] args) {
6666

6767
File folder = new File(sqlPath);
6868
File[] listOfSQLFiles = folder.listFiles(new FilenameFilter() {
69-
@Override
7069
public boolean accept(File dir, String name) {
7170
return name.endsWith(".sql");
7271
}

src/main/java/sqldump/etl/Dump.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,49 @@ public static void toFile(ResultSet rs, String filename, Boolean append, Log log
8282
fileWriter.flush();
8383
fileWriter.close();
8484

85-
PingPong ping2 = log.info("converting data to CSV (one dot corresponds with 50k lines)");
85+
PingPong ping2 = log.info("converting data to CSV (one dot corresponds with 10k lines)");
8686
List<String> records = new ArrayList<String>();
87+
int counter =0;
8788
while (rs.next()) {
88-
89+
90+
boolean StringType = (meta.getColumnType(1) == java.sql.Types.VARCHAR);
91+
8992
StringBuffer sbRow = new StringBuffer();
90-
sbRow.append("\"" + rs.getString(1) + "\"" );
93+
if(StringType) {
94+
sbRow.append("\"" + rs.getString(1) + "\"" );
95+
}else {
96+
sbRow.append(rs.getString(1));
97+
}
9198

9299
for (int j = 2 ; j < numberOfColumns + 1 ; j ++ ) {
93-
sbRow.append(",\"" + rs.getString(j) + "\"");
100+
StringType = (meta.getColumnType(j) == java.sql.Types.VARCHAR);
101+
if(StringType) {
102+
sbRow.append(",\"" + rs.getString(j) + "\"");
103+
}else {
104+
sbRow.append("," + rs.getString(j));
105+
}
94106
}
95107
sbRow.append("\r\n");
96108
records.add(sbRow.toString());
97109

98-
if (records.size()%50000 == 0) {
110+
if (records.size()%10000 == 0) {
111+
counter+=records.size();
99112
System.out.print(".");
113+
writeBuffered(filename, records, BUFFER_SIZE, true); // always apppend
114+
records = new ArrayList<String>();
115+
sbRow.setLength(0);
100116
}
101117

102118
}
103119
log.finished(ping2);
104-
System.out.print(" (" + records.size() + " entries)");
120+
System.out.print(" (" + counter + " entries)");
105121
if (rs != null) {
106122
rs.close();
107123
}
108124

109-
PingPong ping3 = log.info("dumping CSV to file ...");
110-
writeBuffered(filename, records, BUFFER_SIZE, true); // always apppend
111-
log.finished(ping3);
125+
//PingPong ping3 = log.info("dumping CSV to file ...");
126+
//writeBuffered(filename, records, BUFFER_SIZE, true); // always apppend
127+
//log.finished(ping3);
112128

113129
log.finished(ping);
114130

0 commit comments

Comments
 (0)