Skip to content

Commit

Permalink
Merge pull request #25 from support-project/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
koda-masaru authored Mar 20, 2017
2 parents 37339c7 + 290bc19 commit a04d0b3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.support-project</groupId>
<artifactId>common</artifactId>
<version>1.7.0</version>
<version>1.8.0</version>
<packaging>jar</packaging>

<name>common</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ public static void load(ResultSet rs, Object object, String driverClass) {
Blob blob = rs.getBlob(column);
// いったんメモリ内のみで制御
// TODO Out of Memory になる可能性があるため、必要に応じファイルIOで処理する
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileUtil.copy(blob.getBinaryStream(), out);
ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray());
PropertyUtil.setPropertyValue(object, prop, inputStream);
if (blob != null && blob.getBinaryStream() != null) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileUtil.copy(blob.getBinaryStream(), out);
ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray());
PropertyUtil.setPropertyValue(object, prop, inputStream);
}
} else {
// Postgresql
LOG.trace("Postgresql LOB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public PrintWriter getPrintWriter(File file) {
FileOutputStream outputStream = new FileOutputStream(file);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, Charset.forName("UTF-8"));
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
return new PrintWriter(bufferedWriter);
return new DebugAblePrintWriter(bufferedWriter);
} catch (FileNotFoundException e) {
throw new ORMappingException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.support.project.ormapping.tool.impl;

import java.io.PrintWriter;
import java.io.Writer;

public class DebugAblePrintWriter extends PrintWriter {
private StringBuilder builder;
public DebugAblePrintWriter(Writer out) {
super(out);
builder = new StringBuilder();
}
/* (non-Javadoc)
* @see java.io.PrintWriter#print(java.lang.String)
*/
@Override
public void print(String s) {
builder.append(s);
super.print(s);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public List<String> getSelectOnSqlFileNames() {
return list;
}
for (ColumnDefinition primary : primaryKeys) {
list.add(config.getDaoClassName() + "_select_on_" + primary.getColumn_name().toLowerCase() + ".sql");
if (!primary.getColumn_name().toLowerCase().equals("key")) {
list.add(config.getDaoClassName() + "_select_on_" + primary.getColumn_name().toLowerCase() + ".sql");
}
}
return list;
}
Expand Down Expand Up @@ -307,8 +309,10 @@ private void createSelectOn() {

int idx = 0;
for (ColumnDefinition primary : primaryKeys) {
String fileName = sqls.get(idx++);
createSelectOn(primary, fileName);
if (!primary.getColumn_name().toLowerCase().equals("key")) {
String fileName = sqls.get(idx++);
createSelectOn(primary, fileName);
}
}
}

Expand Down Expand Up @@ -369,6 +373,7 @@ private void createSelectOnKeySqlFile() {
}
pw.println(";");
pw.flush();
log.debug(pw.toString());
} finally {
if (pw != null) {
pw.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ private void writeSelectOn(PrintWriter pw) {
List<String> fileNames = sqlCreator.getSelectOnSqlFileNames();
int idx = 0;
for (ColumnDefinition primary : primaryKeys) {
String fileName = fileNames.get(idx++);
writeSelectOn(pw, primary, fileName);
if (!primary.getColumn_name().toLowerCase().equals("key")) {
String fileName = fileNames.get(idx++);
writeSelectOn(pw, primary, fileName);
}
}
}

Expand Down

0 comments on commit a04d0b3

Please sign in to comment.