Fork me on GitHub

CPD Results

The following document contains the results of PMD's CPD 5.3.5.

Duplications

File Line
fr/paris/lutece/plugins/adminsql/business/FieldDAO.java 464
fr/paris/lutece/plugins/adminsql/business/TableDAO.java 318
        DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_FIELD_NULL, getDefaultPool( plugin ) );

        daoUtil.executeQuery(  );

        while ( daoUtil.next(  ) )
        {
            ReferenceItem item = new ReferenceItem(  );
            item.setCode( daoUtil.getString( 1 ) );
            item.setName( daoUtil.getString( 2 ) );
            fieldnullList.add( item );
        }

        daoUtil.free(  );

        return fieldnullList;
    }

    /**
     * Find the field id type by label type from adminsql database
     * @param strLabelType the name of the type that user choose
     * @param plugin Plugin adminsql
     * @param strPoolName the name of the pool
     * @return id type from label type
     */
    public int findFieldTypeIdbyLabel( String strLabelType, Plugin plugin, String strPoolName )
    {
        DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_TYPE_ID, getDefaultPool( plugin ) );
        daoUtil.setString( 1, strLabelType );
        daoUtil.executeQuery(  );

        int nIdFieldType = 0;

        if ( daoUtil.next(  ) )
        {
            nIdFieldType = daoUtil.getInt( 1 );
        }

        daoUtil.free(  );
        plugin = changePool( strPoolName );

        return nIdFieldType;
    }

    /**
     * Find the field label type by id type from adminsql database
     * @param nId the id of type label
     * @param plugin Plugin adminsql
     * @param strPoolName name of the pool
     * @return the label of the type by id
     */
    public String findFieldTypeLabelbyId( int nId, Plugin plugin, String strPoolName )
    {
        DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_TYPE_LABEL_BY_ID, getDefaultPool( plugin ) );
        daoUtil.setInt( 1, nId );
        daoUtil.executeQuery(  );

        String strFieldTypeLabel = "";

        if ( daoUtil.next(  ) )
        {
            strFieldTypeLabel = daoUtil.getString( 1 );
        }

        daoUtil.free(  );
        plugin = changePool( strPoolName );

        return strFieldTypeLabel;
    }

    /**
     * Find the field id null by label null from adminsql database
     * @param strLabelNull the label of the null value
     * @param plugin Plugin adminsql
     * @param strPoolName the name of the pool
     * @return id null from null type
     */
    public int findFieldNullIdbyLabel( String strLabelNull, Plugin plugin, String strPoolName )
    {
        DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_NULL_ID, getDefaultPool( plugin ) );
        daoUtil.setString( 1, strLabelNull );
        daoUtil.executeQuery(  );

        int nIdFieldNull = 0;

        if ( daoUtil.next(  ) )
        {
            nIdFieldNull = daoUtil.getInt( 1 );
        }

        daoUtil.free(  );
        plugin = changePool( strPoolName );

        return nIdFieldNull;
    }

    /**
     * Find the field id null by label null from adminsql database
     * @param nId the id of the null value
     * @param plugin Plugin adminsql
     * @param strPoolName the name of the pool
     * @return the label of null value by id
     */
    public String findFieldNullLabelbyId( int nId, Plugin plugin, String strPoolName )
    {
        DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_NULL_LABEL_BY_ID, getDefaultPool( plugin ) );
        daoUtil.setInt( 1, nId );
        daoUtil.executeQuery(  );

        String strFieldNullLabel = "";

        if ( daoUtil.next(  ) )
        {
            strFieldNullLabel = daoUtil.getString( 1 );
        }

        daoUtil.free(  );
        plugin = changePool( strPoolName );

        return strFieldNullLabel;
    }

    /**
     * Find the field id key by label key from adminsql database
     * @param strLabelKey the label key of the field
     * @param plugin Plugin adminsql
     * @param strPoolName the name of the pool
     * @return id key from label key
     */
    public int findFieldKeyIdbyLabel( String strLabelKey, Plugin plugin, String strPoolName )
    {
        DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_KEY_ID, getDefaultPool( plugin ) );
        daoUtil.setString( 1, strLabelKey );
        daoUtil.executeQuery(  );

        int nIdFieldKey = 0;

        if ( daoUtil.next(  ) )
        {
            nIdFieldKey = daoUtil.getInt( 1 );
        }

        daoUtil.free(  );
        plugin = changePool( strPoolName );

        return nIdFieldKey;
    }

    /**
     * Find the field id key by label key from adminsql database
     * @param nId the id of the key
     * @param plugin Plugin adminsql
     * @param strPoolName the name of the pool
     * @return the label of key by id
     */
    public String findFieldKeyLabelbyId( int nId, Plugin plugin, String strPoolName )
    {
        DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_FIELD_KEY_LABEL_BY_ID, getDefaultPool( plugin ) );
        daoUtil.setInt( 1, nId );
        daoUtil.executeQuery(  );

        String strFieldKeyLabel = "";

        if ( daoUtil.next(  ) )
        {
            strFieldKeyLabel = daoUtil.getString( 1 );
        }

        daoUtil.free(  );
        plugin = changePool( strPoolName );

        return strFieldKeyLabel;
    }

    private Plugin changePool( String strPoolName )
    {
        Plugin plugin = PluginService.getPlugin( "adminsql" );

        PluginConnectionService connectionService = new PluginConnectionService( strPoolName );
        connectionService.setPool( strPoolName );
        plugin.setConnectionService( connectionService );

        return plugin;
    }

    private Plugin getDefaultPool( Plugin plugin )
    {
        PluginConnectionService connectionService = new PluginConnectionService( plugin.getDbPoolName(  ) );
        connectionService.setPool( "adminsql" );
        plugin.setConnectionService( connectionService );

        return plugin; //TODO in properties
    }
}
File Line
fr/paris/lutece/plugins/adminsql/business/DataDAO.java 261
fr/paris/lutece/plugins/adminsql/business/StructureTableDAO.java 114
            statement = connection.prepareStatement( strRequest );

            ResultSet resultSet = statement.executeQuery(  );
            ResultSetMetaData rsmd = resultSet.getMetaData(  );

            ArrayList listRow = new ArrayList(  );

            while ( resultSet.next(  ) )
            {
                String strValue = null;
                ArrayList listLine = new ArrayList(  );

                for ( int i = 1; i <= rsmd.getColumnCount(  ); i++ )
                {
                    if ( resultSet.getObject( rsmd.getColumnName( i ) ) != null )
                    {
                        strValue = resultSet.getObject( rsmd.getColumnName( i ) ).toString(  );
                    }
                    else
                    {
                        strValue = " ";
                    }

                    listLine.add( strValue );
                }

                listRow.add( listLine );
            }

            statement.close(  );
            statement = null;

            return listRow;
        }
        finally
        {
            try
            {
                if ( statement != null )
                {
                    statement.close(  );
                }
            }
            catch ( SQLException e )
            {
                throw new AppException( "SQL Error executing command : " + e.toString(  ) );
            }

            connectionService.freeConnection( connection );
        }
    }

    /**
     * Result of user request
     * @param strUserRequest user request
     * @param connectionService PluginConnectionService object
     * @return  result of user request
     */
    public List<List<String>> findResultOfUserRequest( String strUserRequest, PluginConnectionService connectionService )
File Line
fr/paris/lutece/plugins/adminsql/web/AdminSqlJspBean.java 827
fr/paris/lutece/plugins/adminsql/web/AdminSqlJspBean.java 939
            return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_TABLE_NAME, AdminMessage.TYPE_STOP );
        }

        //Combos
        int nIdFieldType = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_TYPE ) );
        int nIdFieldNull = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_NULL ) );
        int nIdFieldKey = Integer.parseInt( request.getParameter( PARAMETER_ID_FIELD_KEY ) );

        if ( ( nIdFieldType == 3 ) || ( nIdFieldType == 4 ) || ( nIdFieldType == 12 ) || ( nIdFieldType == 13 ) ||
                ( nIdFieldType == 14 ) || ( nIdFieldType == 15 ) || ( nIdFieldType == 17 ) || ( nIdFieldType == 18 ) ||
                ( nIdFieldType == 19 ) || ( nIdFieldType == 20 ) || ( nIdFieldType == 21 ) || ( nIdFieldType == 22 ) ||
                ( nIdFieldType == 23 ) )
        {
            strFieldLengthType = "";
        }
        else if ( ( strFieldLengthType == null ) || strFieldLengthType.equals( "" ) )
        {
            return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_FIELD_TYPE_LENGTH, AdminMessage.TYPE_STOP );
        }
File Line
fr/paris/lutece/plugins/adminsql/business/FieldDAO.java 267
fr/paris/lutece/plugins/adminsql/business/TableDAO.java 130
        field.setLabelNullValue( findFieldNullLabelbyId( field.getIdNullValue(  ), plugin, strPoolName ) );

        String strLabelNullValue = field.getLabelNullValue(  );
        String strFieldLabelNullValue = "";

        if ( strLabelNullValue.equals( "YES" ) )
        {
            strFieldLabelNullValue = NULL_VALUE;
        }
        else
        {
            strFieldLabelNullValue = NOT + NULL_VALUE;
        }

        int nIdKeyValue = field.getIdKeyValue(  );
        field.setLabelKeyValue( findFieldKeyLabelbyId( nIdKeyValue, plugin, strPoolName ) );

        String strFieldLabelKeyValue = field.getLabelKeyValue(  );
        String strKey;

        if ( nIdKeyValue == 1 )
        {
            strKey = "";
        }
        else
        {
            strKey = PRIMARY_KEY;
        }

        String strFieldLabelDefaultValue = field.getDefaultValue(  );
        String strDEFAULT = "";

        if ( strFieldLabelDefaultValue.equals( "" ) )
        {
            strDEFAULT = "";
        }
        else
        {
            strDEFAULT = "DEFAULT";
            strFieldLabelDefaultValue = " '" + strFieldLabelDefaultValue + "' ";
        }
File Line
fr/paris/lutece/plugins/adminsql/web/AdminSqlJspBean.java 311
fr/paris/lutece/plugins/adminsql/web/AdminSqlJspBean.java 333
                    listFieldsNames = DataHome.findFieldsNames( strUserRequest,
                            AdminSqlConnectionService.getConnectionService( strPoolName ), strPoolName );
                }
                catch ( AppException e )
                {
                    String strErrorMessage = ( e.getCause(  ) != null ) ? e.getCause(  ).getMessage(  ) : "";
                    Map<String, Object> model = new HashMap<String, Object>(  );
                    model.put( MARK_POOL_NAME, strPoolName );
                    model.put( MARK_APPEXCEPTION_ERROR, strErrorMessage );
                    model.put( MARK_USER_REQUEST, strUserRequest );

                    HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_USER_REQUEST_ERROR, getLocale(  ),
                            model );

                    return getAdminPage( template.getHtml(  ) );
                }
            }