Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

JNoSQL/Artemis/Qualifier

Qualifier

That is important to work with more than one type of the same application.

@Inject
private DocumentRepository repositoryA;
@Inject
private DocumentRepository repositoryB;

Two injections with the same interface, CDI throws an ambiguous exception. There is the Database qualifier to fix this problem. It has two attributes:

  • DatabaseType: The database type, key-value, document, column, graph.
  • provider: The provider database name, eg. "cassandra, "hbase", "mongodb". So using the Database qualifier:

Using the Database qualifier, Artemis will take and manager a Repository to each repository type.




@Inject
@Database(value = DatabaseType.DOCUMENT , provider = "databaseA")
private DocumentRepository documentRepositoryA;

@Inject
@Database(value = DatabaseType.DOCUMENT , provider = "databaseB")
private DocumentRepository documentRepositoryB;

@Inject
@Database(value = DatabaseType.COLUMN, provider = "databaseA")
private ColumnRepository columnRepositoryA;

@Inject
@Database(value = DatabaseType.COLUMN, provider = "databaseB")
private ColumnRepository columnRepositoryB;


//producers methods
@Produces
@Database(value = DatabaseType.COLUMN, provider = "databaseA")
public ColumnFamilyManager getColumnFamilyManagerA() {
ColumnFamilyManager manager =//instance
return manager;
}

@Produces
@Database(value = DatabaseType.COLUMN, provider = "databaseB")
public ColumnFamilyManager getColumnFamilyManagerB() {
ColumnFamilyManager manager = //instance
return manager;
}

@Produces
@Database(value = DatabaseType.DOCUMENT, provider = "databaseA")
public DocumentCollectionManager getDocumentCollectionManagerA() {
DocumentCollectionManager manager = //instance
return manager;
}

@Produces
@Database(value = DatabaseType.DOCUMENT, provider = "databaseB")
public DocumentCollectionManager DocumentCollectionManagerB() {
DocumentCollectionManager manager = //instance
return manager;
}


Links

Back to the top