import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.net.InetAddress;
+import java.net.URL;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.sql.Connection;
* @author chm
*/
public class MySqlDataLayer extends AbstractDataImpl {
+ /**
+ *
+ */
+ private static final String MYSQL_QUERIES_PROPERTIES = "mysql-queries.properties";
static final transient String PARAM_TABLE_NAME = "PARAMETERS";
private static final transient String ELEMENT_DOC_CONFIGS_OVR = "document.config.override";
/**
}
ps.setString(3, pj.getPjName());
ps.setString(4, pj.getFileName());
+
+ InputStream dataInpStr = null;
+ int pjLength = (int) pj.getUncompressedSize();
+
if ((pj.getData() != null) && (pj.getData().length > 0)) {
- ps.setBinaryStream(5, pj.getDataInputStream(), (int) pj.getUncompressedSize());
+ dataInpStr = pj.getDataInputStream();
} else if (pj.getTmpFileName() != null) {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final byte[] buffer = new byte[1024];
- final FileInputStream fis = new FileInputStream(pj.getTmpFileName());
- int read = fis.read(buffer);
- while (read > 0) {
- baos.write(buffer, 0, read);
- read = fis.read(buffer);
- }
- fis.close();
- baos.flush();
- baos.close();
- ps.setBinaryStream(5, new ByteArrayInputStream(baos.toByteArray()), (int) pj.getUncompressedSize());
+ dataInpStr = new FileInputStream(pj.getTmpFileName());
} else {
- ps.setBinaryStream(5, new ByteArrayInputStream(new byte[0]), 0);
+ dataInpStr = new ByteArrayInputStream(new byte[0]);
+ pjLength = 0;
+ }
+
+ ps.setBinaryStream(5, dataInpStr, pjLength);
+
+ try {
+ ps.executeUpdate();
+ } finally {
+ dataInpStr.close();
}
- ps.executeUpdate();
} catch (final SQLException sqlEx) {
throw new DataAccessException(sqlEx);
} catch (final Exception ex) {
// pas de commit, la transaction est en auto-commit
}
+ @Override
+ protected URL getSpecificQueryFile() {
+ return MySqlDataLayer.class.getResource(MYSQL_QUERIES_PROPERTIES);
+ }
+
}