constraints

Variable field in a constraint annotation

不打扰是莪最后的温柔 提交于 2019-11-29 02:39:54
问题 I need to create a custom constraint annotation which can access the value of another field of my bean. I'll use this annotation to validate the field because it depends on the value of the other but the way I define it the compiler says "The value for annotation attribute" of my field "must be a constant expression". I've defined it in this way: @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy=EqualsFieldValidator.class) @Documented public @interface

C# Generic constraints to include value types AND strings

ぃ、小莉子 提交于 2019-11-29 02:06:55
问题 I'm trying to write an extension method on IEnumerable that will only apply to value types and strings. public static string MyMethod<T>(this IEnumerable<T> source) where T : struct, string However 'string' is not a valid constraint as it is a sealed class. Is there any way to do this? Edit: What I'm actually trying to do is prepare a list of values for an "IN" clause in a dynamically constructed SQL. I have lots of instances of code such as the following that I want to clean up: sb

Strange UIView-Encapsulated-Layout-Height Error

*爱你&永不变心* 提交于 2019-11-29 00:56:16
I'm making test application, so in my tableviewCell in storyboard i have imageView & webView (for show html-text). I set constraints like top/left/right/height=200 for imageView, spacing=5 between them & left/right/bot for webView, so i want to calculate my webView height programmatically and then change cell's heigt to stretch my webView. But i got this : Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that

Fire trigger on update of columnA or ColumnB or ColumnC

大憨熊 提交于 2019-11-29 00:32:20
问题 I have the code to fire a trigger only on an update of a single specific column. The trigger is used to fire a function that will raise a postgres "notify" event, which I am listening for and will need to test and validate the newly input details. There are many values on the account_details table which could be change which do not require an account validate, so a trigger on AFTER UPDATE only (without a when) is no good. CREATE TRIGGER trigger_update_account_details AFTER UPDATE ON account

Change height constraint programmatically

你。 提交于 2019-11-28 22:37:31
I want to change the height constraint of a UITextView programmatically so I set the constraint as an outlet in my controller like this: @property (strong, nonatomic) IBOutlet NSLayoutConstraint *descriptionHeightConstraint; To change it I do the following: self.descriptionHeightConstraint.constant = self.description.contentSize.height; This works if I do it in viewDidAppear but the problem with this is that I can see how the height changes after the view displayed which is not very user friendly so I tried doing it in viewWillAppear but didn't work there, the height doesn't change. Calling

How to set constraints on generic types in Java?

大城市里の小女人 提交于 2019-11-28 22:25:18
I have a generic class: public class ListObject<T> { // fields protected T _Value = null; // .. } Now I want to do something like the following: ListObject<MyClass> foo = new ListObject<MyClass>(); ListObject<MyClass> foo2 = new ListObject<MyClass>(); foo.compareTo(foo2); Question: How can I define the compareTo() method with resprect to the generic T ? I guess I have to somehow implement a constraint on the generic T , to tell that T implements a specific interface (maybe Comparable , if that one exists). Can anyone provide me with a small code sample? nanda Read also the discussion here:

Entity Framework: How to properly handle exceptions that occur due to SQL constraints

巧了我就是萌 提交于 2019-11-28 21:22:24
I use Entity Framework to access my SQL data. I have some constraints in the database schema and I wonder how to handle exceptions that are caused by these constraints. As example, I get the following exception in a case where two users try to add an (almost) identical entity to the DB concurrently. System.Data.UpdateException "An error occurred while updating the entries. See the InnerException for details." (inner exception) System.Data.SqlClient.SqlException "Violation of UNIQUE KEY constraint 'Unique_GiftId'. Cannot insert duplicate key in object 'dbo.Donations'.\r\nThe statement has been

Does SQL Server allow constraint violations in a transaction as long as it's not committed yet?

删除回忆录丶 提交于 2019-11-28 21:06:24
Does SQL Server allow constraint violations (i.e. deferred constraints) in a transaction as long as the transaction has not been committed yet? I have a running, uncommitted transaction and while this transaction is running, I will change my data so that it will violate some constraints (like having duplicate primary keys for example). When I commit the transaction, the data will be in consistent, valid state. Is this generally allowed in SQL and specifically in MS SQL Server? gbn No, sorry. SQL Server does not allow deferred contraints in a transaction. It was present in SQL Server 6.5, but

ASP.net MVC custom route handler/constraint

我怕爱的太早我们不能终老 提交于 2019-11-28 20:46:39
I need to implement an MVC site with urls per below: category1/product/1/wiki category1/product/2/wiki category1/sub-category2/product/3/wiki category1/sub-category2/sub-category3/product/4/wiki etc. etc. where the matching criteria is that the url ends with "wiki". Unfortunately the below catch-all works only in the last part of the url: routes.MapRoute("page1", // Route name "{*path}/wiki", // URL with parameters new { controller = "Wiki", action = "page", version = "" } // Parameter defaults I have not had the time to go through the MVC extensibility options so I was wondering what are the

T-SQL: How do I create a unique key that is case sensitive?

喜欢而已 提交于 2019-11-28 19:08:15
How do I create a unique constraint on a varchar field that is case sensitive (SQL Server 2005)? Currently my constraint looks like this: alter table MyTable add constraint UK_MyTable_MyUniqueKey unique nonclustered (MyCol) When I try to insert the following two values, I get a "Violation of UNIQUE KEY constraint..." error. insert into MyTable (MyCol) values ('ABC') insert into MyTable (MyCol) values ('abc') --causes a violation of UNIQUE KEY constraint 'UK_MyTable_MyUnqiueKey' I would like the two differently-cased values to be handled as unqiue. I imagine it will involve the following code,