Giter Club home page Giter Club logo

activeandroid's Introduction

Build Status Stories in Ready

ActiveAndroid

ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to save and retrieve SQLite database records without ever writing a single SQL statement. Each database record is wrapped neatly into a class with methods like save() and delete().

ActiveAndroid does so much more than this though. Accessing the database is a hassle, to say the least, in Android. ActiveAndroid takes care of all the setup and messy stuff, and all with just a few simple steps of configuration.

Download

Grab via Maven:

<dependency>
  <groupId>com.michaelpardo</groupId>
  <artifactId>activeandroid</artifactId>
  <version>3.1.0-SNAPSHOT</version>
</dependency>

or Gradle:

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'

Documentation

License

Apache Version 2.0

Copyright (C) 2010 Michael Pardo

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributing

Please fork this repository and contribute back using pull requests.

Any contributions, large or small, major features, bug fixes, unit tests are welcomed and appreciated but will be thoroughly reviewed and discussed.

You can run the test suite by following the instructions on the Running the Test Suite Wiki page.

Author

Michael Pardo | www.michaelpardo.com | www.activeandroid.com

activeandroid's People

Contributors

blork avatar bradmcmanus avatar dbalaouras avatar ddrscott avatar harward avatar jdeuce avatar jonan avatar joshuapinter avatar leonardoxh avatar melvin7 avatar mpfeiffermway avatar pardom avatar sabadow avatar seanponeil avatar vonloxley avatar vsigler avatar wendly avatar xarthasx avatar yongjhih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activeandroid's Issues

Fetch id automatically

If I do a

new Select("name").from(Item.class).orderBy("name").execute();

the resulting objects have their id-member set to null and even getId() returns null.

Since the id-field is handled by the library I’d expect the call to getId() to succeed, even if I didn’t specify id in the select-list. Perhaps the id-field should be added to the projection automatically.

ActiveAndroid & androidannotations

I want to use these two library but I think there are incompatibles.

When I use ActiveAndroid in my object class "@table(name = "Categories")", Eclipse show this error: "The annotation @table is disallowed for this location"

Thanks!

Donate

Thanks for making ActiveAndroid open source, but how do i donate?

Using a custom model constructor, object is not saved

In a subclass of Model, I have the custom constructor:

public User(String username) {
    super();
    this.username = username;
}

And I call:

User user = new User("test");
user.save();

But when I call new Select().from(User.class).execute() the resulting list is empty.

On the other hand, doing

User user = new User();
user.username = "test";
user.save();

and the user is saved and can be retrieved.

Is there a reason I can't have a custom constructor on my Model subclass? What am I missing?

SQL JOIN from multiple tables

Hi,

ActiveAndroid has helped me out tremendously so far! But I have come to the point where I need to perform a JOIN across multiple Tables.

Is this possible? If so how, and what will it return?

NullPointerException at com.activeandroid.Registry.getTableName(Registry.java:218)

ActiveAndroid looks great, but my first attempt at using it is giving me a NullPointerException. i'm using ActiveAndroid 3.0. android project target api level 17. eclipse ADT v22. my model:

@Table(name = "conditions")
public class Condition extends Model {
    @Column(name = "name")
    public String name;

    @Column(name = "date")
    public Date date;
}

instantiating this model with

Condition cond = new Condition();

stack trace excerpt:

05-23 13:50:15.751: E/AndroidRuntime(20355): Caused by: java.lang.NullPointerException
05-23 13:50:15.751: E/AndroidRuntime(20355):    at com.activeandroid.Registry.getTableName(Registry.java:218)
05-23 13:50:15.751: E/AndroidRuntime(20355):    at com.activeandroid.ReflectionUtils.getTableName(ReflectionUtils.java:26)
05-23 13:50:15.751: E/AndroidRuntime(20355):    at com.activeandroid.Model.<init>(Model.java:33)
05-23 13:50:15.751: E/AndroidRuntime(20355):    at com.benhirashima.Condition.<init>(Condition.java:60)

seems like a problem with getTableName, but i defined my table name as per the documentation. please advise.

Building with Maven

When I run mvn install, I get this output:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] ActiveAndroid - Parent
[INFO] ActiveAndroid
[INFO] ActiveAndroid - Tests
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ActiveAndroid - Parent 3.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ activeandroid-parent ---
[INFO] Deleting /Volumes/HDD/Github/ActiveAndroid/target
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ activeandroid-parent ---
[INFO] Installing /Volumes/HDD/Github/ActiveAndroid/pom.xml to /Users/sean/.m2/repository/com/activeandroid/activeandroid-parent/3.1-SNAPSHOT/activeandroid-parent-3.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ActiveAndroid 3.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ activeandroid ---
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ activeandroid ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Volumes/HDD/Github/ActiveAndroid/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ activeandroid ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] Compiling 26 source files to /Volumes/HDD/Github/ActiveAndroid/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] Note: /Volumes/HDD/Github/ActiveAndroid/src/com/activeandroid/ModelInfo.java uses unchecked or unsafe operations.
[WARNING] Note: Recompile with -Xlint:unchecked for details.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Volumes/HDD/Github/ActiveAndroid/src/com/activeandroid/Cache.java:[24,31] package android.support.v4.util does not exist
[ERROR] /Volumes/HDD/Github/ActiveAndroid/src/com/activeandroid/Cache.java:[45,24] cannot find symbol
symbol : class LruCache
location: class com.activeandroid.Cache
[ERROR] /Volumes/HDD/Github/ActiveAndroid/src/com/activeandroid/Cache.java:[75,33] cannot find symbol
symbol : class LruCache
location: class com.activeandroid.Cache
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] ActiveAndroid - Parent ............................ SUCCESS [0.239s]
[INFO] ActiveAndroid ..................................... FAILURE [2.007s]
[INFO] ActiveAndroid - Tests ............................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.123s
[INFO] Finished at: Mon Jun 10 22:32:29 EDT 2013
[INFO] Final Memory: 14M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project activeandroid: Compilation failure: Compilation failure:
[ERROR] /Volumes/HDD/Github/ActiveAndroid/src/com/activeandroid/Cache.java:[24,31] package android.support.v4.util does not exist
[ERROR] /Volumes/HDD/Github/ActiveAndroid/src/com/activeandroid/Cache.java:[45,24] cannot find symbol
[ERROR] symbol : class LruCache
[ERROR] location: class com.activeandroid.Cache
[ERROR] /Volumes/HDD/Github/ActiveAndroid/src/com/activeandroid/Cache.java:[75,33] cannot find symbol
[ERROR] symbol : class LruCache
[ERROR] location: class com.activeandroid.Cache
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :activeandroid

Any idea what's wrong?

Adding Sqlite FTS3 support

This would be a very usefull functionality for searcheable activities

FTS is the acronym for “full-text search”. FTS3 itself is an SQLite extension that is now part of SQLite that provides support for creating virtual tables which in fact maintain an inverted index for full-text searches. That means you can use FTS tables to enable full-text search in Android applications.

Custom primary key?

Is it possible, or on the road map to have a custom field as the primary key?

How could i use ActiveAndroid in one class whitch contain a arraylist?

I read the Relationships section,but it's not work.
I think there is something wrong with my usage.
Anyone could help me?

There are two class.

Originally code like

Class RoundInfo :

public class RoundInfo{

String roundNum;
List<MatchInfo> matchInfos = new ArrayList<MatchInfo>();

public RoundInfo() {
    super();
    // TODO Auto-generated constructor stub
}

public RoundInfo(String roundNum) {
    super();
    this.roundNum = roundNum;
    matchInfos.add(new MatchInfo("11", "21", "1121"));
}

}

Class MatchInfo:

public class MatchInfo{

String home;
String away;
String sorce;

public MatchInfo() {
    super();
}

public MatchInfo(String home, String away, String sorce) {
    super();
    this.home = home;
    this.away = away;
    this.sorce = sorce;
}

}

Then i wanna use ActiveAndroid save roundinfo data to db.
And make some change like
1.Let my application class extends com.activeandroid.app.Application
2.Add AA_DB_NAME & AA_DB_VERSION to AndroidManifest.xml
3.Modify class MatchInfo & RoundInfo to

Class RoundInfo:

@table(name = "RoundInfo")
public class RoundInfo extends Model {

@Column(name = "roundNum")
String roundNum;

public List<MatchInfo> matchinfos() {
    return getMany(MatchInfo.class, "MatchInfo");
}

public RoundInfo() {
    super();
    // TODO Auto-generated constructor stub
}

public RoundInfo(String roundNum) {
    super();
    this.roundNum = roundNum;
    matchinfos().add(new MatchInfo("11", "21", "1121"));
    matchinfos().add(new MatchInfo("12", "22", "1222"));
    matchinfos().add(new MatchInfo("13", "23", "1323"));
    matchinfos().add(new MatchInfo("14", "24", "1424"));
}

}

Class MatchInfo:

@table(name = "MatchInfos")
public class MatchInfo extends Model {

@Column(name = "home")
String home;
@Column(name = "away")
String away;
@Column(name = "sorce")
String sorce;

public MatchInfo() {
    super();
    // TODO Auto-generated constructor stub
}

public MatchInfo(String home, String away, String sorce) {
    super();
    this.home = home;
    this.away = away;
    this.sorce = sorce;
}

}

Question:
When i new the RoundInfo class and save() it use

    RoundInfo roundInfo1 = new RoundInfo("1");
    roundInfo1.save();

Finally get some errors like

04-01 22:33:37.875: E/AndroidRuntime(14712): FATAL EXCEPTION: main
04-01 22:33:37.875: E/AndroidRuntime(14712): java.lang.NullPointerException
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.activeandroid.query.From.getArguments(From.java:207)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.activeandroid.query.From.execute(From.java:183)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.activeandroid.Model.getMany(Model.java:247)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.example.testdb.RoundInfo.matchinfos(RoundInfo.java:16)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.example.testdb.RoundInfo.(RoundInfo.java:27)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.example.testdb.MainActivity.initDB(MainActivity.java:45)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.example.testdb.MainActivity.access$0(MainActivity.java:43)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.example.testdb.MainActivity$1.onClick(MainActivity.java:36)
04-01 22:33:37.875: E/AndroidRuntime(14712): at android.view.View.performClick(View.java:2486)
04-01 22:33:37.875: E/AndroidRuntime(14712): at android.view.View$PerformClick.run(View.java:9130)
04-01 22:33:37.875: E/AndroidRuntime(14712): at android.os.Handler.handleCallback(Handler.java:587)
04-01 22:33:37.875: E/AndroidRuntime(14712): at android.os.Handler.dispatchMessage(Handler.java:92)
04-01 22:33:37.875: E/AndroidRuntime(14712): at android.os.Looper.loop(Looper.java:130)
04-01 22:33:37.875: E/AndroidRuntime(14712): at android.app.ActivityThread.main(ActivityThread.java:3703)
04-01 22:33:37.875: E/AndroidRuntime(14712): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 22:33:37.875: E/AndroidRuntime(14712): at java.lang.reflect.Method.invoke(Method.java:507)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-01 22:33:37.875: E/AndroidRuntime(14712): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-01 22:33:37.875: E/AndroidRuntime(14712): at dalvik.system.NativeStart.main(Native Method)

I know the problem is my usage of the method matchinfos().
How to solve it?

Accessing model object through relationship gives null object

I'm getting a mismatch in the objects returned from a direct query vs. those obtained from a relationship. For example, here are the toString() representations of 2 objects (where ID is the result of getId()), the first retrieved by doing parent.example (where Parent is a model which has an Example as a member, and Setting is a model object related to Example):

Example [categoryID=Category1, Settings=null, name=Test, ID=3]

And the second by doing:

new Select()
.from(Example.class)
.where("categoryID = ?", example.categoryID)
.executeSingle();

which gives:

Example [categoryID=Category1, Settings=Settings [ID=1 client=7c2c7af0-ad3e-45b0-b709-7e56bb0b76f3 doesRequireAuthentication=true], name=Test, ID=3]

This consistently happens after my first data import but then works if the app is restarted (without any further database changes). The objects are clearly the same, as the ID is shared, but the first seems to have been cached and not updated. Is there any way for me to force it to be updated without directly requerying?

Hardwired "bin" as a Robolectric workaround?

I'm using Robolectric on my project, and it's very kind of you to have inserted some code that makes it possible to run under Robolectric. I was wondering why "bin" is hardwired into the code, though. Is that an Eclipse thing? IntelliJ IDEA uses "out" by default, it appears.

Thanks,
Rick

Cant seem to find the jar file.

Hi

Thanks for the project! Very handy.

I now wanted to update my versjon of the jar file, but cant seem to find the latest version. Or any version for that matter. It is referd to the web page and there i can only find the source.

Any pointers or should i build it my self?

Best regards Aslak

Is it possible to update a specific field in a table row without wiping out the rest of the data in the row

Hi.

I need to push updates to specific table fields without wiping out any existing data in the row if i dont happen to save() data for all fields each time.

For example:

I have a table named 'user' which contains the following fields:

extSrc | extId | email | firstName | lastName | role | photo | userId | verified

If i save data to all fields except 'verified' and then I later need to update only the verified field - is this possible?

Currently when i use the code below, all fields except userId (which i have stored locally) and verified are populated, all other fields are cleared. At the time that i have the verified value that i need to update i dont have the additional user data to push / save() so i only need to update the specific 'verified' field when the userId matches a userId in the user table and leave all other fields for that user as they are.

My code:

Model:

// define table name
@table(name = "User")

public class User extends Model
{
// define table columns

@Column(name = "extSrc")
public String extSrc;

@Column(name = "extId")
public String extId;

@Column(name = "email")
public String email;

@Column(name = "firstName")
public String firstName;

@Column(name = "lastName")
public String lastName;

@Column(name = "role")
public String role;

@Column(name = "photo")
public String photo;

@Column(name = "userId", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
public String userId;

@Column(name = "verified")
public String verified;

}

controller:

public class UserAdapter implements JsonDeserializer {

@Override
public User deserialize(JsonElement arg0, Type arg1,
        JsonDeserializationContext arg2) throws JsonParseException {

            User u = new User();

            Log.v("user", u.toString());

            JsonObject j = (JsonObject) arg0;

            Log.v("j", j.toString());


            if(j.has("extSrc"))
            {
                u.extSrc = j.get("extSrc").getAsString();
                Log.v("extSrc", u.extSrc);
            }
            else
            {
                Log.v("extSrc", "does not exist");
            }


            if(j.has("extId"))
            {
                u.extId = j.get("extId").getAsString();
                Log.v("extId", u.extId);
            }
            else
            {
                Log.v("extId", "does not exist");
            }


            if(j.has("email"))
            {
                u.email = j.get("email").getAsString();
                Log.v("email", u.email);
            }
            else
            {
                Log.v("email", "does not exist");
            }


            if(j.has("firstName"))
            {
                u.firstName = j.get("firstName").getAsString();
                Log.v("firstName", u.firstName);
            }
            else
            {
                Log.v("firstName", "does not exist");
            }


            if(j.has("lastName"))
            {
                u.lastName = j.get("lastName").getAsString();
                Log.v("lastName", u.lastName);
            }
            else
            {
                Log.v("lastName", "does not exist");
            }


            if(j.has("role"))
            {
                u.role = j.get("role").getAsString();
                Log.v("role", u.role);
            }
            else
            {
                Log.v("role", "does not exist");
            }


            if(j.has("photo"))
            {
                u.photo = j.get("photo").getAsString();
                Log.v("photo", u.photo);
            }
            else
            {
                Log.v("photo", "does not exist");
            }


            if(j.has("userId"))
            {
                u.userId = j.get("userId").getAsString();
                Log.v("userId", u.userId);
            }
            else
            {
                Log.v("userId", "does not exist");
            }

            u.save();

            if(j.has("verified"))
            {
                u.userId = SpontlyApplication.PREFS_USER_ID;
                u.verified = j.get("verified").getAsString();

                Log.v("verified", u.verified);
            }
            else
            {
                u.verified = "true";
                Log.v("verified", "does not exist");
            }

}

Thanks.

Updating table fields - leaving row id the same

Hi.

I am trying to find a method of updating fields in a table row whilst leaving the row id (automatically generated by ActiveAndroid) the same. Is this possible in ActiveAndroid or does the row id always get updated when updates occur to a particular row?

Thanks

Barry.

No ActiveAndroid.jar

The getting started section of the Wiki lists including ActiveAndroid.jar to use the library. Upon downloading the library, no ActiveAndroid.jar file was found.

Caching Model objects eats up memory and is hard to track down.

Hi,

First of all - thanks for great DB library :)

The problem we had is: we're using ActiveAndroid to store all the data we fetch from remote server. Mostly it's information about albums of images, so quite a lot String information (image urls, album details etc.). Thing is, we query DB a lot to get always up-to-date information, but we noticed, that each Select generates around 2-3KB memory overhead, that is later on not really used.

When tracking down the problem, I noticed, that Select is calling SQLiteUtil.processCursor method behind the scenes, which is calling

                    // TODO: Investigate entity cache leak
                    T entity = (T) entityConstructor.newInstance();

The leak mentioned in comment might not exactly be the leak but bloat, since Model in it's constructor is doing:

Cache.addEntity(this);

Anyway, thing is - clearing the cache with ActiveAndroid.clearCache() allows to free the 'lost' memory.

Please consider using LruCache instead of HashSet, as it will allow to specify how much memory you are willing to give away for DB cache to work.
Otherwise it will be hard to maintain the HashSet.

As an interesting point - this Set is able to grow up to several MB on device, which is, at least for me, killing possibility to load bitmap - that was the main issue I started to track it down and decided to write an issue report. Maybe someone else is also looking for answers and hits this post :-)

Keep up great work.

Cheers,
Damian

method getArguments of Set class is wrong

I was trying to use Update class with WHERE arguments, but didn't worked, so I checked Set class and figure out that method is wrong, the set arguments are replacing with where arguments.

Thanks.

getMany() references the wrong table

In the documentation, a relationship between Item and Category is defined in the following manner: getMany(Item.class, "Category") within the Category model. The intent (I believe) is to query the Items table for any records related to the current Category.

Based on the debug output, it appears the following query is constructed:
SELECT * FROM Items WHERE Categories.Category=?

I believe the correct query should be:
SELECT * FROM Items WHERE Items.Category=?

This is happening in 3.1-beta. I tried compiling from the latest source, but then the Gson library is unable to create objects based on Json data (complaining about unable to create the class using the default constructor), so I could not fully test the latest code.

Inheritance Support?

Does ActiveAndroid models support inheritance? For example, if I had a Person model as the superclass and Attendee as a subclass, how would AA handle this? With Ruby on Rails, it is combined into a single table with values from subclasses added to the parent table. Any thoughts?

Also, there's a real need for rest of doco to be completed (schema migrations <-- important).

ContentObservers

This seems like a really great library!

How does your library work with ContentObservers? I'm thinking specifically about the CursorLoader pattern for populating ListViews with CursorAdapters?

UtilDateSerializer not getting registered

We're trying to serialize and deserialize a java.util.Date field. We notice that we don't have a UtilDateSerializer registered in ModelInfo. We would expect that these TypeSerializers would automatically be registered during ActiveAndroid.initialize(). Is there some reason they aren't?

Thanks,
Rick

@Column(name = "unique")

Please add to the documentation a list of column names that we cant use (such as id, unique). I just spent way too long to find out that I couldn’t use unique as a column name after getting this non informative error whenever I tried to start the application:

06-15 15:54:07.730: E/SQLiteLog(27912): (1) near "TEXT": syntax error

Error: Reached MAX size for compiled-sql statement cache for database

I got this error when doing a bulk update inside a transaction. After updating 255 objects the error appears in the log. I searched in Stack overflow and I found a solution http://stackoverflow.com/questions/7255574/reached-max-size-for-compiled-sql-statement-cache-for-database, instead of manually crafting the where clause try to write a parametrized one in the line 147 of Model.java.

String[] whereArgs = new String[]{String.valueOf(mId)}
db.update(mTableInfo.getTableName(), values, "Id= ?", whereArgs);

Last object not saved after table was truncated

I use ActiveAndroid to save my objects to the database, it works mostly well. In my application, I use the following scenario:

•I save a new object to a table in my database
•I select some objects from that table
•I add them to a List<>
•I delete everything from that table
•I use foreach on my List and call 'save' on each object

And here comes the problem. In my table the objects are saved except the aforementioned most recently saved one. I created a counter to check, how many 'save' was called: the counter is 1 more than the count of the objects in the table. I debugged it, no exception was raised, the save was called. I use the latest version of ActiveAndroid (3.0.99)
Any ideas what I should check?

Will ActiveAndroid support multiple databases in future?

Hey guys, thanks for your awesome work.

I would like to know whether supporting multiple databases is in you roadmap? Our project requires to have multiple database and specify their name dynamically. It also requires to access these db at the same time. Now the implementation is quite "static" and hard to archive that goal.

How to put a model into bundle extras

Hi, folks! I'm a newbie with Android and ActiveAndroid. So I'm really sorry if this is a fool issue :( I just cant figure it out

I wrote a Book class which has Chapter objects (a one to many relationship). It implements the method public List chapters(), as stated in the docs. This is the Book.java

@Table(name = "Books")
public class Book extends Model implements Serializable {

    private static final long serialVersionUID = 1L;

    @Column(name = "Name", unique = true, onUniqueConflict = Column.ConflictAction.IGNORE)
    public String name;

    @Column(name = "Sort")
    public int sort;

    public Book() {
        super();
    }

    public Book(String name, int sort) {
        super();
        this.name = name;
        this.sort = sort;
    }

    public List<Chapter> chapters() {
        return getMany(Chapter.class, "Book");
    }

    @Override
    public String toString() {
        return name;
    }

On the main activity I can get the Chapter objects successfully. However, I have to pass a book object to another activity, which has a fragment, and though I get the object's stated attributes (String name and int sort) it throws an exception when I call to chapters():

Bundle bundle = getIntent().getExtras();
Book book = (Book) bundle.getSerializable("BOOK");

// This line is executed successfully
Log.d("TAGGED", "Recovered book: " + book.name + " has " + book.sort + " as its sort");

// This is the line that throws an exception 
ArrayList<Chapter> chapters = book.chapters();

Any ideas what is wrong? Thanks!!!

Content provider NullPointerException

I'm trying to implement content provider for my app but when i try to use "com.activeandroid.content.ContentProvider" the app crash at this line:
private final String mAuthority = getContext().getPackageName();(ContentProvider.java:31)

Unable to install/build project from maven3

Hi

The project seems like a nice fit for my project, but I cannot build this on my local machine. According to the error message the build cannot resolve the parent pom. Where can I find this parent pom, as it is not part of the project source?

Regards
Andries

Can't select by Date

I use this awesome lib in some of my apps and had no issues til now.

In one of my newest apps i have to select an entry by date but i'm not able to get the entry via date. even if i use the same object to do the select.

This is my select-statement. Any hints? Or is this an issue?

return new Select().from(Employment.class).where("employmentDate = ?", date).executeSingle();

How to setup project for ANT build

Hey guys,

I'm trying to build my android app using Ant, but it keeps giving me an error saying that the activeandroid package does not exist.

I'm not using the activeandroid jar, but instead I have checked out the project from github and referenced that project into my android app project.

Whats the correct way to do this? I would prefer to not put a jar in the android apps libs folder, because its much easier to update the library from github.

Thanks

Cannot instantiate POJO models via frameworks like Gson

When attempting to use Gson to populate objects based on ActiveAndroid Models, the construction of the new object fails during the phase. Gson attempts to do this via reflection.

This process works with the latest JAR (activeandroid-3.1-beta.jar) from https://github.com/pardom/ActiveAndroid/downloads, but does not work with JARs compiled from the latest source tree.

Here's the logcat based on my application (I'm loading a JSON resource through a 3rd party library, then using Gson to instantiate the objects, finally saving them to the DB with AA).

06-09 18:42:28.908: W/System.err(8242): java.lang.RuntimeException: Failed to invoke public com.mhamann.versecards.domain.Course() with no args 06-09 18:42:28.916: W/System.err(8242): at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:111) 06-09 18:42:28.916: W/System.err(8242): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:162) 06-09 18:42:28.916: W/System.err(8242): at com.google.gson.Gson.fromJson(Gson.java:803) 06-09 18:42:28.916: W/System.err(8242): at com.koushikdutta.ion.gson.GsonSerializer$1.transform(GsonSerializer.java:39) 06-09 18:42:28.916: W/System.err(8242): at com.koushikdutta.ion.gson.GsonSerializer$1.transform(GsonSerializer.java:35) 06-09 18:42:28.916: W/System.err(8242): at com.koushikdutta.async.future.TransformFuture.onCompleted(TransformFuture.java:14) 06-09 18:42:28.916: W/System.err(8242): at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:81) 06-09 18:42:28.923: W/System.err(8242): at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:110) 06-09 18:42:28.923: W/System.err(8242): at com.koushikdutta.async.parser.ByteBufferListParser$3.onCompleted(ByteBufferListParser.java:42) 06-09 18:42:28.923: W/System.err(8242): at com.koushikdutta.async.DataEmitterBase.report(DataEmitterBase.java:16) 06-09 18:42:28.931: W/System.err(8242): at com.koushikdutta.async.FilteredDataEmitter$1.onCompleted(FilteredDataEmitter.java:24) 06-09 18:42:28.931: W/System.err(8242): at com.koushikdutta.async.DataEmitterBase.report(DataEmitterBase.java:16) 06-09 18:42:28.931: W/System.err(8242): at com.koushikdutta.async.http.AsyncHttpResponseImpl.report(AsyncHttpResponseImpl.java:107) 06-09 18:42:28.931: W/System.err(8242): at com.koushikdutta.async.http.AsyncHttpClient$2$2.report(AsyncHttpClient.java:263) 06-09 18:42:28.931: W/System.err(8242): at com.koushikdutta.async.FilteredDataEmitter$1.onCompleted(FilteredDataEmitter.java:24) 06-09 18:42:28.931: W/System.err(8242): at com.koushikdutta.async.DataEmitterBase.report(DataEmitterBase.java:16) 06-09 18:42:28.931: W/System.err(8242): at com.koushikdutta.async.FilteredDataEmitter$1.onCompleted(FilteredDataEmitter.java:24) 06-09 18:42:28.931: W/System.err(8242): at com.koushikdutta.async.DataEmitterBase.report(DataEmitterBase.java:16) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.http.filter.ChunkedInputFilter.onDataAvailable(ChunkedInputFilter.java:99) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.Util.emitAllData(Util.java:20) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.AsyncSSLSocketWrapper$1.onDataAvailable(AsyncSSLSocketWrapper.java:96) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(BufferedDataEmitter.java:33) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(BufferedDataEmitter.java:62) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.Util.emitAllData(Util.java:20) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:162) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:788) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:647) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:31) 06-09 18:42:28.939: W/System.err(8242): at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:595) 06-09 18:42:28.947: W/System.err(8242): Caused by: java.lang.NullPointerException: key == null || value == null 06-09 18:42:28.947: W/System.err(8242): at android.support.v4.util.LruCache.put(LruCache.java:117) 06-09 18:42:28.955: W/System.err(8242): at com.activeandroid.Cache.addEntity(Cache.java:124) 06-09 18:42:28.955: W/System.err(8242): at com.activeandroid.Model.<init>(Model.java:51) 06-09 18:42:28.955: W/System.err(8242): at com.mhamann.versecards.domain.Course.<init>(Course.java:29) 06-09 18:42:28.955: W/System.err(8242): at java.lang.reflect.Constructor.constructNative(Native Method) 06-09 18:42:28.955: W/System.err(8242): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 06-09 18:42:28.955: W/System.err(8242): at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:104) 06-09 18:42:28.962: W/System.err(8242): ... 28 more

CASCADE Action onDelete

Hi,

Lets take your example with Category and Item.

Category
@table(name = "Categories")
public class Category extends Model {

@Column(name = "Name", notNull = true, unique = true)
public String name;

public List<Item> items() {
    return getMany(Item.class, "Category");
}

public Category() {
    super();
}

public Category(String name) {
    super();
    this.name = name;
}

@Override
public String toString() {
    return new String("[" + Category.class.getName() + "] " 
            + "Name = " + name);
}

}

Item

@table(name = "Items")
public class Item extends Model {

@Column(name = "Name", notNull = true, unique = true)
public String name;

@Column(name = "Category", onDelete = ForeignKeyAction.CASCADE)
public Category category;

public Item() {
    super();
}

public Item(String name, Category category) {
    super();
    this.name = name;
    this.category = category;
}

@Override
public String toString() {
    return new String("[" + Item.class.getName() + "] " 
            + "Name = " + name + " | "
            + "Category = " + category);
}

}

After saving one Category data with many items, when I delete the inserted Category, the items remain in database. Is the CASCADE Action upon onDelete is working ? How to establish properly ForeignKeyActions ?

Thanks.

TypeSerializer confused

Hello guys I am new in android so please bare with me :) Anyway, I just want to know more about TypeSerializer. I am confused how to used it. In the documentation It just show how Date Type Serializer was define but not how to used it. Does it mean if my model have a date property I need to used date type serializer? If yes how? If not. Then what is the used for serializer? If someone is kind enough to show some sample code. Thanks in advance.

NullPointerException when trying to add an object to many relationship of other object

java.lang.NullPointerException
at com.activeandroid.query.From.getArguments(Unknown Source)
at com.activeandroid.query.From.execute(Unknown Source)
at com.activeandroid.Model.getMany(Unknown Source)
at it.mediaprime.terme.models.RKThermae.categories(RKThermae.java:20)

@Table(name = "RKThermaes")
public class RKThermae extends Model{
    @Column(name ="ThermaeId", unique = true)
    public int thermaeId;

    public List<RKCategory> categories() {
        return getMany(RKCategory.class, "RKThermae");
    };

    @Column(name ="Gallery")
    public RKGallery gallery;
...

 public void update(JSONObject json){
   JSONArray arrayCategories = json.optJSONArray("categories");
        if (arrayCategories != null) {
            int categoriesLength = arrayCategories.length();
            for (int i = 0; i < categoriesLength; i++) {
                int categoryId = arrayCategories.optInt(i);
                RKCategory category = RKCategory.find(categoryId);
                if(category != null){
                   try{
                    this.categories().add(category);
                   } catch (Exception e){
                       Log.e("thermae add category", "EXC", e);

                   }
                }
            }
        }
}

}

public class RKCategory extends Model {

    public List<RKProduct> products() {
        return getMany(RKProduct.class, "RKCategory");
    };

    @Column(name = "ModelId")
    public int modelId;
    @Column(name = "CategoryId", unique = true)
        public int categoryId;
    @Column(name = "Deleted")
        public boolean deleted;  
    @Column(name = "CreatedAt")
        public String createdAt;
    @Column(name = "Title")
        public String title;
    @Column(name = "ModelType")
        public String modelType;
        ...

    static public  RKCategory find(int id){
        return new Select().from(RKCategory.class).where("categoryId = ?", id).executeSingle();
    }
}

Working with an existing db (coming from iOS)

I have a working iOS application storing data in a myapp.sqlite file.
I would like to reuse this myapp.sqlite directly with the ActiveAndroid stack.

  • How to do that ?
  • Is it possible ?

Bulk insert?

Can this library support androids faster "Bulk insert", where you create an array of items and save them all in one function call?

Cascading save/delete?

Perhaps it might be useful to have an annotation for relationships between models that determine whether they should be deleted or saved along with the parent object?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.