com.zentense.step2.model
Class ResultSetI18NModel

java.lang.Object
  extended by com.zentense.step2.model.ResultSetModel
      extended by com.zentense.step2.model.ResultSetI18NModel
Direct Known Subclasses:
ResultSetI18NFilterModel

public class ResultSetI18NModel
extends ResultSetModel

This class implements an internationalized resultset model. I18N texts are stored in a separated table while in the model, for each I18N text a reference to the i18n table is stored. This model extends ResultSetModel by managing this I18N columns and translating automatically the references in model by texts in current language. Current language is encoded using ISO codes.

The i18n table must have this form:

CREATE TABLE i18n (
   i18n_id INT NOT NULL,
   i18n_lang CHAR(2) NOT NULL,
   i18n_text TEXT,
   primary key (i18n_id, i18n_lang)
 );


Field Summary
protected  java.lang.String[] I18NCols
          I18N column names
protected  java.lang.String lang
          Language used to retrieve I18N texts
 
Fields inherited from class com.zentense.step2.model.ResultSetModel
idName, logLevel, prepared, preparedTableId, RSConcur, RSType, table
 
Constructor Summary
ResultSetI18NModel()
           
ResultSetI18NModel(java.lang.String tableName, java.lang.String idName)
          Constructor
 
Method Summary
 void delete(java.lang.Object id)
          Deletes a row, and also deletes any associated text from i18n pool.
 void deleteI18N(int id, java.lang.String lang)
           
 void deleteI18N(View v)
          Deletes all i18n texts (all languages) of any I18N column on current row from given view.
 View doLegacyQuery(java.lang.String sql)
          Executes a SQL query but returns a ResultSetView instead of an I18nView so that I18N columns are not translated.
 View doPrepared(java.lang.String name, java.lang.Object[] obj)
          Executes a prepared statement.
 View doQuery(java.lang.String sql)
          Executes a SQL query using JDBC.
 java.lang.String[] getI18NCols()
          Returns array of I18N columns
 java.lang.String getLang()
          Gets current language
 int getLastI18NId()
          Returns the last i18n_id from i18n table
 boolean insertI18N(int id, java.lang.String txt, java.lang.String lang)
          Inserts a text into I18N table
 int insertI18N(java.lang.String txt, java.lang.String lang)
          Inserts a text into I18N table.
 boolean isEmptyEntriesAllowed()
           
 boolean isI18NCol(java.lang.String col)
          Returns true if column is internationalized
 boolean modifyI18N(int id, java.lang.String txt, java.lang.String lang)
          If text with given id exists, text is updated on i18n table.
 void setEmptyEntriesAllowed(boolean emptyEntriesAllowed)
           
 void setI18NCols(java.lang.String[] cols)
          Sets I18N columns
 void setLang(java.lang.String lang)
          Sets language manually.
 boolean textExists(int id, java.lang.String lang)
          Exists a text in current language?
 boolean updateI18N(int id, java.lang.String txt, java.lang.String lang)
          Updates a internationalized text in i18n texts table
 
Methods inherited from class com.zentense.step2.model.ResultSetModel
addPrepared, clearPrepared, deleteAll, deleteBy, doUpdate, exists, find, find, findById, genSQL, genSQL, genSQL, getAll, getAllOrderedBy, getConnection, getCount, getMaxId, getPK, getPrepared, getTableName, insertMode, insertMode, loopMode, prepare, prepareStatements, rowMode, update, updateMode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

I18NCols

protected java.lang.String[] I18NCols
I18N column names


lang

protected java.lang.String lang
Language used to retrieve I18N texts

Constructor Detail

ResultSetI18NModel

public ResultSetI18NModel()

ResultSetI18NModel

public ResultSetI18NModel(java.lang.String tableName,
                          java.lang.String idName)
Constructor

Method Detail

isI18NCol

public boolean isI18NCol(java.lang.String col)
Returns true if column is internationalized


getI18NCols

public final java.lang.String[] getI18NCols()
Returns array of I18N columns


setI18NCols

public final void setI18NCols(java.lang.String[] cols)
Sets I18N columns


getLang

public final java.lang.String getLang()
Gets current language


setLang

public final void setLang(java.lang.String lang)
Sets language manually. Notice that invoking this method disables autoLang

Parameters:
New - language

doQuery

public final View doQuery(java.lang.String sql)
Description copied from class: ResultSetModel
Executes a SQL query using JDBC. The query must be a select or other query that generate results. Use doUpdate for inserts, updates, deletes and alter tables. If rowMode was invoked before this method, the returned view is open and ready to be accessed. Otherwise view is positiones before the first row and a call to next or first must be done in order to position the view at the first available row.

Overrides:
doQuery in class ResultSetModel
Parameters:
sql - SQL statement to execute
Returns:
An instance of ResultSetView containing the ResultSet

doLegacyQuery

public final View doLegacyQuery(java.lang.String sql)
Executes a SQL query but returns a ResultSetView instead of an I18nView so that I18N columns are not translated.


doPrepared

public final View doPrepared(java.lang.String name,
                             java.lang.Object[] obj)
Description copied from class: ResultSetModel
Executes a prepared statement.

Overrides:
doPrepared in class ResultSetModel
Parameters:
name - Name of prepared statement previosly crated with addPrepared
obj - Array of objects to be set in statement. Use ResultSetView.NULL for setting a null value into the statement.
Returns:
Resultset with results (if any)

getLastI18NId

public final int getLastI18NId()
                        throws java.lang.Exception
Returns the last i18n_id from i18n table

Parameters:
vm - A RequestRuntime instance
Returns:
The biggest identifier on i18n table
Throws:
java.lang.Exception

textExists

public final boolean textExists(int id,
                                java.lang.String lang)
                         throws java.lang.Exception
Exists a text in current language?

Parameters:
id - Identifier of internationalized text
Returns:
returns true if the text exists in current language
Throws:
java.lang.Exception - If something goes wrong

insertI18N

public final boolean insertI18N(int id,
                                java.lang.String txt,
                                java.lang.String lang)
Inserts a text into I18N table

Parameters:
id - Identifier for this text
txt - The text
lang - Language described as ISO code
Returns:
true if update was successful, false otherwise (@see isEmptyEntriesAllowed)

insertI18N

public final int insertI18N(java.lang.String txt,
                            java.lang.String lang)
                     throws java.lang.Exception
Inserts a text into I18N table. Assigns automatically a new id

Parameters:
txt - The text
lang - Language described as ISO code
Throws:
java.lang.Exception

updateI18N

public final boolean updateI18N(int id,
                                java.lang.String txt,
                                java.lang.String lang)
Updates a internationalized text in i18n texts table

Parameters:
id - Identifier for this text
txt - The new text
lang - Language described as ISO code
Returns:
true if update was successful, false if entry was deletes (@see isEmptyEntriesAllowed)

modifyI18N

public final boolean modifyI18N(int id,
                                java.lang.String txt,
                                java.lang.String lang)
                         throws java.lang.Exception
If text with given id exists, text is updated on i18n table. Otherwise text is inserted.

Parameters:
id - Identifier for this text
txt - The new text
lang - Language described as ISO code
Returns:
true if update was successful, false if entry was deletes (@see isEmptyEntriesAllowed)
Throws:
java.lang.Exception

delete

public void delete(java.lang.Object id)
Deletes a row, and also deletes any associated text from i18n pool.

Overrides:
delete in class ResultSetModel
Parameters:
id - Identifier value of the row to be deleted

deleteI18N

public final void deleteI18N(int id,
                             java.lang.String lang)

deleteI18N

public final void deleteI18N(View v)
Deletes all i18n texts (all languages) of any I18N column on current row from given view.


setEmptyEntriesAllowed

public void setEmptyEntriesAllowed(boolean emptyEntriesAllowed)

isEmptyEntriesAllowed

public boolean isEmptyEntriesAllowed()

 

© Zentense 2008