Examples of QuotingStrategy


Examples of org.apache.cayenne.dba.QuotingStrategy

            if (entity == null) {
                continue;
            }
            boolean status = entity.getDataMap() != null
                    && entity.getDataMap().isQuotingSQLIdentifiers();
            QuotingStrategy strategy = getAdapter().getQuotingStrategy(status);

            for (String constraint : constraints) {
                StringBuilder drop = new StringBuilder();

                drop.append("ALTER TABLE ")
                .append(strategy.quoteFullyQualifiedName(entity))
                .append(" DROP CONSTRAINT ")
                .append(constraint);
                executeDDL(conn, drop.toString());
            }
        }
View Full Code Here

Examples of org.apache.cayenne.dba.QuotingStrategy

            if (entity == null) {
                continue;
            }
            boolean status = entity.getDataMap() != null
            && entity.getDataMap().isQuotingSQLIdentifiers();
            QuotingStrategy strategy = getAdapter().getQuotingStrategy(status);


            // Get all constraints for the table
            ResultSet rs = metadata.getExportedKeys(entity.getCatalog(), entity
                    .getSchema(), entity.getName());
            try {
                while (rs.next()) {
                    String fk = rs.getString("FK_NAME");
                    String fkTable = rs.getString("FKTABLE_NAME");

                    if (fk != null && fkTable != null) {
                        Collection<String> constraints = constraintMap.get(fkTable);
                        if (constraints == null) {
                            // use a set to avoid duplicate constraints
                            constraints = new HashSet<String>();
                            constraintMap.put(fkTable, constraints);
                        }

                        constraints.add(strategy.quoteString(fk));
                    }
                }
            }
            finally {
                rs.close();
View Full Code Here

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

Examples of org.apache.cayenne.dba.QuotingStrategy

            status = true;
        }
        else {
            status = false;
        }
        QuotingStrategy context = getAdapter().getQuotingStrategy(status);

        buffer.append(context.quoteString(entity.getName()));

        buffer.append(" (");

        Iterator<DbAttribute> it = pk.iterator();

        // at this point we know that there is at least on PK column
        DbAttribute firstColumn = it.next();
        buffer.append(context.quoteString(firstColumn.getName()));

        while (it.hasNext()) {
            DbAttribute column = it.next();
            buffer.append(", ");
            buffer.append(context.quoteString(column.getName()));
        }

        buffer.append(")");
        return buffer.toString();
    }
View Full Code Here

Examples of org.apache.cayenne.dba.QuotingStrategy

            status = true;
        }
        else {
            status = false;
        }
        QuotingStrategy context = getAdapter().getQuotingStrategy(status);
        if (pk == null || pk.size() == 0) {
            throw new CayenneRuntimeException("Entity '"
                    + entity.getName()
                    + "' has no PK defined.");
        }

        StringBuilder buffer = new StringBuilder();

        // compound PK doesn't work well with UNIQUE index...
        // create a regular one in this case
        buffer.append(pk.size() == 1 ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");

        buffer.append(context.quoteString(entity.getName()));
        buffer.append(" (");

        Iterator<DbAttribute> it = pk.iterator();

        // at this point we know that there is at least on PK column
        DbAttribute firstColumn = it.next();
        buffer.append(context.quoteString(firstColumn.getName()));

        while (it.hasNext()) {
            DbAttribute column = it.next();
            buffer.append(", ");
            buffer.append(context.quoteString(column.getName()));
        }
        buffer.append(")");
        return buffer.toString();
    }
View Full Code Here

Examples of org.apache.cayenne.dba.QuotingStrategy

     *
     * @since 3.0
     */
    @Override
    public Collection<String> dropTableStatements(DbEntity table) {
        QuotingStrategy context = getQuotingStrategy(table
                .getDataMap()
                .isQuotingSQLIdentifiers());
        StringBuffer buf = new StringBuffer("DROP TABLE ");
        buf.append(context.quoteFullyQualifiedName(table));

        buf.append(" CASCADE CONSTRAINTS");
        return Collections.singleton(buf.toString());
    }
View Full Code Here

Examples of org.apache.cayenne.dba.QuotingStrategy

            status = true;
        }
        else {
            status = false;
        }
        QuotingStrategy context = getAdapter().getQuotingStrategy(status);

        // use custom generator if possible
        DbKeyGenerator keyGenerator = entity.getPrimaryKeyGenerator();
        if (keyGenerator != null
                && DbKeyGenerator.ORACLE_TYPE.equals(keyGenerator.getGeneratorType())
                && keyGenerator.getGeneratorName() != null) {

            return keyGenerator.getGeneratorName().toLowerCase();
        }
        else {
            String entName = entity.getName();
            String seqName = _SEQUENCE_PREFIX + entName.toLowerCase();

            if (entity.getSchema() != null && entity.getSchema().length() > 0) {

                seqName = context.quoteString(entity.getSchema())
                        + "."
                        + context.quoteString(seqName);
            }
            else {
                seqName = context.quoteString(seqName);
            }
            return seqName;
        }
    }
View Full Code Here

Examples of org.apache.cayenne.dba.QuotingStrategy

        if ((column.getEntity().getDataMap() != null) && column.getEntity().getDataMap().isQuotingSQLIdentifiers()){
            status= true;
        } else {
            status = false;
        }
        QuotingStrategy context = getQuotingStrategy(status);
        String[] types = externalTypesForJdbcType(column.getType());
        if (types == null || types.length == 0) {
            String entityName = column.getEntity() != null ? ((DbEntity) column
                    .getEntity()).getFullyQualifiedName() : "<null>";
            throw new CayenneRuntimeException("Undefined type for attribute '"
                    + entityName
                    + "."
                    + column.getName()
                    + "': "
                    + column.getType());
        }

        String type = types[0];

        String length = "";
        if (typeSupportsLength(column.getType())) {
            int len = column.getMaxLength();
            int scale = TypesMapping.isDecimal(column.getType())
                    ? column.getScale()
                    : -1;

            // sanity check
            if (scale > len) {
                scale = -1;
            }

            if (len > 0) {
                length = " (" + len;

                if (scale >= 0) {
                    length += ", " + scale;
                }

                length += ")";
            }
        }

        // assemble...
        // note that max length for types like XYZ FOR BIT DATA must be entered in the
        // middle of type name, e.g. VARCHAR (100) FOR BIT DATA.

        sqlBuffer.append(context.quoteString(column.getName()));
      
        sqlBuffer.append(' ');
        if (length.length() > 0 && type.endsWith(FOR_BIT_DATA_SUFFIX)) {
            sqlBuffer.append(type.substring(0, type.length()
                    - FOR_BIT_DATA_SUFFIX.length()));
View Full Code Here

Examples of org.apache.cayenne.dba.QuotingStrategy

        if(ent.getDataMap()!=null && ent.getDataMap().isQuotingSQLIdentifiers()){
            status= true;
        } else {
            status = false;
        }
        QuotingStrategy context =  getQuotingStrategy(status);
        StringBuilder buf = new StringBuilder();
        buf.append("CREATE TABLE ");
       
        buf.append(context.quoteFullyQualifiedName(ent));
     
        buf.append(" (");

        // columns
        Iterator<DbAttribute> it = ent.getAttributes().iterator();
        boolean first = true;
        while (it.hasNext()) {
            if (first)
                first = false;
            else
                buf.append(", ");

            DbAttribute at = it.next();

            // attribute may not be fully valid, do a simple check
            if (at.getType() == TypesMapping.NOT_DEFINED) {
                throw new CayenneRuntimeException("Undefined type for attribute '"
                        + ent.getFullyQualifiedName()
                        + "."
                        + at.getName()
                        + "'.");
            }

            String[] types = externalTypesForJdbcType(at.getType());
            if (types == null || types.length == 0) {
                throw new CayenneRuntimeException("Undefined type for attribute '"
                        + ent.getFullyQualifiedName()
                        + "."
                        + at.getName()
                        + "': "
                        + at.getType());
            }

            String type = types[0];
            buf.append(context.quoteString(at.getName())).append(' ').append(type);

            // append size and precision (if applicable)
            if (typeSupportsLength(at.getType())) {
                int len = at.getMaxLength();
                int scale = (TypesMapping.isDecimal(at.getType())
                        && at.getType() != Types.FLOAT) // Postgress don't support notations float(a, b)
                        ? at.getScale() : -1;

                // sanity check
                if (scale > len) {
                    scale = -1;
                }

                if (len > 0) {
                    buf.append('(').append(len);

                    if (scale >= 0) {
                        buf.append(", ").append(scale);
                    }

                    buf.append(')');
                }
            }

            if (at.isMandatory()) {
                buf.append(" NOT NULL");
            }
            else {
                buf.append(" NULL");
            }
        }

        // primary key clause
        Iterator<DbAttribute> pkit = ent.getPrimaryKeys().iterator();
        if (pkit.hasNext()) {
            if (first)
                first = false;
            else
                buf.append(", ");

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

                DbAttribute at = pkit.next();
                buf.append(context.quoteString(at.getName()));
            }
            buf.append(')');
        }
        buf.append(')');
        return buf.toString();
View Full Code Here

Examples of org.apache.cayenne.dba.QuotingStrategy

    /**
     * Adds the CASCADE option to the DROP TABLE clause.
     */
    @Override
    public Collection<String> dropTableStatements(DbEntity table) {
        QuotingStrategy context = getQuotingStrategy(table.getDataMap().isQuotingSQLIdentifiers());
        StringBuffer buf = new StringBuffer("DROP TABLE ");
        buf.append(context.quoteFullyQualifiedName(table));           
        buf.append(" CASCADE");
        return Collections.singleton(buf.toString());
    }
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.