private void validateTable( EntityMeta entityMeta, TableMetadata tableMetadata, PropertyMeta idMeta) { if (idMeta.isEmbeddedId()) { validatePrimaryKeyComponents(tableMetadata, idMeta, true); validatePrimaryKeyComponents(tableMetadata, idMeta, false); } else { validateColumn( tableMetadata, idMeta.getPropertyName().toLowerCase(), idMeta.getValueClassForTableCreation(), idMeta.isIndexed()); } for (PropertyMeta pm : entityMeta.getAllMetasExceptIdAndCounters()) { switch (pm.type()) { case SIMPLE: validateColumn( tableMetadata, pm.getPropertyName().toLowerCase(), pm.getValueClassForTableCreation(), pm.isIndexed()); break; case LIST: case SET: case MAP: validateCollectionAndMapColumn(tableMetadata, pm); break; default: break; } } }
public void loadPropertyIntoObject( PersistenceContext context, Object realObject, PropertyMeta pm) { log.trace("Loading property {} into object {}", pm.getPropertyName(), realObject); PropertyType type = pm.type(); if (type.isCounter()) { counterLoader.loadCounter(context, realObject, pm); } else { Row row = context.loadProperty(pm); mapper.setPropertyToEntity(row, pm, realObject); } }
private void validateCollectionAndMapColumn(TableMetadata tableMetadata, PropertyMeta pm) { log.debug("Validate existing collection/map column {} from table {}"); String columnName = pm.getPropertyName().toLowerCase(); String tableName = tableMetadata.getName(); ColumnMetadata columnMetadata = tableMetadata.getColumn(columnName); Validator.validateTableTrue( columnMetadata != null, "Cannot find column '%s' in the table '%s'", columnName, tableName); Name realType = columnMetadata.getType().getName(); Name expectedValueType = toCQLType(pm.getValueClassForTableCreation()); switch (pm.type()) { case LIST: Validator.validateTableTrue( realType == Name.LIST, "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed", columnName, tableName, realType, Name.LIST); Name realListValueType = columnMetadata.getType().getTypeArguments().get(0).getName(); Validator.validateTableTrue( realListValueType == expectedValueType, "Column '%s' of table '%s' of type 'List<%s>' should be of type 'List<%s>' indeed", columnName, tableName, realListValueType, expectedValueType); break; case SET: Validator.validateTableTrue( realType == Name.SET, "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed", columnName, tableName, realType, Name.SET); Name realSetValueType = columnMetadata.getType().getTypeArguments().get(0).getName(); Validator.validateTableTrue( realSetValueType == expectedValueType, "Column '%s' of table '%s' of type 'Set<%s>' should be of type 'Set<%s>' indeed", columnName, tableName, realSetValueType, expectedValueType); break; case MAP: Validator.validateTableTrue( realType == Name.MAP, "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed", columnName, tableName, realType, Name.MAP); Name expectedMapKeyType = toCQLType(pm.getKeyClass()); Name realMapKeyType = columnMetadata.getType().getTypeArguments().get(0).getName(); Name realMapValueType = columnMetadata.getType().getTypeArguments().get(1).getName(); Validator.validateTableTrue( realMapKeyType == expectedMapKeyType, "Column %s' of table '%s' of type 'Map<%s,?>' should be of type 'Map<%s,?>' indeed", columnName, tableName, realMapKeyType, expectedMapKeyType); Validator.validateTableTrue( realMapValueType == expectedValueType, "Column '%s' of table '%s' of type 'Map<?,%s>' should be of type 'Map<?,%s>' indeed", columnName, tableName, realMapValueType, expectedValueType); break; default: break; } }