Blog do projektu Open Source JavaHotel

piątek, 22 maja 2015

Pro*C to DB2 Embedded SQL migration, BLOB, large object

Pro*C BLOB
Uploading and downloading files from and to BLOB column is a painstaking process in Oracle Pro*C. More details: download, read BLOB and upload, write BLOB.
Pro*C code example:
create table blobtable (id number(12), filename varchar2(100), fileb blob);
Code sample for reading and writing BLOB column is here.
One has to recognize whether file can be swallowed in a single mouthful (uff !) and issue EXEC SQL LOB WRITE ONE. If not then a complicated logic should be developed to recognize the first chunk (EXEC SQL LOB WRITE FIRST), intermediate chunk(s) (EXEC SQL LOB WRITE NEXT) and the closing chunk (EXEC SQL LOB WRITE LAST). The same for reading a BLOB column. DBMB_LOB utility is only a partial solution because it can read/write files from and to Oracle server.
Embedded SQL (DB2) BLOB
In DB2 (Embedded SQL) it is much simpler. Just use BLOB_FILE host variable for BLOB reading and writing. The whole code looks very simple now. Works also while executed at the client or server side.
int writeBlob(char *filename) { 
   struct sqlca sqlca;
   int error = 0;
  EXEC SQL BEGIN DECLARE SECTION;
    int id;
    char pfilename[500];
    SQL TYPE IS BLOB_FILE FILEB;
  EXEC SQL END DECLARE SECTION;
      
   strcpy(pfilename,filename);

   EXEC SQL select id into :id FROM blobtable WHERE id = 1  ;
   EVALRESULT("Select blob record");
   if (error) return 0;
   
   if (sqlca.sqlcode == 100) {
     // not found
     EXEC SQL INSERT INTO blobtable VALUES(1,:pfilename,NULL);
     EVALRESULT("Insert record to blobtable");
     if (error) return 0;
   }     
   strcpy (FILEB.name, pfilename);
   FILEB.name_length = strlen(pfilename);
   FILEB.file_options = SQL_FILE_READ;
   EXEC SQL UPDATE blobtable SET filename=:pfilename,fileb=:FILEB WHERE ID=1;
   EVALRESULT("Insert blob value");
   if (error) return 0;
   
   return 1;
 
 
}

int readBlob(char *filename) { 
   struct sqlca sqlca;
   int error = 0;
  EXEC SQL BEGIN DECLARE SECTION;
    SQL TYPE IS BLOB_FILE FILEB;
  EXEC SQL END DECLARE SECTION;
      
   
   strcpy (FILEB.name, filename);
   FILEB.name_length = strlen(filename);
   FILEB.file_options = SQL_FILE_OVERWRITE;

   EXEC SQL select fileb into :FILEB FROM blobtable WHERE id = 1  ;
   EVALRESULT("Read blob record");
   if (error) return 0;
   
   printf("sql code=%u\n",sqlca.sqlcode);
   if (sqlca.sqlcode == 100) {
     // not found
     printf("No record in blobtable table\n");
     return 0;
   }     
   
   return 1;
 
  
}

niedziela, 17 maja 2015

New version of MVP Jython framework

Introduction
New version of MVP Jython framework was deployed. New features had been added and several bugs fixed.
Sample application (Google App Engine)
Source code
Change title(tooltip)
More detailed description 
Change column header
More detailed description
Sample application Different lists -> Change column header
After clicking "Change column header" button column header will be modified accordingly.
Changes saving
User can modify some parameters related to list. For instance: number of rows.

So far the changes were active only for a current window. After refreshing standard values were restored. From now on the changes will be persisted in browser cookies and reused.
Modify the list layout
Additional option is implemented : "Change column settings"


After selecting the option it is possible to modify column headers and visibility.

Changes are persistent, new layout is stored in browser cookies. It is possible also to restore standard layout by clicking "Restore default" button.
Important: changing column order is planned in the future.
Setting/unsetting all column
Sample application Different lists -> List check
In "list edit" mode (more details) one can make "bool" column editable for check/uncheck. Option has been added to check/uncheck all list after clicking the column header. Whole list is modified, not only a single row.
Important: Side effect is involved because clicking the header causes also list sorting by boolean values. Will be improved in the future.
Small fixes
  • Footer numerical value is formatted like number in the column (decimal point, spaces between thousands). 
  • Jython 2.7 (final release) is used. Unfortunately, nasty problem was detected while converting date time value to Java Timestamp (source code modifier). Also this version does not work in Google App Engine (java.io package) so the old Jython 2.7-b3 is deployed for this version.
Future
  • List: download as csv, PDF (for printing) and send as an attachment in mail.

piątek, 15 maja 2015

New version of JSPWiki In The Cloud

I deployed new version of Google App Engine JSPWiki port. Caching mechanism was added (by means of Google App Engine MemCache). Performance improves a little bit but it is not a significant change.
Sources are available on GitHub.
I also moved demo version to http://myjspwiki.appspot.com/ because previous location is infested by spam.