/*
* Generated by Robotoworks Mechanoid
*/
package com.robotoworks.example.recipes.content;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.net.Uri;
import com.robotoworks.example.recipes.content.RecipesDBContract.Authors;
import com.robotoworks.example.recipes.content.RecipesDBContract.Authors.Builder;
import com.robotoworks.mechanoid.util.Closeables;
import com.robotoworks.mechanoid.db.ActiveRecord;
import com.robotoworks.mechanoid.db.ActiveRecordFactory;
import com.robotoworks.mechanoid.Mechanoid;
import com.robotoworks.mechanoid.db.AbstractValuesBuilder;
public class AuthorsRecord extends ActiveRecord implements Parcelable {
private static ActiveRecordFactory<AuthorsRecord> sFactory = new ActiveRecordFactory<AuthorsRecord>() {
@Override
public AuthorsRecord create(Cursor c) {
return fromCursor(c);
}
@Override
public String[] getProjection() {
return PROJECTION;
}
@Override
public Uri getContentUri() {
return Authors.CONTENT_URI;
}
};
public static ActiveRecordFactory<AuthorsRecord> getFactory() {
return sFactory;
}
public static final Parcelable.Creator<AuthorsRecord> CREATOR
= new Parcelable.Creator<AuthorsRecord>() {
public AuthorsRecord createFromParcel(Parcel in) {
return new AuthorsRecord(in);
}
public AuthorsRecord[] newArray(int size) {
return new AuthorsRecord[size];
}
};
public static String[] PROJECTION = {
Authors._ID,
Authors.NAME
};
public interface Indices {
int _ID = 0;
int NAME = 1;
}
private String mName;
private boolean mNameDirty;
@Override
protected String[] _getProjection() {
return PROJECTION;
}
public void setName(String name) {
mName = name;
mNameDirty = true;
}
public String getName() {
return mName;
}
public AuthorsRecord() {
super(Authors.CONTENT_URI);
}
private AuthorsRecord(Parcel in) {
super(Authors.CONTENT_URI);
setId(in.readLong());
mName = in.readString();
boolean[] dirtyFlags = new boolean[1];
in.readBooleanArray(dirtyFlags);
mNameDirty = dirtyFlags[0];
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(getId());
dest.writeString(mName);
dest.writeBooleanArray(new boolean[] {
mNameDirty
});
}
@Override
protected AbstractValuesBuilder createBuilder() {
Builder builder = Authors.newBuilder();
if(mNameDirty) {
builder.setName(mName);
}
return builder;
}
@Override
public void makeDirty(boolean dirty){
mNameDirty = dirty;
}
@Override
protected void setPropertiesFromCursor(Cursor c) {
setId(c.getLong(Indices._ID));
setName(c.getString(Indices.NAME));
}
public static AuthorsRecord fromCursor(Cursor c) {
AuthorsRecord item = new AuthorsRecord();
item.setPropertiesFromCursor(c);
item.makeDirty(false);
return item;
}
public static AuthorsRecord fromBundle(Bundle bundle, String key) {
bundle.setClassLoader(AuthorsRecord.class.getClassLoader());
return bundle.getParcelable(key);
}
public static AuthorsRecord get(long id) {
Cursor c = null;
ContentResolver resolver = Mechanoid.getContentResolver();
try {
c = resolver.query(Authors.CONTENT_URI.buildUpon()
.appendPath(String.valueOf(id)).build(), PROJECTION, null, null, null);
if(!c.moveToFirst()) {
return null;
}
return fromCursor(c);
} finally {
Closeables.closeSilently(c);
}
}
}