Coverage Report - fr.paris.lutece.plugins.adminsql.business.FieldDAO
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldDAO
0 %
1/238
0 %
0/86
3,688
 
 1  
 /*
 2  
  * Copyright (c) 2002-2017, Mairie de Paris
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met:
 8  
  *
 9  
  *  1. Redistributions of source code must retain the above copyright notice
 10  
  *     and the following disclaimer.
 11  
  *
 12  
  *  2. Redistributions in binary form must reproduce the above copyright notice
 13  
  *     and the following disclaimer in the documentation and/or other materials
 14  
  *     provided with the distribution.
 15  
  *
 16  
  *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
 17  
  *     contributors may be used to endorse or promote products derived from
 18  
  *     this software without specific prior written permission.
 19  
  *
 20  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 21  
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22  
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23  
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 24  
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 25  
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 26  
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 28  
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 29  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 30  
  * POSSIBILITY OF SUCH DAMAGE.
 31  
  *
 32  
  * License 1.0
 33  
  */
 34  
 package fr.paris.lutece.plugins.adminsql.business;
 35  
 
 36  
 import fr.paris.lutece.plugins.adminsql.util.AdminSqlUtil;
 37  
 import fr.paris.lutece.portal.service.database.PluginConnectionService;
 38  
 import fr.paris.lutece.portal.service.plugin.Plugin;
 39  
 import fr.paris.lutece.portal.service.plugin.PluginService;
 40  
 import fr.paris.lutece.util.ReferenceItem;
 41  
 import fr.paris.lutece.util.ReferenceList;
 42  
 import fr.paris.lutece.util.sql.DAOUtil;
 43  
 
 44  
 
 45  
 import java.util.ArrayList;
 46  
 import java.util.List;
 47  
 
 48  
 
 49  
 /**
 50  
  * Creates a new instance of DataDAO
 51  
  */
 52  1
 public class FieldDAO implements IFieldDAO
 53  
 {
 54  
     //Constantes
 55  
     private static final String NULL_VALUE = "NULL";
 56  
     private static final String NOT = "NOT ";
 57  
     private static final String CHANGE = "CHANGE";
 58  
     private static final String ADD = " ADD ";
 59  
     private static final String ADD_KEY = " ,ADD ";
 60  
     private static final String PRIMARY_KEY = "PRIMARY KEY";
 61  
     private static final String FOREIGN_KEY = "FOREIGN KEY";
 62  
     private static final String INDEX_KEY = "INDEX";
 63  
     private static final String UNIQUE_KEY = "UNIQUE";
 64  
     private static final String DROP = " DROP ";
 65  
     private static final String DROP_KEY = " ,DROP ";
 66  
     private static final String POOL_ADMINSQL = "adminsql";
 67  
 
 68  
     //RequĂȘtes
 69  
     private static final String SQL_QUERY_SHOW_TABLE_FIELDS_STRUCTURE = " SHOW COLUMNS FROM ";
 70  
     private static final String SQL_QUERY_SELECT_A_FIELD_ON_TABLE = "DESC ";
 71  
     private static final String SQL_QUERY_SELECTALL_FIELD_TYPE = " SELECT id_field_type, label_field_type FROM adminsql_field_type";
 72  
     private static final String SQL_QUERY_SELECTALL_FIELD_KEY = "SELECT id_field_key, label_field_key FROM adminsql_field_key";
 73  
     private static final String SQL_QUERY_SELECTALL_FIELD_NULL = "SELECT id_field_null, label_field_null FROM adminsql_field_null";
 74  
     private static final String SQL_QUERY_FIND_FIELD_TYPE_ID = " SELECT id_field_type FROM adminsql_field_type WHERE label_field_type= ?";
 75  
     private static final String SQL_QUERY_FIND_FIELD_TYPE_LABEL_BY_ID = " SELECT label_field_type FROM adminsql_field_type WHERE id_field_type= ?";
 76  
     private static final String SQL_QUERY_FIND_FIELD_NULL_ID = " SELECT id_field_null FROM adminsql_field_null WHERE label_field_null= ?";
 77  
     private static final String SQL_QUERY_FIND_FIELD_NULL_LABEL_BY_ID = " SELECT label_field_null FROM adminsql_field_null WHERE id_field_null= ?";
 78  
     private static final String SQL_QUERY_FIND_FIELD_KEY_ID = " SELECT id_field_key FROM adminsql_field_key WHERE label_field_key= ?";
 79  
     private static final String SQL_QUERY_FIND_FIELD_KEY_LABEL_BY_ID = " SELECT label_field_key FROM adminsql_field_key WHERE id_field_key= ?";
 80  
     private static final String SQL_QUERY_UPDATE = " ALTER TABLE ";
 81  
     private static final String SQL_QUERY_DELETE_FIELD = " ALTER TABLE ";
 82  
 
 83  
     /**
 84  
      * Load a field from the table
 85  
      * @param strTableName the name of the table
 86  
      * @param strFieldName the name of the field
 87  
      * @param plugin adminsql plugin
 88  
      * @param strPoolName the name of the pool
 89  
      * @return a field object
 90  
      */
 91  
     public Field load( String strPoolName, String strTableName, String strFieldName, Plugin plugin )
 92  
     {
 93  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_A_FIELD_ON_TABLE + strTableName + " " + strFieldName, plugin );
 94  0
         daoUtil.executeQuery(  );
 95  
 
 96  0
         Field field = new Field(  );
 97  0
         String[] tabString = { "", "" };
 98  
 
 99  0
         if ( daoUtil.next(  ) )
 100  
         {
 101  0
             field.setFieldName( daoUtil.getString( 1 ) );
 102  0
             field.setTypeValue( daoUtil.getString( 2 ) );
 103  
 
 104  0
             String strFieldType = field.getTypeValue(  );
 105  
 
 106  0
             if ( strFieldType.equals( "date" ) || strFieldType.equals( "datetime" ) || strFieldType.equals( "time" ) ||
 107  0
                     strFieldType.equals( "timestamp" ) || strFieldType.equals( "text" ) ||
 108  0
                     strFieldType.equals( "tinytext" ) || strFieldType.equals( "longtext" ) ||
 109  0
                     strFieldType.equals( "mediumtext" ) || strFieldType.equals( "blob" ) ||
 110  0
                     strFieldType.equals( "tinyblob" ) || strFieldType.equals( "longblob" ) ||
 111  0
                     strFieldType.equals( "mediumblob" ) )
 112  
             {
 113  0
                 field.setLabelTypeValue( strFieldType );
 114  0
                 field.setLengthTypeValue( "" );
 115  0
                 field.setIdTypeValue( findFieldTypeIdbyLabel( strFieldType, plugin, strPoolName ) );
 116  
             }
 117  
             else
 118  
             {
 119  0
                 tabString = AdminSqlUtil.getFieldDetails( field.getTypeValue(  ) );
 120  0
                 field.setLabelTypeValue( tabString[0] );
 121  0
                 field.setLengthTypeValue( tabString[1] );
 122  0
                 field.setIdTypeValue( findFieldTypeIdbyLabel( tabString[0], plugin, strPoolName ) );
 123  
             }
 124  
 
 125  0
             field.setLabelNullValue( daoUtil.getString( 3 ) );
 126  
 
 127  0
             int nFieldIdNull = findFieldNullIdbyLabel( daoUtil.getString( 3 ), plugin, strPoolName );
 128  0
             field.setIdNullValue( nFieldIdNull );
 129  
 
 130  0
             String strLabelKeyValue = daoUtil.getString( 4 );
 131  
 
 132  0
             if ( strLabelKeyValue.equals( "PRI" ) )
 133  
             {
 134  0
                 strLabelKeyValue = "PRIMAIRE";
 135  
             }
 136  
 
 137  0
             int nFieldIdKey = findFieldKeyIdbyLabel( strLabelKeyValue, plugin, strPoolName );
 138  0
             field.setIdKeyValue( nFieldIdKey );
 139  
 
 140  0
             if ( daoUtil.getString( 5 ) == null )
 141  
             {
 142  0
                 field.setDefaultValue( NULL_VALUE );
 143  
             }
 144  
             else
 145  
             {
 146  0
                 field.setDefaultValue( daoUtil.getString( 5 ) );
 147  
             }
 148  
         }
 149  
 
 150  0
         daoUtil.free(  );
 151  
 
 152  0
         return field;
 153  
     }
 154  
 
 155  
     /**
 156  
      * Store a field in the table
 157  
      * @param strTableName the name of the table
 158  
      * @param strFieldNameToModify the name of the field to modify
 159  
      * @param field Field object
 160  
      * @param plugin adminsql plugin
 161  
      * @param strPoolName the name of the pool
 162  
      * @param nIdOldFieldKey find the key of the field if exists
 163  
      */
 164  
     public void store( String strPoolName, String strTableName, Field field, String strFieldNameToModify,
 165  
         int nIdOldFieldKey, Plugin plugin )
 166  
     {
 167  0
         String strFieldName = field.getFieldName(  );
 168  0
         field.setLabelTypeValue( findFieldTypeLabelbyId( field.getIdTypeValue(  ), plugin, strPoolName ) );
 169  
 
 170  0
         String strFieldType = field.getLabelTypeValue(  );
 171  0
         String strFieldLabelType = "";
 172  0
         String strLengthTypeValue = field.getLengthTypeValue(  );
 173  
 
 174  0
         if ( strLengthTypeValue.equals( "" ) || ( strLengthTypeValue == null ) )
 175  
         {
 176  0
             strFieldLabelType = strFieldType;
 177  
         }
 178  0
         else if ( strFieldType.equals( "year" ) )
 179  
         {
 180  0
             strFieldLabelType = strFieldType + "(" + 4 + ")";
 181  
         }
 182  
         else
 183  
         {
 184  0
             strFieldLabelType = strFieldType + "(" + field.getLengthTypeValue(  ) + ")";
 185  
         }
 186  
 
 187  0
         field.setLabelNullValue( findFieldNullLabelbyId( field.getIdNullValue(), plugin, strPoolName ) );
 188  
 
 189  0
         String strLabelNullValue = field.getLabelNullValue(  );
 190  0
         String strFieldLabelNullValue = "";
 191  
 
 192  0
         if ( strLabelNullValue.equals( "YES" ) )
 193  
         {
 194  0
             strFieldLabelNullValue = NULL_VALUE;
 195  
         }
 196  
         else
 197  
         {
 198  0
             strFieldLabelNullValue = NOT + NULL_VALUE;
 199  
         }
 200  
 
 201  0
         int nIdKeyValue = field.getIdKeyValue(  );
 202  0
         String strKey = "";
 203  0
         String strNewPrimaryKey = "";
 204  
 
 205  0
         if ( ( nIdOldFieldKey == 1 ) && ( nIdKeyValue == 2 ) )
 206  
         {
 207  0
             strKey = ADD_KEY + PRIMARY_KEY;
 208  0
             strNewPrimaryKey = "(" + strFieldName + ")";
 209  
         }
 210  0
         else if ( ( nIdOldFieldKey == 2 ) && ( nIdKeyValue == 1 ) )
 211  
         {
 212  0
             strKey = DROP_KEY + PRIMARY_KEY;
 213  
         }
 214  
 
 215  0
         String strFieldLabelDefaultValue = field.getDefaultValue(  );
 216  
         String strDEFAULT;
 217  
         String strFieldLabelDefaultValueFinal;
 218  
 
 219  0
         if ( strFieldLabelDefaultValue.equals( "" ) )
 220  
         {
 221  0
             strDEFAULT = "";
 222  0
             strFieldLabelDefaultValueFinal = "";
 223  
         }
 224  
         else
 225  
         {
 226  0
             strDEFAULT = "DEFAULT";
 227  0
             strFieldLabelDefaultValueFinal = " '" + strFieldLabelDefaultValue + "'";
 228  
         }
 229  
 
 230  0
         String strAlterQuery = SQL_QUERY_UPDATE + " " + strTableName + " " + CHANGE + " " + strFieldNameToModify + " " +
 231  
             strFieldName + " " + strFieldLabelType + " " + " " + strFieldLabelNullValue + " " + strDEFAULT +
 232  
             strFieldLabelDefaultValueFinal + " " + strKey + strNewPrimaryKey;
 233  0
         DAOUtil daoUtil = new DAOUtil( strAlterQuery, plugin );
 234  0
         daoUtil.executeUpdate(  );
 235  0
         daoUtil.free(  );
 236  0
     }
 237  
 
 238  
     /**
 239  
      * Insert a field in the table
 240  
      * @param strPoolName the name of the pool
 241  
      * @param field Field object
 242  
      * @param strTableName the name of the table
 243  
      * @param plugin adminsql plugin
 244  
      */
 245  
     public void insert( String strPoolName, String strTableName, Field field, Plugin plugin )
 246  
     {
 247  0
         String strFieldName = field.getFieldName(  );
 248  0
         field.setLabelTypeValue( findFieldTypeLabelbyId( field.getIdTypeValue(  ), plugin, strPoolName ) );
 249  
 
 250  0
         String strFieldLabelType = "";
 251  0
         String strFieldType = field.getLabelTypeValue(  );
 252  0
         String strLengthTypeValue = field.getLengthTypeValue(  );
 253  
 
 254  0
         if ( strLengthTypeValue.equals( "" ) || ( strLengthTypeValue == null ) )
 255  
         {
 256  0
             strFieldLabelType = strFieldType;
 257  
         }
 258  0
         else if ( strFieldType.equals( "YEAR" ) )
 259  
         {
 260  0
             strFieldLabelType = strFieldType + "(" + 4 + ")";
 261  
         }
 262  
         else
 263  
         {
 264  0
             strFieldLabelType = strFieldType + "(" + field.getLengthTypeValue(  ) + ")";
 265  
         }
 266  
 
 267  0
         field.setLabelNullValue( findFieldNullLabelbyId( field.getIdNullValue(  ), plugin, strPoolName ) );
 268  
 
 269  0
         String strLabelNullValue = field.getLabelNullValue(  );
 270  0
         String strFieldLabelNullValue = "";
 271  
 
 272  0
         if ( strLabelNullValue.equals( "YES" ) )
 273  
         {
 274  0
             strFieldLabelNullValue = NULL_VALUE;
 275  
         }
 276  
         else
 277  
         {
 278  0
             strFieldLabelNullValue = NOT + NULL_VALUE;
 279  
         }
 280  
 
 281  0
         int nIdKeyValue = field.getIdKeyValue(  );
 282  0
         field.setLabelKeyValue( findFieldKeyLabelbyId( nIdKeyValue, plugin, strPoolName ) );
 283  
 
 284  0
         String strFieldLabelKeyValue = field.getLabelKeyValue(  );
 285  
         String strKey;
 286  
 
 287  0
         if ( nIdKeyValue == 1 )
 288  
         {
 289  0
             strKey = "";
 290  
         }
 291  
         else
 292  
         {
 293  0
             strKey = PRIMARY_KEY;
 294  
         }
 295  
 
 296  0
         String strFieldLabelDefaultValue = field.getDefaultValue(  );
 297  0
         String strDEFAULT = "";
 298  
 
 299  0
         if ( strFieldLabelDefaultValue.equals( "" ) )
 300  
         {
 301  0
             strDEFAULT = "";
 302  
         }
 303  
         else
 304  
         {
 305  0
             strDEFAULT = "DEFAULT";
 306  0
             strFieldLabelDefaultValue = " '" + strFieldLabelDefaultValue + "' ";
 307  
         }
 308  
 
 309  0
         int nAddFieldEndOfTable = field.getFieldEndOfTable(  );
 310  0
         int nAddFieldBeginningOfTable = field.getFieldBeginningOfTable(  );
 311  0
         int nAddFieldAfterAField = field.getFieldAfterAField(  );
 312  0
         int nPlaceOfField = field.getPlaceOfField(  );
 313  0
         String strFIRST = "";
 314  
 
 315  0
         if ( nPlaceOfField == 2 )
 316  
         {
 317  0
             strFIRST = "FIRST";
 318  
         }
 319  
         else
 320  
         {
 321  0
             strFIRST = "";
 322  
         }
 323  
 
 324  0
         String strAfterTheField = "";
 325  0
         String strAFTER = "";
 326  
 
 327  0
         if ( nPlaceOfField == 3 )
 328  
         {
 329  0
             strAFTER = "AFTER";
 330  0
             strAfterTheField = field.getAfterTheField(  );
 331  
         }
 332  
         else
 333  
         {
 334  0
             strAFTER = "";
 335  
         }
 336  
 
 337  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE + strTableName + " " + ADD + " " + strFieldName + " " +
 338  
                 strFieldLabelType + " " + strKey + " " + strFieldLabelNullValue + " " + strDEFAULT +
 339  
                 strFieldLabelDefaultValue + strFIRST + strAFTER + " " + strAfterTheField, plugin );
 340  0
         daoUtil.executeUpdate(  );
 341  0
         daoUtil.free(  );
 342  0
     }
 343  
 
 344  
     /**
 345  
      * Delete a field from the table
 346  
      * @param strTableName the name of the table
 347  
      * @param strFieldName the name of the field
 348  
      * @param plugin adminsql plugin
 349  
      */
 350  
     public void delete( String strTableName, String strFieldName, Plugin plugin )
 351  
     {
 352  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_FIELD + strTableName + DROP + strFieldName );
 353  0
         daoUtil.executeUpdate(  );
 354  0
         daoUtil.free(  );
 355  0
     }
 356  
 
 357  
     /**
 358  
      * Find the list of fields from a table
 359  
      * @param strPoolName the name of the pool
 360  
      * @param strTableName the name of the table
 361  
      * @param plugin Plugin adminsql
 362  
      * @return list of fields
 363  
      */
 364  
     public List<Field> selectFieldList( String strPoolName, String strTableName, Plugin plugin )
 365  
     {
 366  0
         List<Field> fieldList = new ArrayList<Field>(  );
 367  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SHOW_TABLE_FIELDS_STRUCTURE + strTableName, changePool( strPoolName ) );
 368  0
         daoUtil.executeQuery(  );
 369  
 
 370  0
         while ( daoUtil.next(  ) )
 371  
         {
 372  0
             Field field = new Field(  );
 373  0
             field.setFieldName( daoUtil.getString( 1 ) );
 374  0
             field.setTypeValue( daoUtil.getString( 2 ) );
 375  0
             field.setLabelNullValue( daoUtil.getString( 3 ) );
 376  
 
 377  0
             int nFieldIdNull = findFieldNullIdbyLabel( daoUtil.getString( 3 ), plugin, strPoolName );
 378  0
             field.setIdNullValue( nFieldIdNull );
 379  0
             field.setLabelKeyValue( daoUtil.getString( 4 ) );
 380  
 
 381  0
             int nFieldIdKey = findFieldKeyIdbyLabel( daoUtil.getString( 4 ), plugin, strPoolName );
 382  0
             field.setIdKeyValue( nFieldIdKey );
 383  
 
 384  0
             if ( daoUtil.getString( 5 ) == null )
 385  
             {
 386  0
                 field.setDefaultValue( NULL_VALUE );
 387  
             }
 388  
             else
 389  
             {
 390  0
                 field.setDefaultValue( daoUtil.getString( 5 ) );
 391  
             }
 392  
 
 393  0
             fieldList.add( field );
 394  0
         }
 395  
 
 396  0
         daoUtil.free(  );
 397  
 
 398  0
         return fieldList;
 399  
     }
 400  
 
 401  
     /**
 402  
      * lists the field list possiblilities to create or modify fields form
 403  
      * @return Field list
 404  
      * @param strPoolName the name of the pool
 405  
      * @param plugin plugin adminsql
 406  
      */
 407  
     public ReferenceList selectFieldTypeList( String strPoolName, Plugin plugin )
 408  
     {
 409  0
         ReferenceList fieldtypeList = new ReferenceList(  );
 410  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_FIELD_TYPE, getDefaultPool( plugin ) );
 411  
 
 412  0
         daoUtil.executeQuery(  );
 413  
 
 414  0
         while ( daoUtil.next(  ) )
 415  
         {
 416  0
             ReferenceItem item = new ReferenceItem(  );
 417  0
             item.setCode( daoUtil.getString( 1 ) );
 418  0
             item.setName( daoUtil.getString( 2 ) );
 419  0
             fieldtypeList.add( item );
 420  0
         }
 421  
 
 422  0
         daoUtil.free(  );
 423  0
         plugin = changePool( strPoolName );
 424  
 
 425  0
         return fieldtypeList;
 426  
     }
 427  
 
 428  
     /**
 429  
      * lists the field list possiblilities to create or modify fields form
 430  
      * @param strPoolName the name of the pool
 431  
      * @param plugin Plugin adminsql
 432  
      * @return the keys choice adminsql database
 433  
      */
 434  
     public ReferenceList selectFieldKeyList( String strPoolName, Plugin plugin )
 435  
     {
 436  0
         ReferenceList fieldkeyList = new ReferenceList(  );
 437  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_FIELD_KEY, getDefaultPool( plugin ) );
 438  
 
 439  0
         daoUtil.executeQuery(  );
 440  
 
 441  0
         while ( daoUtil.next(  ) )
 442  
         {
 443  0
             ReferenceItem item = new ReferenceItem(  );
 444  0
             item.setCode( daoUtil.getString( 1 ) );
 445  0
             item.setName( daoUtil.getString( 2 ) );
 446  0
             fieldkeyList.add( item );
 447  0
         }
 448  
 
 449  0
         daoUtil.free(  );
 450  0
         plugin = changePool( strPoolName );
 451  
 
 452  0
         return fieldkeyList;
 453  
     }
 454  
 
 455  
     /**
 456  
      * lists the field list possiblilities to create or modify fields form
 457  
      * @param strPoolName the name of the pool
 458  
      * @param plugin Plugin adminsql
 459  
      * @return the null value choice adminsql database
 460  
      */
 461  
     public ReferenceList selectFieldNullList( String strPoolName, Plugin plugin )
 462  
     {
 463  0
         ReferenceList fieldnullList = new ReferenceList(  );
 464  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_FIELD_NULL, getDefaultPool( plugin ) );
 465  
 
 466  0
         daoUtil.executeQuery(  );
 467  
 
 468  0
         while ( daoUtil.next(  ) )
 469  
         {
 470  0
             ReferenceItem item = new ReferenceItem(  );
 471  0
             item.setCode( daoUtil.getString( 1 ) );
 472  0
             item.setName( daoUtil.getString( 2 ) );
 473  0
             fieldnullList.add( item );
 474  0
         }
 475  
 
 476  0
         daoUtil.free(  );
 477  
 
 478  0
         return fieldnullList;
 479  
     }
 480  
 
 481  
     /**
 482  
      * Find the field id type by label type from adminsql database
 483  
      * @param strLabelType the name of the type that user choose
 484  
      * @param plugin Plugin adminsql
 485  
      * @param strPoolName the name of the pool
 486  
      * @return id type from label type
 487  
      */
 488  
     public int findFieldTypeIdbyLabel( String strLabelType, Plugin plugin, String strPoolName )
 489  
     {
 490  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_TYPE_ID, getDefaultPool( plugin ) );
 491  0
         daoUtil.setString( 1, strLabelType );
 492  0
         daoUtil.executeQuery(  );
 493  
 
 494  0
         int nIdFieldType = 0;
 495  
 
 496  0
         if ( daoUtil.next(  ) )
 497  
         {
 498  0
             nIdFieldType = daoUtil.getInt( 1 );
 499  
         }
 500  
 
 501  0
         daoUtil.free(  );
 502  0
         plugin = changePool( strPoolName );
 503  
 
 504  0
         return nIdFieldType;
 505  
     }
 506  
 
 507  
     /**
 508  
      * Find the field label type by id type from adminsql database
 509  
      * @param nId the id of type label
 510  
      * @param plugin Plugin adminsql
 511  
      * @param strPoolName name of the pool
 512  
      * @return the label of the type by id
 513  
      */
 514  
     public String findFieldTypeLabelbyId( int nId, Plugin plugin, String strPoolName )
 515  
     {
 516  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_TYPE_LABEL_BY_ID, getDefaultPool( plugin ) );
 517  0
         daoUtil.setInt( 1, nId );
 518  0
         daoUtil.executeQuery(  );
 519  
 
 520  0
         String strFieldTypeLabel = "";
 521  
 
 522  0
         if ( daoUtil.next(  ) )
 523  
         {
 524  0
             strFieldTypeLabel = daoUtil.getString( 1 );
 525  
         }
 526  
 
 527  0
         daoUtil.free(  );
 528  0
         plugin = changePool( strPoolName );
 529  
 
 530  0
         return strFieldTypeLabel;
 531  
     }
 532  
 
 533  
     /**
 534  
      * Find the field id null by label null from adminsql database
 535  
      * @param strLabelNull the label of the null value
 536  
      * @param plugin Plugin adminsql
 537  
      * @param strPoolName the name of the pool
 538  
      * @return id null from null type
 539  
      */
 540  
     public int findFieldNullIdbyLabel( String strLabelNull, Plugin plugin, String strPoolName )
 541  
     {
 542  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_NULL_ID, getDefaultPool( plugin ) );
 543  0
         daoUtil.setString( 1, strLabelNull );
 544  0
         daoUtil.executeQuery(  );
 545  
 
 546  0
         int nIdFieldNull = 0;
 547  
 
 548  0
         if ( daoUtil.next(  ) )
 549  
         {
 550  0
             nIdFieldNull = daoUtil.getInt( 1 );
 551  
         }
 552  
 
 553  0
         daoUtil.free(  );
 554  0
         plugin = changePool( strPoolName );
 555  
 
 556  0
         return nIdFieldNull;
 557  
     }
 558  
 
 559  
     /**
 560  
      * Find the field id null by label null from adminsql database
 561  
      * @param nId the id of the null value
 562  
      * @param plugin Plugin adminsql
 563  
      * @param strPoolName the name of the pool
 564  
      * @return the label of null value by id
 565  
      */
 566  
     public String findFieldNullLabelbyId( int nId, Plugin plugin, String strPoolName )
 567  
     {
 568  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_NULL_LABEL_BY_ID, getDefaultPool( plugin ) );
 569  0
         daoUtil.setInt( 1, nId );
 570  0
         daoUtil.executeQuery(  );
 571  
 
 572  0
         String strFieldNullLabel = "";
 573  
 
 574  0
         if ( daoUtil.next(  ) )
 575  
         {
 576  0
             strFieldNullLabel = daoUtil.getString( 1 );
 577  
         }
 578  
 
 579  0
         daoUtil.free(  );
 580  0
         plugin = changePool( strPoolName );
 581  
 
 582  0
         return strFieldNullLabel;
 583  
     }
 584  
 
 585  
     /**
 586  
      * Find the field id key by label key from adminsql database
 587  
      * @param strLabelKey the label key of the field
 588  
      * @param plugin Plugin adminsql
 589  
      * @param strPoolName the name of the pool
 590  
      * @return id key from label key
 591  
      */
 592  
     public int findFieldKeyIdbyLabel( String strLabelKey, Plugin plugin, String strPoolName )
 593  
     {
 594  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_KEY_ID, getDefaultPool( plugin ) );
 595  0
         daoUtil.setString( 1, strLabelKey );
 596  0
         daoUtil.executeQuery(  );
 597  
 
 598  0
         int nIdFieldKey = 0;
 599  
 
 600  0
         if ( daoUtil.next(  ) )
 601  
         {
 602  0
             nIdFieldKey = daoUtil.getInt( 1 );
 603  
         }
 604  
 
 605  0
         daoUtil.free(  );
 606  0
         plugin = changePool( strPoolName );
 607  
 
 608  0
         return nIdFieldKey;
 609  
     }
 610  
 
 611  
     /**
 612  
      * Find the field id key by label key from adminsql database
 613  
      * @param nId the id of the key
 614  
      * @param plugin Plugin adminsql
 615  
      * @param strPoolName the name of the pool
 616  
      * @return the label of key by id
 617  
      */
 618  
     public String findFieldKeyLabelbyId( int nId, Plugin plugin, String strPoolName )
 619  
     {
 620  0
         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_KEY_LABEL_BY_ID, getDefaultPool( plugin ) );
 621  0
         daoUtil.setInt( 1, nId );
 622  0
         daoUtil.executeQuery(  );
 623  
 
 624  0
         String strFieldKeyLabel = "";
 625  
 
 626  0
         if ( daoUtil.next(  ) )
 627  
         {
 628  0
             strFieldKeyLabel = daoUtil.getString( 1 );
 629  
         }
 630  
 
 631  0
         daoUtil.free(  );
 632  0
         plugin = changePool( strPoolName );
 633  
 
 634  0
         return strFieldKeyLabel;
 635  
     }
 636  
 
 637  
     private Plugin changePool( String strPoolName )
 638  
     {
 639  0
         Plugin plugin = PluginService.getPlugin( "adminsql" );
 640  
 
 641  0
         PluginConnectionService connectionService = new PluginConnectionService( strPoolName );
 642  0
         connectionService.setPool( strPoolName );
 643  0
         plugin.setConnectionService( connectionService );
 644  
 
 645  0
         return plugin;
 646  
     }
 647  
 
 648  
     private Plugin getDefaultPool( Plugin plugin )
 649  
     {
 650  0
         PluginConnectionService connectionService = new PluginConnectionService( plugin.getDbPoolName(  ) );
 651  0
         connectionService.setPool( "adminsql" );
 652  0
         plugin.setConnectionService( connectionService );
 653  
 
 654  0
         return plugin; //TODO in properties
 655  
     }
 656  
 }