Package org.apache.cayenne.dba

Examples of org.apache.cayenne.dba.QuotingStrategy


        }
        else {
            status = false;
        }

        QuotingStrategy strategy = getAdapter().getQuotingStrategy(status);
        forcingDistinct = false;

        // build column list
        this.resultColumns = buildResultColumns();
View Full Code Here


    @Override
    public String createSqlString(BatchQuery batch) throws IOException {
        boolean status = batch.getDbEntity().getDataMap() != null
            && batch.getDbEntity().getDataMap().isQuotingSQLIdentifiers();
       
        QuotingStrategy strategy =  getAdapter().getQuotingStrategy(status);
      
        StringBuffer query = new StringBuffer("DELETE FROM ");
        query.append(strategy.quoteFullyQualifiedName(batch.getDbEntity()));

        applyQualifier(query, batch);

        return query.toString();
    }
View Full Code Here

        if(batch.getDbEntity().getDataMap()!=null && batch.getDbEntity().getDataMap().isQuotingSQLIdentifiers()){
            status= true;
        } else {
            status = false;
        }
        QuotingStrategy strategy =  getAdapter().getQuotingStrategy(status);

        StringBuilder query = new StringBuilder("INSERT INTO ");
        query.append(strategy.quoteFullyQualifiedName(batch.getDbEntity()));
        query.append(" (");

        int columnCount = 0;
        for (DbAttribute attribute : dbAttributes) {

            // attribute inclusion rule - one of the rules below must be true:
            // (1) attribute not generated
            // (2) attribute is generated and PK and adapter does not support generated
            // keys

            if (includeInBatch(attribute)) {

                if (columnCount > 0) {
                    query.append(", ");
                }
                query.append(strategy.quoteString(attribute.getName()));
                columnCount++;
            }
        }

        query.append(") VALUES (");
View Full Code Here

        }
       
        boolean status = batch.getDbEntity().getDataMap() != null
            && batch.getDbEntity().getDataMap().isQuotingSQLIdentifiers();
       
        QuotingStrategy strategy = getAdapter().getQuotingStrategy(status);
      
        StringBuffer query = new StringBuffer("UPDATE ");
        query.append(strategy.quoteFullyQualifiedName(batch.getDbEntity()));
        query.append(" SET ").append(strategy.quoteString(deletedFieldName)).append(" = ?");

        applyQualifier(query, batch);

        return query.toString();
    }
View Full Code Here

    }

    @Override
    public List<String> createSql(DbAdapter adapter) {
        StringBuffer sqlBuffer = new StringBuffer();
        QuotingStrategy context = adapter.getQuotingStrategy(getEntity()
                .getDataMap()
                .isQuotingSQLIdentifiers());
        appendPrefix(sqlBuffer, context);
 
        // copied from JdbcAdapter.createTableAppendColumn
View Full Code Here

    }

    @Override
    public List<String> createSql(DbAdapter adapter) {
        StringBuilder sqlBuffer = new StringBuilder();
        QuotingStrategy context = adapter.getQuotingStrategy(getEntity()
                .getDataMap()
                .isQuotingSQLIdentifiers());
        sqlBuffer.append("ALTER TABLE ");
        sqlBuffer.append(context.quoteFullyQualifiedName(getEntity()));
        sqlBuffer.append(" ALTER COLUMN ");
        sqlBuffer.append(context.quoteString(getColumn().getName()));
        sqlBuffer.append(" DROP NOT NULL");

        return Collections.singletonList(sqlBuffer.toString());
    }
View Full Code Here

        }
        else {
            status = false;
        }

        QuotingStrategy strategy = getAdapter().getQuotingStrategy(status);
        forcingDistinct = false;

        // build column list
        this.resultColumns = buildResultColumns();
View Full Code Here

    /**
     * @deprecated since 3.0
     */
    @Override
    public String dropTable(DbEntity table) {
        QuotingStrategy context = getQuotingStrategy(table.getDataMap().isQuotingSQLIdentifiers());
        StringBuffer buf = new StringBuffer("DROP TABLE IF EXISTS ");
        buf.append(context.quoteFullyQualifiedName(table));           
        buf.append(" CASCADE");
        return buf.toString();
    }
View Full Code Here

    @Override
    public Collection<String> dropTableStatements(DbEntity table) {
        // note that CASCADE is a noop as of MySQL 5.0, so we have to use FK checks
        // statement
        StringBuffer buf = new StringBuffer();
        QuotingStrategy context = getQuotingStrategy(table.getDataMap().isQuotingSQLIdentifiers());
        buf.append(context.quoteFullyQualifiedName(table));           
       
        return Arrays.asList("SET FOREIGN_KEY_CHECKS=0", "DROP TABLE IF EXISTS "
                + buf.toString()
                + " CASCADE", "SET FOREIGN_KEY_CHECKS=1");
    }
View Full Code Here

            if(entity.getDataMap()!=null && entity.getDataMap().isQuotingSQLIdentifiers()){
                status= true;
            } else {
                status = false;
            }
        QuotingStrategy context = getQuotingStrategy(status);
        // must move generated to the front...
        List<DbAttribute> pkList = new ArrayList<DbAttribute>(entity.getPrimaryKeys());
        Collections.sort(pkList, new PKComparator());

        Iterator<DbAttribute> pkit = pkList.iterator();
        if (pkit.hasNext()) {

            sqlBuffer.append(", PRIMARY KEY (");
            boolean firstPk = true;
            while (pkit.hasNext()) {
                if (firstPk)
                    firstPk = false;
                else
                    sqlBuffer.append(", ");

                DbAttribute at = pkit.next();
                sqlBuffer.append(context.quoteString(at.getName()));
            }
            sqlBuffer.append(')');
        }

        // if FK constraints are supported, we must add indices to all FKs
        // Note that according to MySQL docs, FK indexes are created automatically when
        // constraint is defined, starting at MySQL 4.1.2
        if (supportsFkConstraints()) {
            for (Relationship r : entity.getRelationships()) {
                DbRelationship relationship = (DbRelationship) r;
                if (relationship.getJoins().size() > 0
                        && relationship.isToPK()
                        && !relationship.isToDependentPK()) {

                    sqlBuffer.append(", KEY (");

                    Iterator<DbAttribute> columns = relationship
                            .getSourceAttributes()
                            .iterator();
                    DbAttribute column = columns.next();
                    sqlBuffer.append(context.quoteString(column.getName()));

                    while (columns.hasNext()) {
                        column = columns.next();
                        sqlBuffer.append(", ").append( context.quoteString(column.getName()));
                    }

                    sqlBuffer.append(")");
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.dba.QuotingStrategy

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.