Created
July 31, 2014 13:30
-
-
Save sizovs/aed5d4e225aebe1e0918 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Retention(RetentionPolicy.RUNTIME) | |
@Target([ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER]) | |
@BindingAnnotation | |
@AutoBind | |
@interface MySQL { | |
String databaseName() | |
} | |
@Immutable | |
class MySQLImpl implements MySQL { | |
final String databaseName | |
String databaseName() { | |
databaseName | |
} | |
// This is specified in java.lang.Annotation. | |
int hashCode() { | |
(127 * "databaseName".hashCode()) ^ databaseName.hashCode() | |
} | |
class<? extends Annotation> annotationType() { | |
MySQL | |
} | |
} | |
class MySQLAutoBindProvider implements AutoBindProvider<MySQL> { | |
public void configure(Binder binder, MySQL annotation) { | |
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/${annotation.databaseName()}?user=admin&password=d0cker") | |
binder.bind(Sql).annotatedWith(new MySQLImpl(annotation.databaseName())).toInstance(sql) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment