Changeset 34905


Ignore:
Timestamp:
2021-02-19T17:56:36+13:00 (3 years ago)
Author:
davidb
Message:

Code tidy up; added in example SQL statement for next planned stage of work, which could retrieve files (e.g. photos) associated with content items

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tipple-bridge/trunk/src/src/main/java/sqlCli.java

    r34903 r34905  
    114114            //remember to put in the projectId parameter instead of hardcoding it
    115115
    116             /*
    117             if we get up to the point where we allow boundary setting, i.e  user specifies
    118             between x and y number of records
    119             could use an if statement to check
    120             if the paramter exists or not, if it does then run a statement with those x and y
    121             if not, then run a different statement without them
    122              */
    123 
     116
     117        /* Step 1: retrieve all the content items associated with the given projectId */
     118       
    124119            String sql = "SELECT name, id, typeId, created from td_ContentItem where projectId="+projectID;
    125 /*
    126             String sql = "select td_Document.id, td_Document.content " +
    127                     "from td_Document, td_ContentItem, td_ContentItem_Document " +
    128                     "where td_ContentItem.projectId=" + projectID + " and td_ContentItem.id =
    129                     td_ContentItem_Document.ContentItemId " +
    130                     "and td_ContentItem_Document.documentId = td_Document.id;";
    131 */
     120
     121        // consider usingLIMIT to get the returned results in controled batch size, rather than getting
     122        // all the results at once.
     123       
    132124            ResultSet myResult = stmt.executeQuery(sql);
    133125            ResultSetMetaData resultMetaData = myResult.getMetaData();
     
    136128            System.out.println(" Number of columns in table retrieved: " + dbColumn);
    137129
     130
     131        /* Step 2: Iterate through each content item, and retrieve the media files that content item has */
     132       
     133        /* The following is an example SELECT statement (for a hard-wired contentId = 333) that retrieves all the
     134           images (both the original name, and the hashed 'path' that maps to the media files on the file
     135           system (the contentItem itself at the time of writing was in projectID=4) */
     136
     137        /*
     138SELECT mFile.filename, mFile.path
     139
     140FROM td_ManagedFile AS mFile, td_ContentItem AS cItem, td_ContentItem_MediaItem AS cMediaItem, td_MediaItem AS mItem
     141
     142WHERE
     143
     144cItem.id = 333
     145
     146And cMediaItem.contentItemId = cItem.id
     147
     148and cMediaItem.mediaItemId = mItem.id
     149
     150And mItem.fileId = mFile.id
     151        */
     152
     153
     154       
    138155            //create gson object and have the file write the opening bracket for valid json
    139156            Gson myGSon = new Gson();
     
    169186                    }
    170187                }
    171                String dbRowAsJson = myGSon.toJson(dbRow);
    172 
    173                     //printing statements for checking output
    174                // System.out.println("As normal: " + dbRow);
    175                // System.out.println("====");
    176                 //System.out.println("As JSON: " + anObject);
    177 
     188        String dbRowAsJson = myGSon.toJson(dbRow);
     189       
     190       
    178191                //saving to json file
    179 
    180192                file.write(dbRowAsJson);
    181193
Note: See TracChangeset for help on using the changeset viewer.