Changeset 3728 in main


Ignore:
Timestamp:
04/19/12 00:07:13 (10 years ago)
Author:
Garth Braithwaite
Message:

java and view - saved query and user file_store blobs saving, retrieving and updating.

Location:
trunk/src/main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/main/java/org/ibisph/xml/service/BLOBStoredDocument.java

    r3727 r3728  
    3939  ;
    4040
     41  protected String fileStoreSQLUpdate =
     42      "update FILE_STORE " +
     43      "set CONTENT = ?, MODIFIED_DTS = ? " +
     44      "where NAME = ?"
     45    ;
     46
    4147  protected String fileStoreSQLDelete = "delete from FILE_STORE where NAME=?";
    4248
     
    7783    throws SQLException, DocumentException
    7884  {
     85    org.dom4j.Document document = null;
    7986    JDBCTemplate jdbcTemplate = this.jdbcTemplateFactory.get();
    8087    jdbcTemplate.setPreparedStatement(this.fileStoreSQLQuery);
    8188    jdbcTemplate.setPreparedStatementString(1, completePathAndFilename);
    8289    jdbcTemplate.executePreparedStatementQuery();
    83     Blob blob = jdbcTemplate.getBlob("CONTENT");
    84     Timestamp accessedDTS = jdbcTemplate.getTimestamp("ACCESSED_DTS");
    85     Timestamp modifiedDTS = jdbcTemplate.getTimestamp("MODIFIED_DTS");
    86 
    87     byte[] xmlBytes = blob.getBytes(1, (int)blob.length());
    88     org.dom4j.Document document = XMLLib.parseToNewDocument(xmlBytes);
    89 
     90    while(jdbcTemplate.next()) {
     91      Blob blob = jdbcTemplate.getBlob("CONTENT");
     92      Timestamp accessedDTS = jdbcTemplate.getTimestamp("ACCESSED_DTS");
     93      Timestamp modifiedDTS = jdbcTemplate.getTimestamp("MODIFIED_DTS");
     94      byte[] xmlBytes = blob.getBytes(1, (int)blob.length());
     95      document = XMLLib.parseToNewDocument(xmlBytes);
     96    }
    9097    return(document);
    9198  } //-------------------------- End of Method ------------------------------
     
    102109    throws IOException, UnsupportedEncodingException
    103110  {
    104 // need to try update first.  Then if no record do an insert.
    105 // need to format if outputFormat or escape set...
    106111    byte[] xmlBytes = getDocumentXMLAsByteArray(document);
    107112    Date now = new Date();
    108113    Timestamp timestamp = new Timestamp(now.getTime());
    109114    JDBCTemplate jdbcTemplate = this.jdbcTemplateFactory.get();
    110     jdbcTemplate.setPreparedStatement(this.fileStoreSQLInsert);
    111     jdbcTemplate.setPreparedStatementString   (1, completePathAndFilename);
    112     jdbcTemplate.setPreparedStatementBlob     (2, xmlBytes);
    113     jdbcTemplate.setPreparedStatementTimestamp(3, timestamp);
    114     jdbcTemplate.setPreparedStatementTimestamp(4, timestamp);
    115     jdbcTemplate.executePreparedStatement();
     115
     116    // first try to update the record.
     117    jdbcTemplate.setPreparedStatement(this.fileStoreSQLUpdate);
     118    jdbcTemplate.setPreparedStatementBlob     (1, xmlBytes);
     119    jdbcTemplate.setPreparedStatementTimestamp(2, timestamp);
     120    jdbcTemplate.setPreparedStatementString   (3, completePathAndFilename);
     121    int updatedCount = jdbcTemplate.executePreparedStatementUpdate();
     122
     123    // if no records updated then insert it.
     124    if(0 == updatedCount) {
     125      jdbcTemplate.setPreparedStatement(this.fileStoreSQLInsert);
     126      jdbcTemplate.setPreparedStatementString   (1, completePathAndFilename);
     127      jdbcTemplate.setPreparedStatementBlob     (2, xmlBytes);
     128      jdbcTemplate.setPreparedStatementTimestamp(3, timestamp);
     129      jdbcTemplate.setPreparedStatementTimestamp(4, timestamp);
     130      jdbcTemplate.executePreparedStatement();
     131    }
    116132  } //-------------------------- End of Method ------------------------------
    117133
     
    157173    jdbcTemplate.setPreparedStatementString(1, documentPathAndName);
    158174    jdbcTemplate.executePreparedStatement();
    159 
    160175    return(true);
    161176  } //-------------------------- End of Method ------------------------------
Note: See TracChangeset for help on using the changeset viewer.