Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    custom insert statement for binary data

    We recently converted all our db primary keys from integer to a binary uuid format : binary(16); to continue using smartgwt server framework, i figured i needed to use the 'valuesClause' method in my ds.xml file to generate a default value for the PK. The MySQL statement im using is "UNHEX(REPLACE(UUID(),'-',''))". However, i was not able to get this to work on a ds.xml that has a binary table column which uses smartgwt's file upload/download mechanism.

    I tried using "$values.contents" in the "valuesClause" but when the insert statement is generated, the string 'java.io.ByteArrayInputStream@1aaa0cd' produced instead of the actual file contents. how do i access the actual contents of the ByteArrayInputStream?

    The operationBinding in question =================
    <operationBinding operationType="add">
    <valuesClause><![CDATA[(id, contents, name, last_update, contents_filename, contents_date_created, contents_filesize) VALUES (UNHEX(REPLACE(UUID(),'-','')), $values.contents, $values.name, $currentDate, $values.contents_filename, $values.contents_date_created, $values.contents_filesize)]]></valuesClause>
    </operationBinding>

    The generated mySql code by SmartGwtEE =================
    INSERT INTO analysis_data_files (id, contents, name, last_update, contents_filename, contents_date_created, contents_filesize) VALUES (UNHEX(REPLACE(UUID(),'-','')), 'java.io.ByteArrayInputStream@1aaa0cd', 'A', '2012-01-03 15:45:32', 'csv_test_SM.csv', '2012-01-03 15:45:32', 1045)

    The Ds.XML file in its entirety =================
    Code:
     
    <DataSource ID="analysis_data_files" serverType="sql" dbName="lyosrw" tableName="analysis_data_files">
    	<fields>
    		<field name="id" type="text" canEdit="false" hidden="true" primaryKey="true" />
    		<field name="name" title="Description" canEdit="true" type="text" length="255" />
    		<field name="contents_filename" title="Filename" canEdit="true" type="text" />
    		<field name="last_update" type="datetime" canEdit="false" hidden="true" />
    		<field name="contents_date_created" title="Upload Date" canEdit="false" type="datetime" />
    		<field name="contents_filesize" title="File Size" canEdit="false" type="integer" canFilter="false" />
    		<field name="contents" title="Download" canEdit="false" type="binary" canFilter="false" />
    		<field name="csv_data" canEdit="false" type="any" hidden="true" canFilter="false" />
    	</fields>
    	<operationBindings>
    		<operationBinding operationType="fetch" outputs="id,name,contents_filename,last_update,contents_date_created,contents_filesize,contents">
    		</operationBinding>
    		<operationBinding operationType="fetch" operationId="contents_as_csv" outputs="id,csv_data">
    			<serverObject className="com.intelights.rtimms.server.analysis.dsgen.AnalysisFileDataSetProvider" methodName="fetchCsv" />
    		</operationBinding>
    		<operationBinding operationType="add">
    			<valuesClause><![CDATA[(id, contents, name, last_update, contents_filename, contents_date_created, contents_filesize) VALUES (UNHEX(REPLACE(UUID(),'-','')), $values.contents, $values.name, $currentDate,  $values.contents_filename, $values.contents_date_created, $values.contents_filesize)]]></valuesClause>
    		</operationBinding>
    		<operationBinding operationType="update">
    			<values fieldName="last_update" value="$currentDate" />
    			<valuesClause><![CDATA[oplock = oplock + 1, $defaultValuesClause]]></valuesClause>
    			<serverObject className="com.intelights.rtimms.server.analysis.dsgen.AnalysisFileDataSetProvider" methodName="update" />
    			<!-- hack added to update operation to remove extra layer of array so that the update returns correct data -->
    		</operationBinding>
    	</operationBindings>
    </DataSource>
    I'm using GWT2.4.0 and SmartGwtEE (Eval) 2.5

    Thanks!

    #2
    There's no need to replace the entire <valuesClause> and it certainly won't work for binary data (which doesn't generally get inlined in SQL).

    If you need to customize the SQL for any given field, use DataSourceField.customInsertExpression (and related properties for UPDATE, SELECT as needed - linked in the docs).

    To provide programmatically modified values, add a DMI (in Java) and manipulate the DSRequest object (eg setFieldValue).

    Comment

    Working...
    X