public String getMaxLength(DbAttribute attr) { return (attr.getMaxLength() >= 0) ? String.valueOf(attr.getMaxLength()) : ""; }
@Override public List<String> createSql(DbAdapter adapter) { List<String> sqls = new ArrayList<>(); if (columnOriginal.getMaxLength() != columnNew.getMaxLength()) { sqls.add("ALTER TABLE " + entity.getFullyQualifiedName() + " COLUMN " + columnNew.getName() + " SET LENGTH " + columnNew.getMaxLength()); } return sqls; }
/** * Returns this attribute's maximum allowed length * * @see DbAttribute#getMaxLength() */ public int getMaxLength() { DbAttribute dbAttribute = getDbAttribute(); return dbAttribute == null ? -1 : dbAttribute.getMaxLength(); }
if (dbAttribute.getMaxLength() <= 0) { return true; if (bytes.length > dbAttribute.getMaxLength()) { String message = "\"" + property + "\" exceeds maximum allowed length (" + dbAttribute.getMaxLength() + " bytes): " + bytes.length;
if (dbAttribute.getMaxLength() <= 0) { return true; if (string.length() > dbAttribute.getMaxLength()) { String message = "\"" + property + "\" exceeds maximum allowed length (" + dbAttribute.getMaxLength() + " chars): " + string.length();
/** * @return a binary PK if DbEntity has a BINARY or VARBINARY pk, null otherwise. This * method will likely be deprecated in 1.1 in favor of a more generic * soultion. * @since 1.0.2 */ protected byte[] binaryPK(DbEntity entity) { List pkColumns = entity.getPrimaryKey(); if (pkColumns.size() == 1) { DbAttribute pk = (DbAttribute) pkColumns.get(0); if (pk.getMaxLength() > 0 && (pk.getType() == Types.BINARY || pk.getType() == Types.VARBINARY)) { return IDUtil.pseudoUniqueSecureByteSequence(pk.getMaxLength()); } } return null; }
@Override public List<String> createSql(DbAdapter adapter) { StringBuilder sqlBuffer = new StringBuilder(); QuotingStrategy context = adapter.getQuotingStrategy(); sqlBuffer.append("ALTER TABLE "); sqlBuffer.append(context.quotedFullyQualifiedName(getEntity())); sqlBuffer.append(" ALTER COLUMN "); sqlBuffer.append(context.quotedName(getColumn())); sqlBuffer.append(" "); sqlBuffer.append(adapter.externalTypesForJdbcType(getColumn().getType())[0]); if (adapter.typeSupportsLength(getColumn().getType()) && getColumn().getMaxLength() > 0) { sqlBuffer.append("("); sqlBuffer.append(getColumn().getMaxLength()); sqlBuffer.append(")"); } sqlBuffer.append(" WITH NULL"); return Collections.singletonList(sqlBuffer.toString()); }
@Override public List<String> createSql(DbAdapter adapter) { /* * TODO: we generate this query as in ingres db documentation, * but unfortunately ingres don't support it */ StringBuilder sqlBuffer = new StringBuilder(); QuotingStrategy context = adapter.getQuotingStrategy(); sqlBuffer.append("ALTER TABLE "); sqlBuffer.append(getEntity().getFullyQualifiedName()); sqlBuffer.append(" ALTER COLUMN "); sqlBuffer.append(context.quotedName(getColumn())); sqlBuffer.append(" "); sqlBuffer.append(adapter.externalTypesForJdbcType(getColumn().getType())[0]); if (adapter.typeSupportsLength(getColumn().getType()) && getColumn().getMaxLength() > 0) { sqlBuffer.append("("); sqlBuffer.append(getColumn().getMaxLength()); sqlBuffer.append(")"); } sqlBuffer.append(" NOT NULL"); return Collections.singletonList(sqlBuffer.toString()); }
if (columnOriginal.getMaxLength() != columnNew.getMaxLength()) { sb.append(" maxLength: "); sb.append(columnOriginal.getMaxLength()); sb.append(" -> "); sb.append(columnNew.getMaxLength());
if (columnOriginal.getMaxLength() != columnNew.getMaxLength()) { sb.append(" maxLength: "); sb.append(columnOriginal.getMaxLength()); sb.append(" -> "); sb.append(columnNew.getMaxLength());
@Override public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { // CAY-1095: if the column is type double, temporarily set the max // length to 0 to // avoid adding precision information. if (column.getType() == Types.DOUBLE && column.getMaxLength() > 0) { int len = column.getMaxLength(); column.setMaxLength(0); super.createTableAppendColumn(sqlBuffer, column); column.setMaxLength(len); } else { super.createTableAppendColumn(sqlBuffer, column); } if(column.isGenerated()) { sqlBuffer.append(" GENERATED BY DEFAULT AS IDENTITY (START WITH 1)"); } } }
int len = at.getMaxLength(); int scale = TypesMapping.isDecimal(at.getType()) ? at.getScale() : -1;
/** * Returns a non-repeating primary key for a given PK attribute. Since * OpenBase-specific mechanism is used, key caching is disabled. Instead a * database operation is performed on every call. * * @since 3.0 */ @Override public Object generatePk(DataNode node, DbAttribute pk) throws Exception { DbEntity entity = pk.getEntity(); switch (pk.getType()) { case Types.BINARY: case Types.VARBINARY: return IDUtil.pseudoUniqueSecureByteSequence(pk.getMaxLength()); } long value = longPkFromDatabase(node, entity); if (pk.getType() == Types.BIGINT) { return value; } else { // leaving it up to the user to ensure that PK does not exceed max // int... return (int) value; } }
public static String sizeAndPrecision(DbAdapter adapter, DbAttribute column) { if (!adapter.typeSupportsLength(column.getType())) { return ""; } int len = column.getMaxLength(); int scale = TypesMapping.isDecimal(column.getType()) && column.getType() != Types.FLOAT ? column.getScale() : -1; // sanity check if (scale > len) { scale = -1; } if (len > 0) { return "(" + len + (scale >= 0 ? ", " + scale : "") + ")"; } return ""; }
if(original.getMaxLength() != imported.getMaxLength()) { int[] typesWithMaxLength = {Types.NCHAR, Types.NVARCHAR, Types.CHAR, Types.VARCHAR}; for(int type : typesWithMaxLength) {
@Override public ObjAttribute getClientAttribute() { ClientObjAttribute attribute = new ClientObjAttribute(getName()); attribute.setType(getType()); // unconditionally expose DbAttribute path and configure as mandatory. attribute.setDbAttributePath(dbAttributePath); attribute.setMandatory(true); DbAttribute dbAttribute = getDbAttribute(); if (dbAttribute != null) { attribute.setMaxLength(dbAttribute.getMaxLength()); } // TODO: will likely need "userForLocking" property as well. return attribute; }
@Override public void execute(MergerContext mergerContext) { columnOriginal.setType(columnNew.getType()); columnOriginal.setMaxLength(columnNew.getMaxLength()); columnOriginal.setAttributePrecision(columnNew.getAttributePrecision()); columnOriginal.setScale(columnNew.getScale()); mergerContext.getDelegate().dbAttributeModified(columnOriginal); }
/** * Creates a ColumnDescriptor from Cayenne DbAttribute. * * @since 1.2 */ public ColumnDescriptor(DbAttribute attribute, String columnAlias) { this.name = attribute.getName(); this.qualifiedColumnName = attribute.getAliasedName(columnAlias); this.label = name; this.jdbcType = attribute.getType(); this.primaryKey = attribute.isPrimaryKey(); this.javaClass = getDefaultJavaClass(attribute.getMaxLength(), attribute .getPrecision()); if (attribute.getEntity() != null) { this.tableName = attribute.getEntity().getName(); } }
/** * Creates and initializes a derived attribute with an attribute of a parent entity. */ public DerivedDbAttribute(DbEntity entity, DbAttribute parentProto) { setName(parentProto.getName()); setType(parentProto.getType()); setMandatory(parentProto.isMandatory()); setMaxLength(parentProto.getMaxLength()); setPrecision(parentProto.getPrecision()); setPrimaryKey(parentProto.isPrimaryKey()); setExpressionSpec(ATTRIBUTE_TOKEN); addParam(parentProto); setEntity(entity); }
else if (attribute.getMaxLength() < 0 && (attribute.getType() == java.sql.Types.VARCHAR || attribute.getType() == java.sql.Types.NVARCHAR