public Boolean isMandatory(DbAttribute attr) { return (attr.isMandatory()) ? Boolean.TRUE : Boolean.FALSE; }
/** * Returns whether this attribute is mandatory * * @see DbAttribute#isMandatory() */ public boolean isMandatory() { DbAttribute dbAttribute = getDbAttribute(); return dbAttribute == null ? false : dbAttribute.isMandatory(); }
@Override public boolean isMandatory() { return objAttribute.getDbAttribute().isMandatory(); }
/** * This method tries to find mandatory PK attribute, if no such exists returns first PK attribute. * Used to translate COUNT(entity) expressions into COUNT(alias.pk_column). */ private DbAttribute getPk(DbEntity dbEntity) { for(DbAttribute attribute : dbEntity.getPrimaryKeys()) { if(attribute.isMandatory()) { return attribute; } } return dbEntity.getPrimaryKeys().iterator().next(); }
/** * Appends SQL for column creation to CREATE TABLE buffer. * * @since 1.2 */ @Override public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { sqlBuffer.append(quotingStrategy.quotedName(column)); sqlBuffer.append(' ').append(getType(this, column)); sqlBuffer.append(sizeAndPrecision(this, column)); sqlBuffer.append(column.isMandatory() ? " NOT NULL" : " NULL"); }
@Override public boolean isMandatory() { for (DbJoin join : getJoins()) { if (join.getSource().isMandatory()) { return true; } } return false; }
private void checkMandatory(DbAttribute original, DbAttribute imported, List<MergerToken> tokens) { if(original.isMandatory() == imported.isMandatory()) { return; } DbEntity originalDbEntity = original.getEntity(); if (original.isMandatory()) { if (valueForNull.hasValueFor(originalDbEntity, original)) { tokens.add(getTokenFactory().createSetValueForNullToDb(originalDbEntity, original, valueForNull)); } tokens.add(getTokenFactory().createSetNotNullToDb(originalDbEntity, original)); } else { tokens.add(getTokenFactory().createSetAllowNullToDb(originalDbEntity, original)); } }
@Override public List<String> createSql(DbAdapter adapter) { StringBuffer sqlBuffer = new StringBuffer(); QuotingStrategy context = adapter.getQuotingStrategy(); sqlBuffer.append("ALTER TABLE "); sqlBuffer.append(context.quotedFullyQualifiedName(getEntity())); sqlBuffer.append(" ADD "); boolean magnatory = column.isMandatory(); column.setMandatory(false); adapter.createTableAppendColumn(sqlBuffer, column); if(magnatory){ column.setMandatory(magnatory); } return Collections.singletonList(sqlBuffer.toString()); }
/** * Helper method for ExtendedType implementors to check for null required values. * * @since 1.2 */ public static boolean validateNull( Object source, String property, Object value, DbAttribute dbAttribute, ValidationResult validationResult) { if (dbAttribute.isMandatory() && value == null) { validationResult.addFailure(new BeanValidationFailure(source, property, "'" + property + "' must be not null")); return false; } return true; }
public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { String[] types = externalTypesForJdbcType(column.getType()); if (types == null || types.length == 0) { String entityName = column.getEntity() != null ? column.getEntity().getFullyQualifiedName() : "<null>"; throw new CayenneRuntimeException("Undefined type for attribute '%s.%s': %s" , entityName, column.getName(), column.getType()); } sqlBuffer.append(quotingStrategy.quotedName(column)); sqlBuffer.append(' '); String type = types[0]; String length = sizeAndPrecision(this, column); int suffixIndex = type.indexOf(NCHAR_SUFFIX); if (!length.isEmpty() && suffixIndex > 0) { sqlBuffer.append(type.substring(0, suffixIndex)).append(length).append(NCHAR_SUFFIX); } else { sqlBuffer.append(type).append(" ").append(length); } sqlBuffer.append(column.isMandatory() ? " NOT NULL" : ""); }
if (column.isMandatory()) { sqlBuffer.append(" NOT NULL");
if (column.isMandatory()) { sqlBuffer.append(" NOT NULL");
private void createAttribute(DbEntity ent, QuotingStrategy context, StringBuilder buf, DbAttribute at) { // attribute may not be fully valid, do a simple check if (at.getType() == TypesMapping.NOT_DEFINED) { throw new CayenneRuntimeException("Undefined type for attribute '%s.%s'" , ent.getFullyQualifiedName(), at.getName()); } String[] types = externalTypesForJdbcType(at.getType()); if (types == null || types.length == 0) { throw new CayenneRuntimeException("Undefined type for attribute '%s.%s': %s" , ent.getFullyQualifiedName(), at.getName(), at.getType()); } // Checking that attribute is generated and we have alternative types in types.xml. // If so, use those autoincremented types. For example serial, bigserial, smallserial. String type = (at.isGenerated() && types.length > 1) ? types[1] : types[0]; buf.append(context.quotedName(at)).append(' ').append(type).append(sizeAndPrecision(this, at)) .append(at.isMandatory() ? " NOT" : "").append(" NULL"); }
/** * Add column to db * @param original attribute found in model but missing in db */ @Override Collection<MergerToken> createTokensForMissingImported(DbAttribute original) { DbEntity originalDbEntity = original.getEntity(); List<MergerToken> tokens = new LinkedList<>(); tokens.add(getTokenFactory().createAddColumnToDb(originalDbEntity, original)); // Create not null check if (original.isMandatory()) { if (valueForNull.hasValueFor(originalDbEntity, original)) { tokens.add(getTokenFactory().createSetValueForNullToDb(originalDbEntity, original, valueForNull)); } tokens.add(getTokenFactory().createSetNotNullToDb(originalDbEntity, original)); } if(original.isPrimaryKey() && originalDbEntity instanceof DetectedDbEntity && "VIEW".equals(((DetectedDbEntity) originalDbEntity).getType())) { // Views doesn't has PKs in a database, but if the user selects some PKs in a model, we put these keys. return null; } return tokens; }
if (at.isMandatory()) { buf.append(" NOT NULL");
sqlBuffer.append(column.isMandatory() ? " NOT NULL" : " NULL");
sqlBuffer.append(column.isMandatory() ? " NOT NULL" : " NULL");
/** * 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); }
if (isMandatory()) { encoder.print(" isMandatory=\"true\"");
if (isMandatory()) { encoder.print(" isMandatory=\"true\"");