SlideShare a Scribd company logo
package com.example.mycontentprovider; 
import java.util.HashMap; 
import android.content.ContentProvider; 
import android.content.ContentUris; 
import android.content.ContentValues; 
import android.content.Context; 
import android.content.UriMatcher; 
import android.database.Cursor; 
import android.database.SQLException; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteQueryBuilder; 
import android.net.Uri; 
import android.text.TextUtils; 
public class StudentsProvider extends ContentProvider { 
//composition de uri de provider 
static final String PROVIDER_NAME = "com.example.provider"; 
static final String URL = "content://" + PROVIDER_NAME + "/students"; 
static final public Uri CONTENT_URI = Uri.parse(URL); 
static final String _ID = "_id"; 
static final String NAME = "name"; 
static final String GRADE = "grade"; 
private static HashMap<String, String> STUDENTS_PROJECTION_MAP; 
static final int STUDENTS = 1; 
static final int STUDENT_ID = 2; 
//Creates the root node of the URI tree 
static final UriMatcher uriMatcher; 
static{ 
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); 
uriMatcher.addURI(PROVIDER_NAME, "students", STUDENTS); 
uriMatcher.addURI(PROVIDER_NAME, "students/#", STUDENT_ID); 
} 
/** 
* Database specific constant declarations 
*/ 
DatabaseHelper dbHelper ; 
private SQLiteDatabase db; 
// création et ouverture de la base college.db 
@Override 
public boolean onCreate() { 
Context context = getContext(); 
//création de la base college.db 
dbHelper = new DatabaseHelper(context); 
/** 
*open data base to practice the CRUD operations 
*/ 
db = dbHelper.getWritableDatabase(); 
return (db == null)? false:true; 
} 
@Override 
public Uri insert(Uri uri, ContentValues values) {
/** 
* Add a new student record 
*/ 
long rowID = db.insert(dbHelper.STUDENTS_TABLE_NAME, "", values); 
/** 
* If record is added successfully 
*/ 
if (rowID > 0) 
{ 
Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID); 
getContext().getContentResolver().notifyChange(_uri, null); 
return _uri; 
} 
throw new SQLException("Failed to add a record into " + uri); 
} 
@Override 
public Cursor query(Uri uri, String[] projection, String selection, 
String[] selectionArgs, String sortOrder) { 
SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); 
qb.setTables(dbHelper.STUDENTS_TABLE_NAME); 
switch (uriMatcher.match(uri)) { 
case STUDENTS: 
qb.setProjectionMap(STUDENTS_PROJECTION_MAP); 
break; 
case STUDENT_ID: 
qb.appendWhere( _ID + "=" + uri.getPathSegments().get(1)); 
break; 
default: 
throw new IllegalArgumentException("Unknown URI " + uri); 
} 
if (sortOrder == null || sortOrder == ""){ 
/** 
* By default sort on student names 
*/ 
sortOrder = NAME; 
} 
Cursor c = qb.query(db, projection, selection, selectionArgs, 
null, null, sortOrder); 
/** 
* register to watch a content URI for changes 
*/ 
c.setNotificationUri(getContext().getContentResolver(), uri); 
return c; 
} 
@Override 
public int delete(Uri uri, String selection, String[] selectionArgs) { 
int count = 0; 
switch (uriMatcher.match(uri)){ 
case STUDENTS: 
count = db.delete(dbHelper.STUDENTS_TABLE_NAME, selection, 
selectionArgs); 
break; 
case STUDENT_ID: 
String id = uri.getPathSegments().get(1); 
count = db.delete( dbHelper.STUDENTS_TABLE_NAME, _ID + " = " + id + 
(!TextUtils.isEmpty(selection) ? " AND (" + 
selection + ')' : ""), selectionArgs); 
break;
default: 
throw new IllegalArgumentException("Unknown URI " + uri); 
} 
getContext().getContentResolver().notifyChange(uri, null); 
return count; 
} 
@Override 
public int update(Uri uri, ContentValues values, String selection, 
String[] selectionArgs) { 
int count = 0; 
switch (uriMatcher.match(uri)){ 
case STUDENTS: 
count = db.update(dbHelper.STUDENTS_TABLE_NAME, values, 
selection, selectionArgs); 
break; 
case STUDENT_ID: 
count = db.update(dbHelper.STUDENTS_TABLE_NAME, values, _ID + 
" = " + uri.getPathSegments().get(1) + 
(!TextUtils.isEmpty(selection) ? " AND (" + 
selection + ')' : ""), selectionArgs); 
break; 
default: 
throw new IllegalArgumentException("Unknown URI " + uri ); 
} 
getContext().getContentResolver().notifyChange(uri, null); 
return count; 
} 
@Override 
public String getType(Uri uri) { 
switch (uriMatcher.match(uri)){ 
/** 
* Get all student records 
*/ 
case STUDENTS: 
return "vnd.android.cursor.dir/vnd.example.students"; 
/** 
* Get a particular student 
*/ 
case STUDENT_ID: 
return "vnd.android.cursor.item/vnd.example.students"; 
default: 
throw new IllegalArgumentException("Unsupported URI: " + uri); 
} 
} 
}

More Related Content

What's hot

Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
Jackson Tian
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
philogb
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
Senten500.c
Senten500.cSenten500.c
Senten500.c
albertinous
 
Viastudy ef core_cheat_sheet
Viastudy ef core_cheat_sheetViastudy ef core_cheat_sheet
Viastudy ef core_cheat_sheet
imdurgesh
 
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Formacion en movilidad: Conceptos de desarrollo en iOS (IV) Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Mobivery
 
When cqrs meets event sourcing
When cqrs meets event sourcingWhen cqrs meets event sourcing
When cqrs meets event sourcing
Manel Sellés
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩
GDG Korea
 
662305 09
662305 09662305 09
Simplifying JavaScript Projects with ReactJS
Simplifying JavaScript Projects with ReactJSSimplifying JavaScript Projects with ReactJS
Simplifying JavaScript Projects with ReactJS
Kevin Dangoor
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
Amit Ghosh
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
Denis Ristic
 
Func dyn statement_set.c
Func dyn statement_set.cFunc dyn statement_set.c
Func dyn statement_set.c
albertinous
 
jQuery Datatables With MongDb
jQuery Datatables With MongDbjQuery Datatables With MongDb
jQuery Datatables With MongDb
sliimohara
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
saydin_soft
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
Alex Hardman
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
Bruce McPherson
 
Hack tutorial
Hack tutorialHack tutorial
Hack tutorial
Wakana Yoshizawa
 
JavaScript Performance 20160723
JavaScript Performance 20160723JavaScript Performance 20160723
JavaScript Performance 20160723
kamiyam .
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Lorna Mitchell
 

What's hot (20)

Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
 
Senten500.c
Senten500.cSenten500.c
Senten500.c
 
Viastudy ef core_cheat_sheet
Viastudy ef core_cheat_sheetViastudy ef core_cheat_sheet
Viastudy ef core_cheat_sheet
 
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Formacion en movilidad: Conceptos de desarrollo en iOS (IV) Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
 
When cqrs meets event sourcing
When cqrs meets event sourcingWhen cqrs meets event sourcing
When cqrs meets event sourcing
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩
 
662305 09
662305 09662305 09
662305 09
 
Simplifying JavaScript Projects with ReactJS
Simplifying JavaScript Projects with ReactJSSimplifying JavaScript Projects with ReactJS
Simplifying JavaScript Projects with ReactJS
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
 
Func dyn statement_set.c
Func dyn statement_set.cFunc dyn statement_set.c
Func dyn statement_set.c
 
jQuery Datatables With MongDb
jQuery Datatables With MongDbjQuery Datatables With MongDb
jQuery Datatables With MongDb
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
 
Hack tutorial
Hack tutorialHack tutorial
Hack tutorial
 
JavaScript Performance 20160723
JavaScript Performance 20160723JavaScript Performance 20160723
JavaScript Performance 20160723
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 

Similar to F3

CDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptor
Caelum
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java script
Ürgo Ringo
 
Testdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinnerTestdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinner
Truls Jørgensen
 
The Principle of Hybrid App.
The Principle of Hybrid App.The Principle of Hybrid App.
The Principle of Hybrid App.
musart Park
 
F1
F1F1
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
 
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
Fukaya Akifumi
 
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
DeNA
 
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
DeNA
 
F2
F2F2
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Android dev toolbox
Android dev toolboxAndroid dev toolbox
Android dev toolbox
Shem Magnezi
 
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docxDAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
theodorelove43763
 
Jsr 303
Jsr 303Jsr 303
Modul Praktek Java OOP
Modul Praktek Java OOP Modul Praktek Java OOP
Modul Praktek Java OOP
Zaenal Arifin
 
Introduction to Java Programming 10th ed --25-4 (Implement preorder t.docx
Introduction to Java Programming 10th ed  --25-4 (Implement preorder t.docxIntroduction to Java Programming 10th ed  --25-4 (Implement preorder t.docx
Introduction to Java Programming 10th ed --25-4 (Implement preorder t.docx
diegor62
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
Chris Weldon
 
Practical Model View Programming (Roadshow Version)
Practical Model View Programming (Roadshow Version)Practical Model View Programming (Roadshow Version)
Practical Model View Programming (Roadshow Version)
Marius Bugge Monsen
 
MVM - It's all in the (Implementation) Details
MVM - It's all in the (Implementation) DetailsMVM - It's all in the (Implementation) Details
MVM - It's all in the (Implementation) Details
Florina Muntenescu
 

Similar to F3 (20)

CDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptor
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java script
 
Testdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinnerTestdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinner
 
The Principle of Hybrid App.
The Principle of Hybrid App.The Principle of Hybrid App.
The Principle of Hybrid App.
 
F1
F1F1
F1
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
ヘルスケアサービスを実現する最新技術
〜HealthKit・GCP+Go〜
 
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
 
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
 
F2
F2F2
F2
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Android dev toolbox
Android dev toolboxAndroid dev toolbox
Android dev toolbox
 
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docxDAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
 
Jsr 303
Jsr 303Jsr 303
Jsr 303
 
Modul Praktek Java OOP
Modul Praktek Java OOP Modul Praktek Java OOP
Modul Praktek Java OOP
 
Introduction to Java Programming 10th ed --25-4 (Implement preorder t.docx
Introduction to Java Programming 10th ed  --25-4 (Implement preorder t.docxIntroduction to Java Programming 10th ed  --25-4 (Implement preorder t.docx
Introduction to Java Programming 10th ed --25-4 (Implement preorder t.docx
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Practical Model View Programming (Roadshow Version)
Practical Model View Programming (Roadshow Version)Practical Model View Programming (Roadshow Version)
Practical Model View Programming (Roadshow Version)
 
MVM - It's all in the (Implementation) Details
MVM - It's all in the (Implementation) DetailsMVM - It's all in the (Implementation) Details
MVM - It's all in the (Implementation) Details
 

More from Saber LAJILI

Cours android user_interface_2016
Cours android user_interface_2016Cours android user_interface_2016
Cours android user_interface_2016
Saber LAJILI
 
Cours android 2016
Cours android 2016Cours android 2016
Cours android 2016
Saber LAJILI
 
Les ateliers android_1_vers2015
Les ateliers android_1_vers2015Les ateliers android_1_vers2015
Les ateliers android_1_vers2015
Saber LAJILI
 
4 asynch task_services_thread
4 asynch task_services_thread4 asynch task_services_thread
4 asynch task_services_thread
Saber LAJILI
 
Accueil.java
Accueil.javaAccueil.java
Accueil.java
Saber LAJILI
 
Activity accueil
Activity accueilActivity accueil
Activity accueil
Saber LAJILI
 
Main.xml
Main.xmlMain.xml
Main.xml
Saber LAJILI
 
Liste exposés université privée leaders
Liste exposés université privée leadersListe exposés université privée leaders
Liste exposés université privée leaders
Saber LAJILI
 
1 tours horizon
1 tours horizon1 tours horizon
1 tours horizon
Saber LAJILI
 
5 android web_service
5 android web_service5 android web_service
5 android web_service
Saber LAJILI
 
Exemple de création de base
Exemple de création de baseExemple de création de base
Exemple de création de base
Saber LAJILI
 
Mini projet android 2014 2015 iset nabeul sem3
Mini projet android 2014 2015 iset nabeul sem3Mini projet android 2014 2015 iset nabeul sem3
Mini projet android 2014 2015 iset nabeul sem3
Saber LAJILI
 
Les capteurs sous android
Les capteurs sous androidLes capteurs sous android
Les capteurs sous android
Saber LAJILI
 
3 shared preference_sq_lite
3 shared preference_sq_lite3 shared preference_sq_lite
3 shared preference_sq_lite
Saber LAJILI
 
4 asynch task_services_thread
4 asynch task_services_thread4 asynch task_services_thread
4 asynch task_services_thread
Saber LAJILI
 
2 activity user_interface
2 activity user_interface2 activity user_interface
2 activity user_interfaceSaber LAJILI
 

More from Saber LAJILI (16)

Cours android user_interface_2016
Cours android user_interface_2016Cours android user_interface_2016
Cours android user_interface_2016
 
Cours android 2016
Cours android 2016Cours android 2016
Cours android 2016
 
Les ateliers android_1_vers2015
Les ateliers android_1_vers2015Les ateliers android_1_vers2015
Les ateliers android_1_vers2015
 
4 asynch task_services_thread
4 asynch task_services_thread4 asynch task_services_thread
4 asynch task_services_thread
 
Accueil.java
Accueil.javaAccueil.java
Accueil.java
 
Activity accueil
Activity accueilActivity accueil
Activity accueil
 
Main.xml
Main.xmlMain.xml
Main.xml
 
Liste exposés université privée leaders
Liste exposés université privée leadersListe exposés université privée leaders
Liste exposés université privée leaders
 
1 tours horizon
1 tours horizon1 tours horizon
1 tours horizon
 
5 android web_service
5 android web_service5 android web_service
5 android web_service
 
Exemple de création de base
Exemple de création de baseExemple de création de base
Exemple de création de base
 
Mini projet android 2014 2015 iset nabeul sem3
Mini projet android 2014 2015 iset nabeul sem3Mini projet android 2014 2015 iset nabeul sem3
Mini projet android 2014 2015 iset nabeul sem3
 
Les capteurs sous android
Les capteurs sous androidLes capteurs sous android
Les capteurs sous android
 
3 shared preference_sq_lite
3 shared preference_sq_lite3 shared preference_sq_lite
3 shared preference_sq_lite
 
4 asynch task_services_thread
4 asynch task_services_thread4 asynch task_services_thread
4 asynch task_services_thread
 
2 activity user_interface
2 activity user_interface2 activity user_interface
2 activity user_interface
 

Recently uploaded

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 

Recently uploaded (20)

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 

F3

  • 1. package com.example.mycontentprovider; import java.util.HashMap; import android.content.ContentProvider; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.UriMatcher; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri; import android.text.TextUtils; public class StudentsProvider extends ContentProvider { //composition de uri de provider static final String PROVIDER_NAME = "com.example.provider"; static final String URL = "content://" + PROVIDER_NAME + "/students"; static final public Uri CONTENT_URI = Uri.parse(URL); static final String _ID = "_id"; static final String NAME = "name"; static final String GRADE = "grade"; private static HashMap<String, String> STUDENTS_PROJECTION_MAP; static final int STUDENTS = 1; static final int STUDENT_ID = 2; //Creates the root node of the URI tree static final UriMatcher uriMatcher; static{ uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher.addURI(PROVIDER_NAME, "students", STUDENTS); uriMatcher.addURI(PROVIDER_NAME, "students/#", STUDENT_ID); } /** * Database specific constant declarations */ DatabaseHelper dbHelper ; private SQLiteDatabase db; // création et ouverture de la base college.db @Override public boolean onCreate() { Context context = getContext(); //création de la base college.db dbHelper = new DatabaseHelper(context); /** *open data base to practice the CRUD operations */ db = dbHelper.getWritableDatabase(); return (db == null)? false:true; } @Override public Uri insert(Uri uri, ContentValues values) {
  • 2. /** * Add a new student record */ long rowID = db.insert(dbHelper.STUDENTS_TABLE_NAME, "", values); /** * If record is added successfully */ if (rowID > 0) { Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID); getContext().getContentResolver().notifyChange(_uri, null); return _uri; } throw new SQLException("Failed to add a record into " + uri); } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(dbHelper.STUDENTS_TABLE_NAME); switch (uriMatcher.match(uri)) { case STUDENTS: qb.setProjectionMap(STUDENTS_PROJECTION_MAP); break; case STUDENT_ID: qb.appendWhere( _ID + "=" + uri.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } if (sortOrder == null || sortOrder == ""){ /** * By default sort on student names */ sortOrder = NAME; } Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); /** * register to watch a content URI for changes */ c.setNotificationUri(getContext().getContentResolver(), uri); return c; } @Override public int delete(Uri uri, String selection, String[] selectionArgs) { int count = 0; switch (uriMatcher.match(uri)){ case STUDENTS: count = db.delete(dbHelper.STUDENTS_TABLE_NAME, selection, selectionArgs); break; case STUDENT_ID: String id = uri.getPathSegments().get(1); count = db.delete( dbHelper.STUDENTS_TABLE_NAME, _ID + " = " + id + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs); break;
  • 3. default: throw new IllegalArgumentException("Unknown URI " + uri); } getContext().getContentResolver().notifyChange(uri, null); return count; } @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { int count = 0; switch (uriMatcher.match(uri)){ case STUDENTS: count = db.update(dbHelper.STUDENTS_TABLE_NAME, values, selection, selectionArgs); break; case STUDENT_ID: count = db.update(dbHelper.STUDENTS_TABLE_NAME, values, _ID + " = " + uri.getPathSegments().get(1) + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs); break; default: throw new IllegalArgumentException("Unknown URI " + uri ); } getContext().getContentResolver().notifyChange(uri, null); return count; } @Override public String getType(Uri uri) { switch (uriMatcher.match(uri)){ /** * Get all student records */ case STUDENTS: return "vnd.android.cursor.dir/vnd.example.students"; /** * Get a particular student */ case STUDENT_ID: return "vnd.android.cursor.item/vnd.example.students"; default: throw new IllegalArgumentException("Unsupported URI: " + uri); } } }