Package org.apache.turbine.util.db.map

Examples of org.apache.turbine.util.db.map.ColumnMap


            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));
                    }
View Full Code Here


        DatabaseMap dbMap = TurbineDB.getDatabaseMap( criteria.getDbName() );
        TableMap tableMap = dbMap.getTable(tableName);
        Object keyInfo = tableMap.getPrimaryKeyMethodInfo();
        IdGenerator keyGen = tableMap.getIdGenerator();

        ColumnMap pk = getPrimaryKey(criteria);
        // only get a new key value if you need to
        // the reason is that a primary key might be defined
        // but you are still going to set its value. for example:
        // a join table where both keys are primary and you are
        // setting both columns with your own values
        boolean info = false;
       
        if (!criteria.containsKey(pk.getFullyQualifiedName()))
        {
            // If the keyMethod is SEQUENCE or IDBROKERTABLE, get the id
            // before the insert.
           
            if (keyGen.isPriorToInsert())
            {
                if ( pk.getType() instanceof Number )
                {
                    id = new NumberKey( tableMap.getIdGenerator()
                        .getIdAsBigDecimal(dbCon.getConnection(), keyInfo) );
                }
                else
                {
                    id = new StringKey( tableMap.getIdGenerator()
                        .getIdAsString(dbCon.getConnection(), keyInfo) );
                }
                criteria.add( pk.getFullyQualifiedName(), id );
            }
        }

        // Set up Village for the insert.
        TableDataSet tds = null;
        try
        {
            tds = new TableDataSet(dbCon.getConnection(), tableName );
            Record rec = tds.addRecord();
            insertOrUpdateRecord(rec, tableName, criteria);
        }
        finally
        {
            if (tds != null) tds.close();
        }

        // If the primary key column is auto-incremented, get the id
        // now.
        if ((keyGen != null) && (keyGen.isPostInsert()))
        {
            if ( pk.getType() instanceof Number )
            {
                id = new NumberKey( tableMap.getIdGenerator()
                    .getIdAsBigDecimal(dbCon.getConnection(), keyInfo) );
            }
            else
View Full Code Here

        ColumnMap[] columnMaps = dbMap.getTable( tableName ).getColumns();
        boolean shouldSave = false;
        for (int j=0; j<columnMaps.length; j++)
        {
            ColumnMap colMap = columnMaps[j];
            String key = new StringBuffer(colMap.getTableName())
                .append('.').append(colMap.getColumnName()).toString();
            if ( criteria.containsKey(key) )
            {
                // A village Record.setValue( String, Object ) would
                // be nice here.
                Object obj = criteria.getValue(key);
                if ( obj instanceof SimpleKey )
                {
                    obj = ((SimpleKey)obj).getValue();
                }
                if (obj == null)
                {
                    rec.setValueNull(colMap.getColumnName());
                }   
                else if ( obj instanceof String )
                    rec.setValue( colMap.getColumnName(),
                                  (String)obj );
                else if ( obj instanceof Integer)
                    rec.setValue( colMap.getColumnName(),
                                  criteria.getInt(key) );
                else if ( obj instanceof BigDecimal)
                    rec.setValue( colMap.getColumnName(),
                                  (BigDecimal)obj );
                else if ( obj instanceof Long)
                    rec.setValue( colMap.getColumnName(),
                                  criteria.getLong(key) );
                else if ( obj instanceof java.util.Date)
                    rec.setValue( colMap.getColumnName(),
                                  (java.util.Date)obj );
                else if ( obj instanceof Float)
                    rec.setValue( colMap.getColumnName(),
                                  criteria.getFloat(key) );
                else if ( obj instanceof Double)
                    rec.setValue( colMap.getColumnName(),
                                  criteria.getDouble(key) );
                else if ( obj instanceof Hashtable )
                    rec.setValue( colMap.getColumnName(),
                                  hashtableToByteArray( (Hashtable)obj ) );
                else if ( obj instanceof byte[])
                    rec.setValue( colMap.getColumnName(),
                                  (byte[])obj);
                else if ( obj instanceof Boolean)
                    rec.setValue( colMap.getColumnName(),
                                   criteria.getBoolean(key) ? 1 : 0);
                shouldSave = true;
             }
        }
        if ( shouldSave )
View Full Code Here

                String columnName;
                if (spacePos == -1)
                    columnName = orderByColumn.substring(orderByColumn.indexOf('.') + 1);
                else
                    columnName = orderByColumn.substring(orderByColumn.indexOf('.') + 1, spacePos);
                ColumnMap column = dbMap.getTable(table).getColumn( columnName );
                if ( column.getType() instanceof String )
                {
                    if (spacePos == -1)
                        orderByClause.add( db.ignoreCaseInOrderBy(orderByColumn) );
                    else
                        orderByClause.add( db.ignoreCaseInOrderBy(orderByColumn.substring(0, spacePos)) + orderByColumn.substring(spacePos) );
View Full Code Here

    {
        // Assume all the keys are for the same table.
        String key = (String)criteria.keys().nextElement();

        String table = criteria.getTableName(key);
        ColumnMap pk = null;

        if ( !table.equals("") )
        {
            DatabaseMap dbMap = TurbineDB.getDatabaseMap(criteria.getDbName());
            if (dbMap == null)
View Full Code Here

     */
    public static void doUpdate(Criteria updateValues,
                                DBConnection dbCon)
        throws Exception
    {
        ColumnMap pk = getPrimaryKey(updateValues);
        Criteria selectCriteria = null;

        if ( pk != null &&
             updateValues.containsKey(pk.getFullyQualifiedName()) )
        {
            selectCriteria = new Criteria(2);
            selectCriteria.put( pk.getFullyQualifiedName(),
                                updateValues.remove(pk.getFullyQualifiedName()) );
        }
        else
        {
            throw new Exception("BasePeer.doUpdate(criteria) - no PK specified");
        }
View Full Code Here

            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 ));
                    }
View Full Code Here

                String columnName;
                if (spacePos == -1)
                    columnName = orderByColumn.substring(orderByColumn.indexOf('.') + 1);
                else
                    columnName = orderByColumn.substring(orderByColumn.indexOf('.') + 1, spacePos);
                ColumnMap column = dbMap.getTable(table).getColumn( columnName );
                if ( column.getType() instanceof String )
                {
                    if (spacePos == -1)
                        orderByClause.add( db.ignoreCaseInOrderBy(orderByColumn) );
                    else
                        orderByClause.add( db.ignoreCaseInOrderBy(orderByColumn.substring(0, spacePos)) + orderByColumn.substring(spacePos) );
View Full Code Here

            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));
                    }
View Full Code Here

        DatabaseMap dbMap = TurbineDB.getDatabaseMap( criteria.getDbName() );
        TableMap tableMap = dbMap.getTable(tableName);
        Object keyInfo = tableMap.getPrimaryKeyMethodInfo();
        IdGenerator keyGen = tableMap.getIdGenerator();

        ColumnMap pk = getPrimaryKey(criteria);
        // only get a new key value if you need to
        // the reason is that a primary key might be defined
        // but you are still going to set its value. for example:
        // a join table where both keys are primary and you are
        // setting both columns with your own values
        boolean info = false;
       
        if (!criteria.containsKey(pk.getFullyQualifiedName()))
        {
            // If the keyMethod is SEQUENCE or IDBROKERTABLE, get the id
            // before the insert.
           
            if (keyGen.isPriorToInsert())
            {
                if ( pk.getType() instanceof Number )
                {
                    id = new NumberKey( tableMap.getIdGenerator()
                        .getIdAsBigDecimal(dbCon.getConnection(), keyInfo) );
                }
                else
                {
                    id = new StringKey( tableMap.getIdGenerator()
                        .getIdAsString(dbCon.getConnection(), keyInfo) );
                }
                criteria.add( pk.getFullyQualifiedName(), id );
            }
        }

        // Set up Village for the insert.
        TableDataSet tds = null;
        try
        {
            tds = new TableDataSet(dbCon.getConnection(), tableName );
            Record rec = tds.addRecord();
            insertOrUpdateRecord(rec, tableName, criteria);
        }
        finally
        {
            if (tds != null) tds.close();
        }

        // If the primary key column is auto-incremented, get the id
        // now.
        if ((keyGen != null) && (keyGen.isPostInsert()))
        {
            if ( pk.getType() instanceof Number )
            {
                id = new NumberKey( tableMap.getIdGenerator()
                    .getIdAsBigDecimal(dbCon.getConnection(), keyInfo) );
            }
            else
View Full Code Here

TOP

Related Classes of org.apache.turbine.util.db.map.ColumnMap

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.