-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from gfx/embedded_type_as_foreign_key
Embedded type as foreign key
- Loading branch information
Showing
6 changed files
with
145 additions
and
16 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
library/src/test/java/com/github/gfx/android/orma/test/PrimaryKeyWithTypeAdapterTest.java
This file contains 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,71 @@ | ||
/* | ||
* Copyright (c) 2015 FUJI Goro (gfx). | ||
* | ||
* 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 com.github.gfx.android.orma.test; | ||
|
||
import com.github.gfx.android.orma.ModelFactory; | ||
import com.github.gfx.android.orma.test.model.ModelWithCustomPrimaryKey; | ||
import com.github.gfx.android.orma.test.model.OrmaDatabase; | ||
import com.github.gfx.android.orma.test.toolbox.EnumA; | ||
import com.github.gfx.android.orma.test.toolbox.OrmaFactory; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class PrimaryKeyWithTypeAdapterTest { | ||
|
||
OrmaDatabase db; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
db = OrmaFactory.create(); | ||
} | ||
|
||
@Test | ||
public void bigIntegerPrimaryKey() throws Exception { | ||
final ModelWithCustomPrimaryKey model = db | ||
.createModelWithCustomPrimaryKey(new ModelFactory<ModelWithCustomPrimaryKey>() { | ||
@NonNull | ||
@Override | ||
public ModelWithCustomPrimaryKey call() { | ||
return ModelWithCustomPrimaryKey.create(EnumA.FOO); | ||
} | ||
}); | ||
|
||
ModelWithCustomPrimaryKey.Holder holder = db.createHolder(new ModelFactory<ModelWithCustomPrimaryKey.Holder>() { | ||
@NonNull | ||
@Override | ||
public ModelWithCustomPrimaryKey.Holder call() { | ||
ModelWithCustomPrimaryKey.Holder holder = new ModelWithCustomPrimaryKey.Holder(); | ||
holder.object = model; | ||
return holder; | ||
} | ||
}); | ||
|
||
assertThat(holder.object.id, is(EnumA.FOO)); | ||
|
||
assertThat(db.selectFromHolder().objectEq(EnumA.FOO).value().object.id, is(EnumA.FOO)); | ||
assertThat(db.selectFromHolder().objectEq(model).value().object.id, is(EnumA.FOO)); | ||
} | ||
} |
This file contains 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
46 changes: 46 additions & 0 deletions
46
library/src/test/java/com/github/gfx/android/orma/test/model/ModelWithCustomPrimaryKey.java
This file contains 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,46 @@ | ||
/* | ||
* Copyright (c) 2015 FUJI Goro (gfx). | ||
* | ||
* 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 com.github.gfx.android.orma.test.model; | ||
|
||
import com.github.gfx.android.orma.annotation.Column; | ||
import com.github.gfx.android.orma.annotation.PrimaryKey; | ||
import com.github.gfx.android.orma.annotation.Table; | ||
import com.github.gfx.android.orma.test.toolbox.EnumA; | ||
|
||
// https://github.com/gfx/Android-Orma/issues/368 | ||
@Table | ||
public class ModelWithCustomPrimaryKey { | ||
|
||
@PrimaryKey | ||
public EnumA id; | ||
|
||
public static ModelWithCustomPrimaryKey create(EnumA id) { | ||
ModelWithCustomPrimaryKey model = new ModelWithCustomPrimaryKey(); | ||
model.id = id; | ||
return model; | ||
} | ||
|
||
@Table | ||
public static class Holder { | ||
|
||
@PrimaryKey | ||
public long id; | ||
|
||
@Column(indexed = true) | ||
public ModelWithCustomPrimaryKey object; | ||
} | ||
} |
This file contains 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 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 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