Examples of DatabaseMap


Examples of org.apache.torque.map.DatabaseMap

                          Connection connection)
        throws Exception
    {
        BigDecimal nextId = null;
        BigDecimal quantity = null;
        DatabaseMap dbMap = tableMap.getDatabaseMap();

        // Block on the table.  Multiple tables are allowed to ask for
        // ids simultaneously.
        //        TableMap tMap = dbMap.getTable(tableName);
        //        synchronized(tMap)  see comment in the getNextIds method
        //        {
        if (adjustQuantity)
        {
            checkTiming(tableName);
        }

        boolean useNewConnection = (connection == null) || (configuration
                .getBoolean(DB_IDBROKER_USENEWCONNECTION, true));
        try
        {
            if (useNewConnection)
            {
                connection = Transaction.beginOptional(dbMap.getName(),
                    transactionsSupported);
            }

            // Write the current value of quantity of keys to grab
            // to the database, primarily to obtain a write lock
View Full Code Here

Examples of org.apache.torque.map.DatabaseMap

     */
    public static void doDelete(Criteria criteria, Connection con)
        throws TorqueException
    {
        DB db = Torque.getDB(criteria.getDbName());
        DatabaseMap dbMap = Torque.getDatabaseMap(criteria.getDbName());

        // Set up a list of required tables and add extra entries to
        // criteria if directed to delete all related records.
        // StringStack.add() only adds element if it is unique.
        HashSet tables = new HashSet();
        Iterator it = criteria.keySet().iterator();
        while (it.hasNext())
        {
            String key = (String) it.next();
            Criteria.Criterion c = criteria.getCriterion(key);
            List tableNames = c.getAllTables();
            for (int i = 0; i < tableNames.size(); i++)
            {
                String name = (String) tableNames.get(i);
                String tableName2 = criteria.getTableForAlias(name);
                if (tableName2 != null)
                {
                    tables.add(new StringBuffer(
                            name.length() + tableName2.length() + 1)
                            .append(tableName2)
                            .append(' ')
                            .append(name)
                            .toString());
                }
                else
                {
                    tables.add(name);
                }
            }

            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
                        // updating, 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));
                        }
                    }
                }
            }
        }
        Iterator tabIt = tables.iterator();
        while (tabIt.hasNext())
        {
            String tab = (String) tabIt.next();
            KeyDef kd = new KeyDef();
            HashSet whereClause = new HashSet();

            ColumnMap[] columnMaps = dbMap.getTable(tab).getColumns();
            for (int j = 0; j < columnMaps.length; j++)
            {
                ColumnMap colMap = columnMaps[j];
                if (colMap.isPrimaryKey())
                {
View Full Code Here

Examples of org.apache.torque.map.DatabaseMap

        {
            throw new TorqueException("Database insert attempted without "
                    + "anything specified to insert");
        }

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

        ColumnMap pk = getPrimaryKey(criteria);
View Full Code Here

Examples of org.apache.torque.map.DatabaseMap

        Record rec,
        String tableName,
        Criteria criteria)
        throws TorqueException
    {
        DatabaseMap dbMap = Torque.getDatabaseMap(criteria.getDbName());

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

Examples of org.apache.torque.map.DatabaseMap

    static Query createQuery(Criteria criteria)
        throws TorqueException
    {
        Query query = new Query();
        DB db = Torque.getDB(criteria.getDbName());
        DatabaseMap dbMap = Torque.getDatabaseMap(criteria.getDbName());

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

        UniqueList orderBy = criteria.getOrderByColumns();
        UniqueList groupBy = criteria.getGroupByColumns();
        UniqueList select = criteria.getSelectColumns();
        Hashtable aliases = criteria.getAsColumns();
        UniqueList 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 = (String) select.get(i);
            if (columnName.indexOf('.') == -&& columnName.indexOf('*') == -1)
            {
                throwMalformedColumnNameException("select", columnName);
            }
            String tableName = null;
            selectClause.add(columnName);
            int parenPos = columnName.indexOf('(');
            if (parenPos == -1)
            {
                tableName = columnName.substring(0, columnName.indexOf('.'));
            }
            else if (columnName.indexOf('.') > -1)
            {
                tableName =
                    columnName.substring(parenPos + 1, columnName.indexOf('.'));
                // functions may contain qualifiers so only take the last
                // word as the table name.
                int lastSpace = tableName.lastIndexOf(' ');
                if (lastSpace != -1)
                {
                    tableName = tableName.substring(lastSpace + 1);
                }
            }
            String tableName2 = criteria.getTableForAlias(tableName);
            if (tableName2 != null)
            {
                fromClause.add(new StringBuffer(
                        tableName.length() + tableName2.length() + 1)
                        .append(tableName2)
                        .append(' ')
                        .append(tableName)
                        .toString());
            }
            else
            {
                fromClause.add(tableName);
            }
        }

        Iterator it = aliases.keySet().iterator();
        while (it.hasNext())
        {
            String key = (String) it.next();
            selectClause.add((String) aliases.get(key) + " AS " + key);
        }

        Iterator critKeys = criteria.keySet().iterator();
        while (critKeys.hasNext())
        {
            String key = (String) critKeys.next();
            Criteria.Criterion criterion = criteria.getCriterion(key);
            Criteria.Criterion[] someCriteria =
                criterion.getAttachedCriterion();
            String table = null;
            for (int i = 0; i < someCriteria.length; i++)
            {
                String tableName = someCriteria[i].getTable();
                table = criteria.getTableForAlias(tableName);
                if (table != null)
                {
                    fromClause.add(new StringBuffer(
                            tableName.length() + table.length() + 1)
                            .append(table)
                            .append(' ')
                            .append(tableName)
                            .toString());
                }
                else
                {
                    fromClause.add(tableName);
                    table = tableName;
                }

                boolean ignorCase = ((criteria.isIgnoreCase()
                        || someCriteria[i].isIgnoreCase())
                        && (dbMap
                            .getTable(table)
                            .getColumn(someCriteria[i].getColumn())
                            .getType()
                            instanceof String));

                someCriteria[i].setIgnoreCase(ignorCase);
            }

            criterion.setDB(db);
            whereClause.add(criterion.toString());
        }

        List join = criteria.getJoinL();
        if (join != null)
        {
            for (int i = 0; i < join.size(); i++)
            {
                String join1 = (String) join.get(i);
                String join2 = (String) criteria.getJoinR().get(i);
                if (join1.indexOf('.') == -1)
                {
                    throwMalformedColumnNameException("join", join1);
                }
                if (join2.indexOf('.') == -1)
                {
                    throwMalformedColumnNameException("join", join2);
                }

                String tableName = join1.substring(0, join1.indexOf('.'));
                String table = criteria.getTableForAlias(tableName);
                if (table != null)
                {
                    fromClause.add(new StringBuffer(
                            tableName.length() + table.length() + 1)
                            .append(table)
                            .append(' ')
                            .append(tableName)
                            .toString());
                }
                else
                {
                    fromClause.add(tableName);
                }

                int dot = join2.indexOf('.');
                tableName = join2.substring(0, dot);
                table = criteria.getTableForAlias(tableName);
                if (table != null)
                {
                    fromClause.add(new StringBuffer(
                            tableName.length() + table.length() + 1)
                            .append(table)
                            .append(' ')
                            .append(tableName)
                            .toString());
                }
                else
                {
                    fromClause.add(tableName);
                    table = tableName;
                }

                boolean ignorCase = (criteria.isIgnoreCase()
                        && (dbMap
                            .getTable(table)
                            .getColumn(join2.substring(dot + 1, join2.length()))
                            .getType()
                            instanceof String));

                whereClause.add(
                    SqlExpression.buildInnerJoin(join1, join2, ignorCase, db));
            }
        }

        // need to allow for multiple group bys
        if (groupBy != null && groupBy.size() > 0)
        {
            for (int i = 0; i < groupBy.size(); i++)
            {
                String groupByColumn = (String) groupBy.get(i);
                if (groupByColumn.indexOf('.') == -1)
                {
                    throwMalformedColumnNameException("group by",
                            groupByColumn);
                }
                groupByClause.add(groupByColumn);
            }
        }

        Criteria.Criterion having = criteria.getHaving();
        if (having != null)
        {
            //String groupByString = null;
            query.setHaving(having.toString());
        }

        if (orderBy != null && orderBy.size() > 0)
        {
            // Check for each String/Character column and apply
            // toUpperCase().
            for (int i = 0; i < orderBy.size(); i++)
            {
                String orderByColumn = (String) orderBy.get(i);
                if (orderByColumn.indexOf('.') == -1)
                {
                    throwMalformedColumnNameException("order by",
                            orderByColumn);
                }
                String tableName =
                    orderByColumn.substring(0, orderByColumn.indexOf('.'));
                String table = criteria.getTableForAlias(tableName);
                if (table == null)
                {
                    table = tableName;
                }

                // See if there's a space (between the column list and sort
                // order in ORDER BY table.column DESC).
                int spacePos = orderByColumn.indexOf(' ');
                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(
View Full Code Here

Examples of org.apache.torque.map.DatabaseMap

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

        if (!table.equals(""))
        {
            DatabaseMap dbMap = Torque.getDatabaseMap(criteria.getDbName());
            if (dbMap == null)
            {
                throw new TorqueException("dbMap is null");
            }
            if (dbMap.getTable(table) == null)
            {
                throw new TorqueException("dbMap.getTable() is null");
            }

            ColumnMap[] columns = dbMap.getTable(table).getColumns();

            for (int i = 0; i < columns.length; i++)
            {
                if (columns[i].isPrimaryKey())
                {
View Full Code Here

Examples of org.apache.torque.map.DatabaseMap

        Criteria updateValues,
        Connection con)
        throws TorqueException
    {
        DB db = Torque.getDB(selectCriteria.getDbName());
        DatabaseMap dbMap = Torque.getDatabaseMap(selectCriteria.getDbName());

        // Set up a list of required tables. StringStack.add()
        // only adds element if it is unique.
        HashSet tables = new HashSet();
        Iterator it = selectCriteria.keySet().iterator();
        while (it.hasNext())
        {
            tables.add(selectCriteria.getTableName((String) it.next()));
        }

        Iterator tabIt = tables.iterator();
        while (tabIt.hasNext())
        {
            String tab = (String) tabIt.next();
            KeyDef kd = new KeyDef();
            HashSet whereClause = new HashSet();
            DatabaseMap tempDbMap = dbMap;

            ColumnMap[] columnMaps = tempDbMap.getTable(tab).getColumns();
            for (int j = 0; j < columnMaps.length; j++)
            {
                ColumnMap colMap = columnMaps[j];
                if (colMap.isPrimaryKey())
                {
View Full Code Here

Examples of org.apache.torque.map.DatabaseMap

        StringBuffer queryString,
        List params)
        throws TorqueException
    {
        DB db = Torque.getDB(criteria.getDbName());
        DatabaseMap dbMap = Torque.getDatabaseMap(criteria.getDbName());

        Query query = new Query();

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

        UniqueList orderBy = criteria.getOrderByColumns();
        UniqueList select = criteria.getSelectColumns();
        Hashtable aliases = criteria.getAsColumns();
        UniqueList 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 = (String) select.get(i);
            if (columnName.indexOf('.') == -1)
            {
                throwMalformedColumnNameException("select", columnName);
            }
            String tableName = null;
            selectClause.add(columnName);
            int parenPos = columnName.indexOf('(');
            if (parenPos == -1)
            {
                tableName = columnName.substring(0, columnName.indexOf('.'));
            }
            else
            {
                tableName =
                    columnName.substring(parenPos + 1, columnName.indexOf('.'));
                // functions may contain qualifiers so only take the last
                // word as the table name.
                int lastSpace = tableName.lastIndexOf(' ');
                if (lastSpace != -1)
                {
                    tableName = tableName.substring(lastSpace + 1);
                }
            }
            String tableName2 = criteria.getTableForAlias(tableName);
            if (tableName2 != null)
            {
                fromClause.add(new StringBuffer(tableName.length()
                        + tableName2.length() + 1)
                        .append(tableName2)
                        .append(' ')
                        .append(tableName)
                        .toString());
            }
            else
            {
                fromClause.add(tableName);
            }
        }

        Iterator it = aliases.keySet().iterator();
        while (it.hasNext())
        {
            String key = (String) it.next();
            selectClause.add((String) aliases.get(key) + " AS " + key);
        }

        Iterator critKeys = criteria.keySet().iterator();
        while (critKeys.hasNext())
        {
            String key = (String) critKeys.next();
            Criteria.Criterion criterion = criteria.getCriterion(key);
            Criteria.Criterion[] someCriteria =
                criterion.getAttachedCriterion();

            String table = null;
            for (int i = 0; i < someCriteria.length; i++)
            {
                String tableName = someCriteria[i].getTable();
                table = criteria.getTableForAlias(tableName);
                if (table != null)
                {
                    fromClause.add(new StringBuffer(tableName.length()
                            + table.length() + 1)
                            .append(table)
                            .append(' ')
                            .append(tableName)
                            .toString());
                }
                else
                {
                    fromClause.add(tableName);
                    table = tableName;
                }

                boolean ignorCase = ((criteria.isIgnoreCase()
                        || someCriteria[i].isIgnoreCase())
                        && (dbMap
                            .getTable(table)
                            .getColumn(someCriteria[i].getColumn())
                            .getType()
                            instanceof String));

                someCriteria[i].setIgnoreCase(ignorCase);
            }

            criterion.setDB(db);
            StringBuffer sb = new StringBuffer();
            criterion.appendPsTo(sb, params);
            whereClause.add(sb.toString());
        }

        List join = criteria.getJoinL();
        if (join != null)
        {
            for (int i = 0; i < join.size(); i++)
            {
                String join1 = (String) join.get(i);
                String join2 = (String) criteria.getJoinR().get(i);
                if (join1.indexOf('.') == -1)
                {
                    throwMalformedColumnNameException("join", join1);
                }
                if (join2.indexOf('.') == -1)
                {
                    throwMalformedColumnNameException("join", join2);
                }

                String tableName = join1.substring(0, join1.indexOf('.'));
                String table = criteria.getTableForAlias(tableName);
                if (table != null)
                {
                    fromClause.add(new StringBuffer(tableName.length()
                            + table.length() + 1)
                            .append(table)
                            .append(' ')
                            .append(tableName)
                            .toString());
                }
                else
                {
                    fromClause.add(tableName);
                }

                int dot = join2.indexOf('.');
                tableName = join2.substring(0, dot);
                table = criteria.getTableForAlias(tableName);
                if (table != null)
                {
                    fromClause.add(new StringBuffer(tableName.length()
                            + table.length() + 1)
                            .append(table)
                            .append(' ')
                            .append(tableName)
                            .toString());
                }
                else
                {
                    fromClause.add(tableName);
                    table = tableName;
                }

                boolean ignorCase = (criteria.isIgnoreCase()
                        && (dbMap
                            .getTable(table)
                            .getColumn(join2.substring(dot + 1, join2.length()))
                            .getType()
                            instanceof String));

                whereClause.add(
                    SqlExpression.buildInnerJoin(join1, join2, ignorCase, db));
            }
        }

        if (orderBy != null && orderBy.size() > 0)
        {
            // Check for each String/Character column and apply
            // toUpperCase().
            for (int i = 0; i < orderBy.size(); i++)
            {
                String orderByColumn = (String) orderBy.get(i);
                if (orderByColumn.indexOf('.') == -1)
                {
                    throwMalformedColumnNameException("order by",
                        orderByColumn);
                }
                String table =
                    orderByColumn.substring(0, orderByColumn.indexOf('.'));
                // See if there's a space (between the column list and sort
                // order in ORDER BY table.column DESC).
                int spacePos = orderByColumn.indexOf(' ');
                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(
View Full Code Here

Examples of org.apache.torque.map.DatabaseMap

    {
        if (dbMaps != null)
        {
            for (Iterator it = dbMaps.values().iterator(); it.hasNext();)
            {
                DatabaseMap map = (DatabaseMap) it.next();
                IDBroker idBroker = map.getIDBroker();
                if (idBroker != null)
                {
                    idBroker.stop();
                }
            }
View Full Code Here

Examples of org.apache.torque.map.DatabaseMap

            throw new TorqueException("Torque was not initialized properly.");
        }

        synchronized (dbMaps)
        {
            DatabaseMap map = (DatabaseMap) dbMaps.get(name);
            if (map == null)
            {
                // Still not there.  Create and add.
                map = initDatabaseMap(name);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.