Package org.apache.turbine.util

Examples of org.apache.turbine.util.StringStackBuffer


            TurbineDB.getDatabaseMap( selectCriteria.getDbName() );
        Connection connection = dbCon.getConnection();

        // Set up a list of required tables.  StringStackBuffer.add()
        // only adds element if it is unique.
        StringStackBuffer tables = new StringStackBuffer();
        Enumeration e = selectCriteria.keys();
        while(e.hasMoreElements())
        {
            tables.add(selectCriteria.getTableName( (String)e.nextElement() ));
        }

        for (int i=0; i<tables.size(); i++)
        {
            KeyDef kd = new KeyDef();
            StringStackBuffer whereClause = new StringStackBuffer();
            DatabaseMap tempDbMap = dbMap;

            ColumnMap[] columnMaps =
                tempDbMap.getTable( tables.get(i) ).getColumns();
            for (int j=0; j<columnMaps.length; j++)
            {
                ColumnMap colMap = columnMaps[j];
                if ( colMap.isPrimaryKey() )
                {
                    kd.addAttrib( colMap.getColumnName() );
                }
                String key = new StringBuffer(colMap.getTableName())
                    .append('.').append(colMap.getColumnName()).toString();
                if ( selectCriteria.containsKey(key) )
                {
                    if ( selectCriteria.getComparison( key ).equals(Criteria.CUSTOM) )
                    {
                        whereClause.add( selectCriteria.getString( key ));
                    }
                    else
                    {
                        whereClause.add( SqlExpression.build( colMap.getColumnName(),
                            selectCriteria.getValue( key ),
                            selectCriteria.getComparison( key ),
                            selectCriteria.isIgnoreCase(),
                            db ));
                    }
                }
            }
            TableDataSet tds = null;
            try
            {
                // Get affected records.
                tds = new TableDataSet(connection, tables.get(i), kd );
                String sqlSnippet = whereClause.toString(" AND ");
                TurbineLogging.getLogger(TurbineConstants.SQL_LOG_FACILITY)
                    .debug("BasePeer.doUpdate: whereClause=" + sqlSnippet);
                tds.where(sqlSnippet);
                tds.fetchRecords();
View Full Code Here


        DB db = TurbineDB.getDB( criteria.getDbName() );
        DatabaseMap dbMap = TurbineDB.getDatabaseMap( criteria.getDbName() );
       
        Query query = new Query();
       
        StringStackBuffer selectModifiers = query.getSelectModifiers();
        StringStackBuffer selectClause = query.getSelectClause();
        StringStackBuffer fromClause = query.getFromClause();
        StringStackBuffer whereClause = query.getWhereClause();
        StringStackBuffer orderByClause = query.getOrderByClause();

        StringStackBuffer orderBy = criteria.getOrderByColumns();
        boolean ignoreCase = criteria.isIgnoreCase();
        StringStackBuffer select = criteria.getSelectColumns();
        Hashtable aliases = criteria.getAsColumns();
        StringStackBuffer modifiers = criteria.getSelectModifiers();

        for (int i=0; i<modifiers.size(); i++)
        {
            selectModifiers.add( modifiers.get(i) );
        }

        for (int i=0; i<modifiers.size(); i++)
        {
            selectModifiers.add( modifiers.get(i) );
        }

        for (int i=0; i<select.size(); i++)
        {
            String columnName = select.get(i);
View Full Code Here

                if ( comparison.equals(Criteria.IN) || comparison.equals(Criteria.NOT_IN) )
                {
                    sb.append (field)
                      .append (comparison);

                    StringStackBuffer inClause = new StringStackBuffer();

                    if (value instanceof Vector)
                    {
                        value = ((Vector)value).toArray (new Object[0]);
                    }

                    for (int i = 0; i < Array.getLength(value); i++)
                    {
                        Object item = Array.get(value, i);

                        inClause.add(SqlExpression.processInValue(item, ignoreCase, db));
                    }

                    StringBuffer inString = new StringBuffer();
                    inString.append('(').append(inClause.toString(",")).append(')');

                    sb.append (inString.toString());
                }
                else
                {
View Full Code Here

            return h;
        }

        public String[] getAllTables()
        {
            StringStackBuffer tables = new StringStackBuffer();
            addCriterionTable(this, tables);
            return tables.toStringArray();
        }
View Full Code Here

        {
            return true;
        }

        DatabaseMap map = TurbineDB.getDatabaseMap(databaseMapName);
        StringStackBuffer tables = new StringStackBuffer();
        for (Enumeration e = super.elements(); e.hasMoreElements(); )
        {
            Criterion co = (Criterion)e.nextElement();
            String tableName = co.getTable();
            if (!tables.contains(tableName))
            {
                if (map.getTable(tableName).containsObjectColumn())
                  return true;
                tables.add(tableName);
            }
        }
        return false;
    }
View Full Code Here

        {
            whereClause.append(columnName);
        }

        whereClause.append(comparison);
        StringStackBuffer inClause = new StringStackBuffer();
        if (criteria instanceof List)
        {
            Iterator iter = ((List)criteria).iterator();
            while (iter.hasNext())
            {
                Object value = iter.next();

                // The method processInValue() quotes the string
                // and/or wraps it in UPPER().
                inClause.add(processInValue(value, ignoreCase, db));
            }
        }
        else
        {
            // Assume array.
            for (int i = 0; i < Array.getLength(criteria); i++)
            {
                Object value = Array.get(criteria, i);

                // The method processInValue() quotes the string
                // and/or wraps it in UPPER().
                inClause.add(processInValue(value, ignoreCase, db));
            }
        }
        whereClause.append('(')
                   .append(inClause.toString(","))
                   .append(')');
    }
View Full Code Here

        Connection connection = dbCon.getConnection();

        // Set up a list of required tables and add extra entries to
        // criteria if directed to delete all related records.
        // StringStackBuffer.add() only adds element if it is unique.
        StringStackBuffer tables = new StringStackBuffer();
        Enumeration e = criteria.keys();
        while(e.hasMoreElements())
        {
            String key = (String)e.nextElement();
            Criteria.Criterion c = criteria.getCriterion(key);
            String[] tableNames = c.getAllTables();
            for (int i=0; i<tableNames.length; i++)
            {
                String tableName2 = criteria.getTableForAlias(tableNames[i]);
                if ( tableName2 != null )
                {
                    tables.add(
                        new StringBuffer(tableNames[i].length() +
                                         tableName2.length() + 1)
                        .append(tableName2).append(' ').append(tableNames[i])
                        .toString() );
                }
                else
                {
                    tables.add(tableNames[i]);
                }
            }

            if ( criteria.isCascade() )
            {
                // This steps thru all the columns in the database.
                TableMap[] tableMaps = dbMap.getTables();
                for (int i=0; i<tableMaps.length; i++)
                {
                    ColumnMap[] columnMaps = tableMaps[i].getColumns();
                    for (int j=0; j<columnMaps.length; j++)
                    {
                        // Only delete rows where the foreign key is
                        // also a primary key.  Other rows need
                        // updateing, but that is not implemented.
                        if ( columnMaps[j].isForeignKey()
                            && columnMaps[j].isPrimaryKey()
                            && key.equals(columnMaps[j].getRelatedName()) )
                        {
                            tables.add(tableMaps[i].getName());
                            criteria.add(columnMaps[j].getFullyQualifiedName(),
                                         criteria.getValue(key));
                        }
                    }
                }
            }
        }

        for (int i=0; i<tables.size(); i++)
        {
            KeyDef kd = new KeyDef();
            StringStackBuffer whereClause = new StringStackBuffer();

            ColumnMap[] columnMaps =
                dbMap.getTable( tables.get(i) ).getColumns();
            for (int j=0; j<columnMaps.length; j++)
            {
                ColumnMap colMap = columnMaps[j];
                if ( colMap.isPrimaryKey() )
                {
                    kd.addAttrib( colMap.getColumnName() );
                }
                String key = new StringBuffer(colMap.getTableName())
                    .append('.').append(colMap.getColumnName()).toString();
                if ( criteria.containsKey(key) )
                {
                    if ( criteria.getComparison(key).equals(Criteria.CUSTOM) )
                    {
                        whereClause.add( criteria.getString(key) );
                    }
                    else
                    {
                        whereClause.add( SqlExpression.build( colMap.getColumnName(),
                            criteria.getValue(key),
                            criteria.getComparison(key),
                            criteria.isIgnoreCase(),
                            db));
                    }
                }
            }

            // Execute the statement.
            TableDataSet tds = null;
            try
            {
                tds = new TableDataSet(connection, tables.get(i), kd);
                String sqlSnippet = whereClause.toString(" AND ");
                TurbineLogging.getLogger(TurbineConstants.SQL_LOG_FACILITY)
                    .debug("BasePeer.doDelete: whereClause=" + sqlSnippet);
                tds.where(sqlSnippet);
                tds.fetchRecords();
                if ( tds.size() > 1 && criteria.isSingleRecord() )
View Full Code Here

    {
        Query query = new Query();
        DB db = TurbineDB.getDB( criteria.getDbName() );
        DatabaseMap dbMap = TurbineDB.getDatabaseMap( criteria.getDbName() );

        StringStackBuffer selectModifiers = query.getSelectModifiers();
        StringStackBuffer selectClause = query.getSelectClause();
        StringStackBuffer fromClause = query.getFromClause();
        StringStackBuffer whereClause = query.getWhereClause();
        StringStackBuffer orderByClause = query.getOrderByClause();

        StringStackBuffer orderBy = criteria.getOrderByColumns();
        boolean ignoreCase = criteria.isIgnoreCase();
        StringStackBuffer select = criteria.getSelectColumns();
        Hashtable aliases = criteria.getAsColumns();
        StringStackBuffer modifiers = criteria.getSelectModifiers();

        for (int i=0; i<modifiers.size(); i++)
        {
            selectModifiers.add( modifiers.get(i) );
        }

        for (int i=0; i<select.size(); i++)
        {
            String columnName = select.get(i);
View Full Code Here

            TurbineDB.getDatabaseMap( selectCriteria.getDbName() );
        Connection connection = dbCon.getConnection();

        // Set up a list of required tables.  StringStackBuffer.add()
        // only adds element if it is unique.
        StringStackBuffer tables = new StringStackBuffer();
        Enumeration e = selectCriteria.keys();
        while(e.hasMoreElements())
        {
            tables.add(selectCriteria.getTableName( (String)e.nextElement() ));
        }

        for (int i=0; i<tables.size(); i++)
        {
            KeyDef kd = new KeyDef();
            StringStackBuffer whereClause = new StringStackBuffer();
            DatabaseMap tempDbMap = dbMap;

            ColumnMap[] columnMaps =
                tempDbMap.getTable( tables.get(i) ).getColumns();
            for (int j=0; j<columnMaps.length; j++)
            {
                ColumnMap colMap = columnMaps[j];
                if ( colMap.isPrimaryKey() )
                {
                    kd.addAttrib( colMap.getColumnName() );
                }
                String key = new StringBuffer(colMap.getTableName())
                    .append('.').append(colMap.getColumnName()).toString();
                if ( selectCriteria.containsKey(key) )
                {
                    if ( selectCriteria.getComparison( key ).equals(Criteria.CUSTOM) )
                    {
                        whereClause.add( selectCriteria.getString( key ));
                    }
                    else
                    {
                        whereClause.add( SqlExpression.build( colMap.getColumnName(),
                            selectCriteria.getValue( key ),
                            selectCriteria.getComparison( key ),
                            selectCriteria.isIgnoreCase(),
                            db ));
                    }
                }
            }
            TableDataSet tds = null;
            try
            {
                // Get affected records.
                tds = new TableDataSet(connection, tables.get(i), kd );
                String sqlSnippet = whereClause.toString(" AND ");
                TurbineLogging.getLogger(TurbineConstants.SQL_LOG_FACILITY)
                    .debug("BasePeer.doUpdate: whereClause=" + sqlSnippet);
                tds.where(sqlSnippet);
                tds.fetchRecords();
View Full Code Here

        DB db = TurbineDB.getDB( criteria.getDbName() );
        DatabaseMap dbMap = TurbineDB.getDatabaseMap( criteria.getDbName() );

        Query query = new Query();

        StringStackBuffer selectModifiers = query.getSelectModifiers();
        StringStackBuffer selectClause = query.getSelectClause();
        StringStackBuffer fromClause = query.getFromClause();
        StringStackBuffer whereClause = query.getWhereClause();
        StringStackBuffer orderByClause = query.getOrderByClause();

        StringStackBuffer orderBy = criteria.getOrderByColumns();
        boolean ignoreCase = criteria.isIgnoreCase();
        StringStackBuffer select = criteria.getSelectColumns();
        Hashtable aliases = criteria.getAsColumns();
        StringStackBuffer modifiers = criteria.getSelectModifiers();

        for (int i=0; i<modifiers.size(); i++)
        {
            selectModifiers.add( modifiers.get(i) );
        }

        for (int i=0; i<modifiers.size(); i++)
        {
            selectModifiers.add( modifiers.get(i) );
        }

        for (int i=0; i<select.size(); i++)
        {
            String columnName = select.get(i);
View Full Code Here

TOP

Related Classes of org.apache.turbine.util.StringStackBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.