Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Initialize new Session using reflection instead of casting
Browse files Browse the repository at this point in the history
  • Loading branch information
Decky Fiyemonda committed Jun 5, 2018
1 parent a98b69d commit 1a7e059
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha03'
classpath 'com.android.tools.build:gradle:3.2.0-alpha16'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Additional libraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,24 @@ public String getRaw(){
return "{}";
}

public <T extends BaseItem> T get(){
public T get(){
T session = this.getOrNull();
if (session == null) {
return (T) new BaseItem();
try {
session = this.mSessionClass.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return session;
}

public <T extends BaseItem> T getOrNull(){
public T getOrNull(){
T session = null;
try {
session = (T) BaseItem.fromJson(this.getRaw(), this.mSessionClass);
session = T.fromJson(this.getRaw(), this.mSessionClass);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -91,7 +97,7 @@ public void set(String config) throws JSONException {
this.set(new JSONObject(config));
}

public void set(JSONObject config) throws JSONException {
public void set(JSONObject config) {
List session_list = this.getEntity(DB_SESSION.DAO_NAME)
.queryBuilder().limit(1)
.orderAsc(this.DbSessionIdProperty).list();
Expand All @@ -108,7 +114,7 @@ public void set(JSONObject config) throws JSONException {
this.getEntity(DB_SESSION.DAO_NAME).insertOrReplace(session);
}

public void set(BaseItem session) throws Exception {
public void set(T session) throws Exception {
this.set(BaseItem.toJson(session));
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 02 12:34:20 WIB 2017
#Tue Jun 05 16:03:35 WIB 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 comments on commit 1a7e059

Please sign in to comment.