Package org.jboss.as.cmp.jdbc.metadata

Examples of org.jboss.as.cmp.jdbc.metadata.JDBCFunctionMappingMetaData


        if (entity.getMetaData().hasRowLocking()) {
            JDBCEntityPersistenceStore manager = entity.getManager();
            JDBCTypeFactory typeFactory = manager.getJDBCTypeFactory();
            JDBCTypeMappingMetaData typeMapping = typeFactory.getTypeMapping();
            JDBCFunctionMappingMetaData rowLockingTemplate = typeMapping.getRowLockingTemplate();
            if (rowLockingTemplate == null) {
                throw CmpMessages.MESSAGES.noRowLockingTemplateForMapping(typeMapping.getName());
            }

            selectSql = rowLockingTemplate.getFunctionSql(new Object[]{selectColumns, tableName, whereColumns, null},
                    new StringBuffer()).toString();
        } else {
            selectSql = "select ";
            selectSql += selectColumns;
            selectSql += " from " + tableName + " where ";
View Full Code Here


                    break;
                }
                case ADD_COLUMN_TEMPLATE: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setAddColumnTemplate(new JDBCFunctionMappingMetaData("add-column-template", value));
                    } else {
                        metaData.setAddColumnTemplate(new JDBCFunctionMappingMetaData("add-column-template", "ALTER TABLE ?1 ADD ?2 ?3"));
                    }
                    break;
                }
                case ALIAS_HEADER_PREFIX: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setAliasHeaderPrefix(value);
                    }
                    break;
                }
                case ALIAS_HEADER_SUFFIX: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setAliasHeaderSuffix(value);
                    }
                    break;
                }
                case ALIAS_MAX_LENGHT: {
                    final String value = getElementText(reader);
                    try {
                        final int aliasMaxLength = Integer.parseInt(value);
                        metaData.setAliasMaxLength(aliasMaxLength);
                    } catch (NumberFormatException e) {
                        throw MESSAGES.invalidNumberFormat("alias-max-length", value);
                    }
                    break;
                }
                case ALTER_COLUMN_TEMPLATE: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setAlterColumnTemplate(new JDBCFunctionMappingMetaData("add-column-template", value));
                    } else {
                        metaData.setAlterColumnTemplate(new JDBCFunctionMappingMetaData("add-column-template", "ALTER TABLE ?1 ADD ?2 ?3"));
                    }
                    break;
                }
                case AUTO_INCREMENT_TEMPLATE: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setAutoIncrementTemplate(new JDBCFunctionMappingMetaData("auto-increment", value));
                    }
                    break;
                }
                case DROP_COLUMN_TEMPLATE: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setDropColumnTemplate(new JDBCFunctionMappingMetaData("drop-column-template", value));
                    } else {
                        metaData.setDropColumnTemplate(new JDBCFunctionMappingMetaData("drop-column-template", "ALTER TABLE ?1 DROP ?2"));
                    }
                    break;
                }
                case FALSE_MAPPING: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setFalseMapping(value);
                    }
                    break;
                }
                case FK_CONSTRAINT_TEMPLATE: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setFKConstraintTemplate(new JDBCFunctionMappingMetaData("fk-constraint", value));
                    }
                    break;
                }
                case FUNCTION_MAPPING: {
                    metaData.addFunctionMapping(parseFunctionMapping(reader));
                    break;
                }
                case MAPPING: {
                    metaData.addMapping(parseMapping(reader));
                    break;
                }
                case MAX_KEYS_IN_DELETE: {
                    final String value = getElementText(reader);
                    try {
                        final int maxKeys = Integer.parseInt(value);
                        metaData.setMaxKeysInDelete(maxKeys);
                    } catch (NumberFormatException e) {
                        throw MESSAGES.invalidNumberFormat("max-keys-in-delete", value);
                    }
                    break;
                }
                case PK_CONSTRAINT_TEMPLATE: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setPKConstraintTemplate(new JDBCFunctionMappingMetaData("pk-constraint", value));
                    }
                    break;
                }
                case ROW_LOCKING_TEMPLATE: {
                    final String value = getElementText(reader);
                    if (!isEmpty(value)) {
                        metaData.setRowLockingTemplate(new JDBCFunctionMappingMetaData("row-locking", value));
                    }
                    break;
                }
                case SUBQUERY_SUPPORTED: {
                    metaData.setSubQuerySupported(Boolean.valueOf(getElementText(reader)));
View Full Code Here

        return metaData;
    }

    private static JDBCFunctionMappingMetaData parseFunctionMapping(final XMLStreamReader reader) throws XMLStreamException {

        final JDBCFunctionMappingMetaData metaData = new JDBCFunctionMappingMetaData();
        for (Element element : children(reader)) {
            switch (element) {
                case FUNCTION_NAME: {
                    metaData.setFunctionName(getElementText(reader));
                    break;
                }
                case FUNCTION_SQL: {
                    metaData.setFunctionSql(getElementText(reader));
                    break;
                }
                default: {
                    throw unexpectedElement(reader);
                }
View Full Code Here

            addField(type, sql);
        }

        // add a pk constraint
        if (entityMetaData.hasPrimaryKeyConstraint()) {
            JDBCFunctionMappingMetaData pkConstraint = manager.getMetaData().getTypeMapping().getPkConstraintTemplate();
            if (pkConstraint == null) {
                throw CmpMessages.MESSAGES.pkNotAllowedForDatasource();
            }

            String defTableName = entity.getManager().getMetaData().getDefaultTableName();
            String name = "pk_" + SQLUtil.unquote(defTableName, dataSource);
            name = SQLUtil.fixConstraintName(name, dataSource);
            String[] args = new String[]{
                    name,
                    SQLUtil.getColumnNamesClause(entity.getPrimaryKeyFields(), new StringBuffer(100)).toString()
            };
            sql.append(SQLUtil.COMMA);
            pkConstraint.getFunctionSql(args, sql);
        }

        return sql.append(')').toString();
    }
View Full Code Here

    private void addField(JDBCType type, StringBuffer sqlBuffer) {
        // apply auto-increment template
        if (type.getAutoIncrement()[0]) {
            String columnClause = SQLUtil.getCreateTableColumnsClause(type);
            JDBCFunctionMappingMetaData autoIncrement =
                    manager.getMetaData().getTypeMapping().getAutoIncrementTemplate();
            if (autoIncrement == null) {
                throw MESSAGES.autoIncTemplateNotFound();
            }
            String[] args = new String[]{columnClause};
            autoIncrement.getFunctionSql(args, sqlBuffer);
        } else {
            sqlBuffer.append(SQLUtil.getCreateTableColumnsClause(type));
        }
    }
View Full Code Here

                .append(SQLUtil.getCreateTableColumnsClause(fieldsArr));

        // add a pk constraint
        final JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();
        if (relationMetaData.hasPrimaryKeyConstraint()) {
            JDBCFunctionMappingMetaData pkConstraint =
                    manager.getMetaData().getTypeMapping().getPkConstraintTemplate();
            if (pkConstraint == null) {
                throw MESSAGES.pkConstraintNotAllowed();
            }

            String name = "pk_" + relationMetaData.getDefaultTableName();
            name = SQLUtil.fixConstraintName(name, dataSource);
            String[] args = new String[]{
                    name,
                    SQLUtil.getColumnNamesClause(fieldsArr, new StringBuffer(100).toString(), new StringBuffer()).toString()
            };
            sql.append(SQLUtil.COMMA);
            pkConstraint.getFunctionSql(args, sql);
        }
        sql.append(')');
        return sql.toString();
    }
View Full Code Here

        // can only alter tables we created
        if (!manager.hasCreateTable(tableName)) {
            return;
        }

        JDBCFunctionMappingMetaData fkConstraint = manager.getMetaData().getTypeMapping().getFkConstraintTemplate();
        if (fkConstraint == null) {
            throw MESSAGES.fkConstraintNotAllowed();
        }
        String a = SQLUtil.getColumnNamesClause(fields, new StringBuffer(50)).toString();
        String b = SQLUtil.getColumnNamesClause(referencesFields, new StringBuffer(50)).toString();

        String[] args = new String[]{
                tableName,
                SQLUtil.fixConstraintName("fk_" + tableName + "_" + cmrFieldName, dataSource),
                a,
                referencesTableName,
                b};

        String sql = fkConstraint.getFunctionSql(args, new StringBuffer(100)).toString();

        // since we use the pools, we have to do this within a transaction
        // suspend the current transaction
        TransactionManager tm = manager.getComponent().getTransactionManager();
        Transaction oldTransaction;
View Full Code Here

            select.insert(0, SQLUtil.DISTINCT);
        }

        StringBuffer buf = (StringBuffer) data;
        if (selectManager.getMetaData().hasRowLocking()) {
            JDBCFunctionMappingMetaData rowLockingTemplate = typeMapping.getRowLockingTemplate();
            Object[] args = new Object[]{
                    select,
                    from,
                    where.length() == 0 ? null : where,
                    orderBy.length() == 0 ? null : orderBy
            };
            rowLockingTemplate.getFunctionSql(args, buf);
        } else {
            buf.append(SQLUtil.SELECT)
                    .append(select)
                    .append(SQLUtil.FROM)
                    .append(from);
View Full Code Here

    /**
     * Type-mapping function translation
     */
    public Object visit(ASTConcat node, Object data) {
        StringBuffer buf = (StringBuffer) data;
        JDBCFunctionMappingMetaData function = typeMapping.getFunctionMapping(JDBCTypeMappingMetaData.CONCAT);
        Object[] args = new Object[]{
                new NodeStringWrapper(node.jjtGetChild(0)),
                new NodeStringWrapper(node.jjtGetChild(1)),
        };
        function.getFunctionSql(args, buf);
        return buf;
    }
View Full Code Here

    /**
     * Type-mapping function translation
     */
    public Object visit(ASTSubstring node, Object data) {
        StringBuffer buf = (StringBuffer) data;
        JDBCFunctionMappingMetaData function = typeMapping.getFunctionMapping(JDBCTypeMappingMetaData.SUBSTRING);
        Object[] args = new Object[]{
                new NodeStringWrapper(node.jjtGetChild(0)),
                new NodeStringWrapper(node.jjtGetChild(1)),
                new NodeStringWrapper(node.jjtGetChild(2)),
        };
        function.getFunctionSql(args, buf);
        return buf;
    }
View Full Code Here

TOP

Related Classes of org.jboss.as.cmp.jdbc.metadata.JDBCFunctionMappingMetaData

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.