mirror of https://github.com/kurisufriend/Clover
parent
adc6cb0d52
commit
373f7f5e17
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,42 @@ |
|||||||
|
package org.floens.chan.database; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
import org.floens.chan.model.Loadable; |
||||||
|
import org.floens.chan.model.Pin; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import android.database.sqlite.SQLiteDatabase; |
||||||
|
|
||||||
|
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; |
||||||
|
import com.j256.ormlite.dao.Dao; |
||||||
|
import com.j256.ormlite.support.ConnectionSource; |
||||||
|
|
||||||
|
public class DatabaseHelper extends OrmLiteSqliteOpenHelper { |
||||||
|
private static final String DATABASE_NAME = "ChanDB"; |
||||||
|
private static final int DATABASE_VERSION = 1; |
||||||
|
|
||||||
|
public Dao<Pin, Integer> pinDao; |
||||||
|
public Dao<Loadable, Integer> loadableDao; |
||||||
|
|
||||||
|
public DatabaseHelper(Context context) { |
||||||
|
super(context, DATABASE_NAME, null, DATABASE_VERSION); |
||||||
|
|
||||||
|
try { |
||||||
|
pinDao = getDao(Pin.class); |
||||||
|
loadableDao = getDao(Loadable.class); |
||||||
|
} catch (SQLException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
package org.floens.chan.database; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.floens.chan.model.Pin; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
|
||||||
|
public class DatabaseManager { |
||||||
|
private final DatabaseHelper helper; |
||||||
|
|
||||||
|
public DatabaseManager(Context context) { |
||||||
|
helper = new DatabaseHelper(context); |
||||||
|
} |
||||||
|
|
||||||
|
public void addPin(Pin pin) { |
||||||
|
try { |
||||||
|
helper.pinDao.create(pin); |
||||||
|
} catch (SQLException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void removePin(Pin pin) { |
||||||
|
try { |
||||||
|
helper.pinDao.delete(pin); |
||||||
|
} catch (SQLException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void updatePin(Pin pin) { |
||||||
|
try { |
||||||
|
helper.pinDao.update(pin); |
||||||
|
} catch (SQLException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public List<Pin> getPinned() { |
||||||
|
List<Pin> list = null; |
||||||
|
try { |
||||||
|
list = helper.pinDao.queryForAll(); |
||||||
|
} catch (SQLException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
return list; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue