Data Layer

MAF Extensibility Framework provides a data adapter interface called MAFDataSourceAdapter. This interface allows the framework to be completely independent from the data provider.

Applications can provide an adapter on top of any kind of data source to map the stored information to objects that the MAF Extensibility Framework can recognize. These objects are known as MAF Generic Business Objects and are interpreted by the MAFGenericBO interface.

Once you have built an MAFCore object with the MAFCoreBuilder, you can set your data source adapter using the setDataSourceAdapter() method of MAFCore.

A data source adapter and a data source library is shipped with the MAF Extensibility Framework. SDMDataSource library is a façade that is built on the standard SDM libraries, which helps consume the APIs of the SDM libraries. SDMDataSourceAdapter converts between SDMODataEntries and MAFGenericBOs.

For a sample data source adapter implementation, see SampleApp_10_CustomDataSource, which uses the Android built in SQLite database as its data source.

To use the SDM Data Source library as your data provider, instantiate the SDMSource class of the library. With the new instance, you can create an MAFSDMDataSourceAdapter instance that you can set to MAFCore as the MAFDataSourceAdapter.

After you set any one of these adapters, or your own implementation of MAFDataSourceAdapter interface for MAFCore, MAFExtensibility Framework is ready to receive and work with the provided data.

	…
        // Initialization of a DataSource that uses built in SQLite database for handling data requests.
        // Initialization of a DB Adapter is not a long-running process so it can be done in the UI thread
        appDataSourceAdapter = new MAFDBDataSourceAdapter(this);
        // add demo data to the DB DataSource
        addTestData(appDataSourceAdapter);
        // let MAF Extensibility to use this DB DataSource Adapter
        mafCoreBuilder.setApplicationDataSourceAdapter(appDataSourceAdapter);
	…

    public static void addTestData(MAFDBDataSource dbSource) {
    	
        //Clear all data from the DB created by previous run of this sample
        dbSource.removeData();

        //Use Database source in Synchron mode (no asynchron simulation is needed)
        dbSource.setDefaultCommunicationMode(CommunicationModeEnum.SYNCHRON);
        
        //Add demo data to the DataSource
        Map<String, String> values = new HashMap<String, String>();

        //Setting the relation (foreign key column name)
        dbSource.addRelation(TITLES_COLLECTION, GENRE_TITLE_RELATION_ID, GENRES_COLLECTION);

        //...for 'Titles' collection...
        
        values.put(NAME_ATTR, "The Shawshank Redemption");
        values.put(RELEASEYEAR_ATTR, "1994");
        dbSource.addDBBO(TITLES_COLLECTION,"shawshank", values);

	…

        values.clear();

        //...and for 'Genres' collection with setting the appropriate relation (foreign key)
        
        values.put(GENRENAME_ATTR, "Drama");
        values.put(GENRE_TITLE_RELATION_ID, "shawshank");
        dbSource.addDBBO(GENRES_COLLECTION,  values);
        
	…

    }