|
|
@@ -1,584 +0,0 @@
|
|
|
-/**
|
|
|
- * HISTORY
|
|
|
- * FIOALE - 27.07.2004
|
|
|
- * + Aggiunta implementazione setInIntFk che permette di inserire NULL nel db
|
|
|
- * per i valori numerici interi. Da usare solo per rispettare le relazioni
|
|
|
- * BASLUC - 13.07.2005
|
|
|
- * + Aggiunta funzione come da modifica intf
|
|
|
- * BASLUC - 14.07.2005
|
|
|
- * ~ Corretta l'impl della setInStringFk() per via del != e dell'equals...
|
|
|
- */
|
|
|
-
|
|
|
-package commons.utility.database.postgressql;
|
|
|
-
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.sql.Blob;
|
|
|
-import java.sql.CallableStatement;
|
|
|
-import java.sql.ResultSet;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.sql.Timestamp;
|
|
|
-import java.sql.Types;
|
|
|
-import java.util.GregorianCalendar;
|
|
|
-
|
|
|
-import commons.utility.Compression;
|
|
|
-import commons.utility.database.IResultSet;
|
|
|
-import commons.utility.database.ISpStatement;
|
|
|
-import commons.utility.database.NullValue;
|
|
|
-import commons.exception.ZCompressException;
|
|
|
-import commons.exception.ZDataBaseException;
|
|
|
-
|
|
|
-class PostgresSqStatement implements ISpStatement {
|
|
|
- CallableStatement m_cs = null;
|
|
|
-
|
|
|
- public PostgresSqStatement(CallableStatement cs) {
|
|
|
- m_cs = cs;
|
|
|
- }
|
|
|
-
|
|
|
- //////////////////////////////////////////////////////////////////////////////
|
|
|
- //Parametri di INPUT
|
|
|
- public void setInBlob(int pos, byte[] value, boolean compression) throws ZDataBaseException, ZCompressException {
|
|
|
- //gestione BLOB
|
|
|
- try
|
|
|
- {
|
|
|
- if (value != null) {
|
|
|
- if (compression == true)
|
|
|
- value = Compression.Compress(value);
|
|
|
- ByteArrayInputStream bais = new ByteArrayInputStream(value);
|
|
|
- m_cs.setBinaryStream(pos, bais, value.length);
|
|
|
- } else
|
|
|
- m_cs.setNull(pos, Types.BINARY);
|
|
|
- }
|
|
|
- catch (ZCompressException e)
|
|
|
- {
|
|
|
- throw e;
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- public void setInByte(int pos, byte value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.setByte(pos, value);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInDate(int pos, java.util.Date value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- if (value != null) {
|
|
|
-
|
|
|
- long ad = value.getTime();
|
|
|
- long ld = new GregorianCalendar(1850, 1, 1).getTimeInMillis();
|
|
|
-
|
|
|
- if (ad > ld)
|
|
|
- m_cs.setTimestamp(pos, new Timestamp(value.getTime()));
|
|
|
- else {
|
|
|
- System.out.println("Data formalmente errata(" + value.toString() + "). Sostituita con 01/02/1850");
|
|
|
- m_cs.setTimestamp(pos, new Timestamp(ld));
|
|
|
- }
|
|
|
- } else
|
|
|
- m_cs.setNull(pos, Types.DATE);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInDouble(int pos, double value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.setDouble(pos, value);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInFloat(int pos, float value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.setFloat(pos, value);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInInt(int pos, int value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.setInt(pos, value);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInIntFk(int pos, int value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- if (value != 0)
|
|
|
- m_cs.setInt(pos, value);
|
|
|
- else
|
|
|
- m_cs.setNull(pos, Types.INTEGER);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInLong(int pos, long value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.setLong(pos, value);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInShort(int pos, short value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.setShort(pos, value);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInString(int pos, String value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- if (value != null)
|
|
|
- m_cs.setString(pos, value.trim().toUpperCase());
|
|
|
- else
|
|
|
- m_cs.setString(pos, NullValue.STRING);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void setInStringFk(int pos, String value) throws ZDataBaseException
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (!NullValue.STRING.equals(value))
|
|
|
- m_cs.setString(pos, value);
|
|
|
- else
|
|
|
- m_cs.setString(pos, null);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Utilizzare questa funzione quando passo la mail e la password
|
|
|
- */
|
|
|
- public void setInString(int pos, String value, boolean noUpper) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- if (value != null)
|
|
|
- m_cs.setString(pos, value.trim());
|
|
|
- else
|
|
|
- m_cs.setString(pos, NullValue.STRING);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void setInStringCAP(int pos, String value) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- if (value != null)
|
|
|
- value = value.trim();
|
|
|
- else
|
|
|
- value = NullValue.STRING;
|
|
|
-
|
|
|
- if (value.equals(NullValue.STRING))
|
|
|
- value = " ";
|
|
|
-
|
|
|
- m_cs.setString(pos, value.toUpperCase());
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void setInBit(int pos, boolean value) throws ZDataBaseException {
|
|
|
- byte valore;
|
|
|
- if (value == true)
|
|
|
- valore = 1;
|
|
|
- else
|
|
|
- valore = 0;
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.setByte(pos, valore);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setInBit(int pos, String nulla) throws ZDataBaseException {
|
|
|
- if (nulla == null){
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.setByte(pos, (byte) 0);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //////////////////////////////////////////////////////////////////////////////
|
|
|
- //Parametri di OUTPUT
|
|
|
- public void setOutBlob(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.BLOB);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutByte(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.TINYINT);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutDate(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.TIMESTAMP);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutDouble(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.DOUBLE);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutFloat(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.FLOAT);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutInt(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.INTEGER);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutLong(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.BIGINT);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutShort(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.SMALLINT);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutString(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.VARCHAR);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public void setOutBit(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.registerOutParameter(pos, Types.BIT);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- //////////////////////////////////////////////////////////////////////////////
|
|
|
- //Lettura parametri di OUTPUT
|
|
|
- public byte[] getOutBlob(int pos, boolean decompress) throws ZDataBaseException, ZCompressException {
|
|
|
- byte[] value;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- Blob blob = m_cs.getBlob(pos);
|
|
|
- value = blob.getBytes(1, (int) blob.length());
|
|
|
- if (decompress == true && value != null)
|
|
|
- value = Compression.Decompress(value);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- catch (ZCompressException e)
|
|
|
- {
|
|
|
- throw e;
|
|
|
- }
|
|
|
-
|
|
|
- return value;
|
|
|
- }
|
|
|
- public byte getOutByte(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- return m_cs.getByte(pos);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public java.util.Date getOutDate(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- return new java.util.Date(m_cs.getTimestamp(pos).getTime());
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public double getOutDouble(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- return m_cs.getDouble(pos);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public float getOutFloat(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- return m_cs.getFloat(pos);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public int getOutInt(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- return m_cs.getInt(pos);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public long getOutLong(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- return m_cs.getLong(pos);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public short getOutShort(int pos) throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- return m_cs.getShort(pos);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- public String getOutString(int pos) throws ZDataBaseException {
|
|
|
- String value;
|
|
|
- try
|
|
|
- {
|
|
|
- value = m_cs.getString(pos);
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- if (value != null) {
|
|
|
- value = value.trim();
|
|
|
- } else {
|
|
|
- value = NullValue.STRING;
|
|
|
- }
|
|
|
-
|
|
|
- return value;
|
|
|
- }
|
|
|
- public boolean getOutBit(int pos) throws ZDataBaseException {
|
|
|
- boolean valore;
|
|
|
- try
|
|
|
- {
|
|
|
- if (m_cs.getByte(pos) == 1)
|
|
|
- valore = true;
|
|
|
- else
|
|
|
- valore = false;
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- return valore;
|
|
|
- }
|
|
|
- public IResultSet executeQuery() throws ZDataBaseException {
|
|
|
- ResultSet rs = null;
|
|
|
- try
|
|
|
- {
|
|
|
-
|
|
|
-// m_cs.execute();
|
|
|
-// while(true)
|
|
|
-// {
|
|
|
-// if (m_cs.getMoreResults() == false)
|
|
|
-// {
|
|
|
-// rs = m_cs.getResultSet();
|
|
|
-// if (rs != null)
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// else
|
|
|
-// break;
|
|
|
-// }
|
|
|
-
|
|
|
-// boolean nextResultSet = true;
|
|
|
-//
|
|
|
-// try
|
|
|
-// {
|
|
|
-// boolean noMoreResults = false;
|
|
|
-// boolean noMoreCount = false;
|
|
|
-//
|
|
|
-// while (!(noMoreResults && noMoreCount))
|
|
|
-// {
|
|
|
-// if (nextResultSet)
|
|
|
-// {
|
|
|
-// nextResultSet = m_cs.getMoreResults();
|
|
|
-// noMoreResults = (nextResultSet == false);
|
|
|
-// }
|
|
|
-// else
|
|
|
-// {
|
|
|
-// int updateCount = m_cs.getUpdateCount();
|
|
|
-// noMoreCount = (updateCount == -1);
|
|
|
-// if (!noMoreCount)
|
|
|
-// nextResultSet = m_cs.getMoreResults();
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// rs = m_cs.getResultSet();
|
|
|
-// }
|
|
|
-// catch (SQLException sqle)
|
|
|
-// {
|
|
|
-// throw sqle;
|
|
|
-// }
|
|
|
-
|
|
|
-// boolean results= m_cs.execute();
|
|
|
-// int rsCount = 0;
|
|
|
-//
|
|
|
-// do {
|
|
|
-// if(results) {
|
|
|
-// rs = m_cs.getResultSet();
|
|
|
-// rsCount++;
|
|
|
-//
|
|
|
-// //Show data from the result set.
|
|
|
-// System.out.println("RESULT SET #" + rsCount);
|
|
|
-// }
|
|
|
-// System.out.println();
|
|
|
-// results = m_cs.getMoreResults();
|
|
|
-// } while(results);
|
|
|
-
|
|
|
- rs = m_cs.executeQuery();
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- return new PostgresSqResultSet(rs);
|
|
|
- }
|
|
|
- public int executeUpdate() throws ZDataBaseException {
|
|
|
- try
|
|
|
- {
|
|
|
- return m_cs.executeUpdate();
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public boolean execute() throws ZDataBaseException {
|
|
|
- boolean b;
|
|
|
- try
|
|
|
- {
|
|
|
- b = m_cs.execute();
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- return b;
|
|
|
- }
|
|
|
- public void close() throws ZDataBaseException {
|
|
|
- if (m_cs != null){
|
|
|
- try
|
|
|
- {
|
|
|
- m_cs.close();
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- throw new ZDataBaseException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- m_cs = null;
|
|
|
- }
|
|
|
-
|
|
|
-}
|