This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
943 release openhelpermanager #1245
Merged
WonderCsabo
merged 3 commits into
androidannotations:develop
from
jiongxuan:943_release_openhelpermanager
Nov 20, 2014
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...tations/androidannotations/src/main/java/org/androidannotations/helper/OrmLiteHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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. | ||
| */ | ||
| package org.androidannotations.helper; | ||
|
|
||
| import static com.sun.codemodel.JExpr._null; | ||
|
|
||
| import org.androidannotations.holder.HasReceiverRegistration; | ||
| import org.androidannotations.process.ProcessHolder; | ||
|
|
||
| import com.sun.codemodel.JBlock; | ||
| import com.sun.codemodel.JFieldVar; | ||
|
|
||
| public class OrmLiteHelper { | ||
|
|
||
| public static void injectReleaseInDestroy(JFieldVar databaseHelperRef, HasReceiverRegistration receiverHolder, ProcessHolder.Classes classes) { | ||
| JBlock destroyBody = receiverHolder.getOnDestroyBeforeSuperBlock(); | ||
|
|
||
| destroyBody.staticInvoke(classes.OPEN_HELPER_MANAGER, "releaseHelper"); | ||
| destroyBody.assign(databaseHelperRef, _null()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...est-1-5/src/main/java/org/androidannotations/test15/ormlite/OrmLiteOnDestroyActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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. | ||
| */ | ||
| package org.androidannotations.test15.ormlite; | ||
|
|
||
| import org.androidannotations.annotations.EActivity; | ||
| import org.androidannotations.annotations.OrmLiteDao; | ||
|
|
||
| import android.app.Activity; | ||
|
|
||
| @EActivity | ||
| public class OrmLiteOnDestroyActivity extends Activity { | ||
|
|
||
| @OrmLiteDao(helper = DatabaseHelper.class) | ||
| UserDao userDao; | ||
| } |
59 changes: 59 additions & 0 deletions
59
...al-test-1-5/src/test/java/org/androidannotations/test15/ormlite/OrmLiteOnDestroyTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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. | ||
| */ | ||
| package org.androidannotations.test15.ormlite; | ||
|
|
||
| import static org.fest.assertions.api.Assertions.assertThat; | ||
| import static org.fest.reflect.core.Reflection.field; | ||
| import static org.fest.reflect.core.Reflection.staticField; | ||
|
|
||
| import org.fest.reflect.field.Invoker; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.robolectric.Robolectric; | ||
| import org.robolectric.RobolectricTestRunner; | ||
| import org.robolectric.util.ActivityController; | ||
|
|
||
| import com.j256.ormlite.android.apptools.OpenHelperManager; | ||
| import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; | ||
|
|
||
| @RunWith(RobolectricTestRunner.class) | ||
| public class OrmLiteOnDestroyTest { | ||
|
|
||
| private ActivityController<OrmLiteOnDestroyActivity_> controller; | ||
| private Invoker<Integer> instanceCountInvoker; | ||
|
|
||
| @Before | ||
| public void setup() throws NoSuchFieldException, IllegalAccessException { | ||
| staticField("helper").ofType(OrmLiteSqliteOpenHelper.class).in(OpenHelperManager.class).set(null); | ||
| staticField("helperClass").ofType(Class.class).in(OpenHelperManager.class).set(null); | ||
| staticField("wasClosed").ofType(boolean.class).in(OpenHelperManager.class).set(false); | ||
|
|
||
| instanceCountInvoker = staticField("instanceCount").ofType(int.class).in(OpenHelperManager.class); | ||
| instanceCountInvoker.set(0); | ||
|
|
||
| controller = Robolectric.buildActivity(OrmLiteOnDestroyActivity_.class).create(); | ||
| } | ||
|
|
||
| @Test | ||
| public void helper_is_destroyed() throws Exception { | ||
| controller.destroy(); | ||
|
|
||
| Object databaseHelper_ = field("databaseHelper_").ofType(OrmLiteSqliteOpenHelper.class).in(controller.get()).get(); | ||
| assertThat(databaseHelper_).isNull(); | ||
| assertThat(instanceCountInvoker.get()).isEqualTo(0); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think it is not really nice if we use
HasReceiverRegistration, because this code has nothing to do with receivers. I suggest to reintroduce the interface that i mentioned, and use it there instead ofHasReceiverRegistration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HasLifecycleMethods?Are you sure that the interface should have
onDestroyBeforeSuperBlockmethod?If not, how can I insert
OpenHelperManager.releasein the onDestroy method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that
HasLifecycleMethodsshould not haveonDestroyBeforeSuperBlock? Why?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the
OrmliteDaoHandlercan handle two scenarios: with anonDestorymethod or not.We cannot create
getOnDestroyintoHasLifecycleMethods, thus will be ignore annother scenario.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EBeanand@EActivitycan use it well. But@EBeandoes not have a onDestroy methodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean we should only add
onDestroyXXXin theHasLifecycleMethods?So that it conforms to the ISP? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't get me wrong, I just confirm that I understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, it would be seen as redundant to you, because basically everyting which is a
HasLifecycleMethodsisHasReceiverRegistration, too. But i still think this is better design. This is what i propose:create a new
HasLifecycleMethodsinterface:Let
HasReceiverRegistrationextendHasLifecycleMethods, and remove redundant method declarations:Use
HasLifecycleMethodsinOrmLiteHelper:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. You're right!
In fact, the most perfect solution i think is split into four interface:
HasLifecycleMethods/HasStartAndStopMethods/HasAttachableMethods/HasReceiverRegistration.There is no connection between them.
EActivityHolderandEFragmentHolderneed implement:HasLifecycleMethods,HasStartAndStopMethods,HasAttachableMethodsandHasReceiverRegistrationEServiceHolderneed implement:HasLifecycleMethodsandHasReceiverRegistrationIn
ReceiverHandler.registerAndUnregisterReceivermethod, we can add two method with the same name.These methods are respectively corresponding to these Interface.
However, this is a huge change. I think to do as you say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we could split it even further, but i think my proposal will suffice
for now.