Merge branch 'features/database/databasehelper' into develop
This commit is contained in:
commit
ef981aee4b
Binary file not shown.
|
@ -25,7 +25,7 @@
|
|||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -5,7 +5,7 @@ android {
|
|||
defaultConfig {
|
||||
applicationId "com.example.monnthic.monnthicmobile"
|
||||
multiDexEnabled true
|
||||
minSdkVersion 19
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
@ -32,5 +32,8 @@ dependencies {
|
|||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
implementation 'org.web3j:core:3.3.1-android'
|
||||
implementation 'com.j256.ormlite:ormlite-android:4.48'
|
||||
implementation 'com.j256.ormlite:ormlite-core:5.1'
|
||||
implementation 'com.j256.ormlite:ormlite-jdbc:5.1'
|
||||
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@ import org.web3j.protocol.Web3j;
|
|||
import org.web3j.protocol.Web3jFactory;
|
||||
import org.web3j.protocol.core.methods.response.EthGetBalance;
|
||||
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
|
||||
import org.web3j.protocol.core.methods.request.Transaction;
|
||||
import org.web3j.protocol.http.HttpService;
|
||||
import org.web3j.protocol.core.DefaultBlockParameterName;
|
||||
import org.web3j.utils.Convert;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import monnethic.mobile.transaction.DbTransaction;
|
||||
import monnethic.mobile.transaction.Transaction;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -115,7 +114,7 @@ public class AccessBlockchain {
|
|||
return null;
|
||||
}
|
||||
|
||||
//Send DbTransaction demo function
|
||||
//Send Transaction demo function
|
||||
public static boolean sendTransationTo(String addressSource, String addressDestination, BigInteger amountToSend){
|
||||
Web3j n1 = Web3jFactory.build(new HttpService(node1));
|
||||
try{
|
||||
|
@ -126,7 +125,7 @@ public class AccessBlockchain {
|
|||
BigInteger gasLimit = gasPrice.multiply(BigInteger.valueOf(2));
|
||||
|
||||
BigInteger amountEther = Convert.toWei(amountToSend.toString(), Convert.Unit.ETHER).toBigInteger();
|
||||
Transaction transaction = Transaction.createEtherTransaction(coinbase, nonce, gasPrice, gasLimit, addressDestination, amountEther);
|
||||
org.web3j.protocol.core.methods.request.Transaction transaction = org.web3j.protocol.core.methods.request.Transaction.createEtherTransaction(coinbase, nonce, gasPrice, gasLimit, addressDestination, amountEther);
|
||||
String txUnit = "ETHER";
|
||||
|
||||
System.out.println("source : "+coinbase+"\nnonce : "+nonce+"\ngasPrice : "+gasPrice);
|
||||
|
@ -153,6 +152,6 @@ public class AccessBlockchain {
|
|||
|
||||
private void insertTransaction(String adS, String adD, BigInteger amTs, String txH, String blN, String txUnit){
|
||||
|
||||
DbTransaction dbTrs = new DbTransaction();
|
||||
Transaction dbTrs = new Transaction();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package monnethic.mobile.database;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import monnethic.mobile.transaction.Transaction;
|
||||
import monnethic.mobile.user.User;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
|
||||
public class DatabaseHelper {
|
||||
private static final String DATABASE_NAME = "monnethic";
|
||||
private static final String DATABASE_USER = "";
|
||||
private static final String DATABASE_PWD = "";
|
||||
private final static String DATABASE_URL = "jdbc:postgresql://37.187.101.44:5432/"+DATABASE_NAME;
|
||||
|
||||
|
||||
public ConnectionSource setupDatabaseConnection(){
|
||||
try{
|
||||
return new JdbcConnectionSource(DATABASE_URL, DATABASE_USER, DATABASE_PWD);
|
||||
}catch (Exception e){
|
||||
System.out.print("\n"+e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void insertTransaction(Transaction tx){
|
||||
try{
|
||||
//Dao<Transaction, Integer> dao = getDao(Transaction.class);
|
||||
//dao.create(tx);
|
||||
} catch(Exception exception){
|
||||
Log.e("DATABASE","Can't insert Transaction into Database", exception);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package monnethic.mobile.database;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Log;
|
||||
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
|
||||
import monnethic.mobile.transaction.DbTransaction;
|
||||
|
||||
public class DatabaseManager extends OrmLiteSqliteOpenHelper{
|
||||
private static final String DATABASE_NAME = "WalletTransaction.db";
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
public DatabaseManager(Context context){
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
|
||||
try{
|
||||
TableUtils.clearTable(connectionSource, DbTransaction.class);
|
||||
Log.i("DATABASE","onCreate invoked");
|
||||
}catch(Exception exception){
|
||||
Log.e("DATABASE","Can't create Database", exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
|
||||
try{
|
||||
TableUtils.dropTable(connectionSource, DbTransaction.class, true);
|
||||
onCreate(database, connectionSource);
|
||||
Log.i("DATABASE","onUpdate invoked");
|
||||
}catch(Exception exception){
|
||||
Log.e("DATABASE","Can't update Database", exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertTransaction(DbTransaction tx){
|
||||
try{
|
||||
Dao<DbTransaction, Integer> dao = getDao(DbTransaction.class);
|
||||
dao.create(tx);
|
||||
} catch(Exception exception){
|
||||
Log.e("DATABASE","Can't insert DbTransaction into Database", exception);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package monnethic.mobile.database;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "T_TEST")
|
||||
public class DatabaseTest {
|
||||
public static final String NAME_FIELD_NAME = "name";
|
||||
public static final String ID_FIELD_NAME = "id";
|
||||
|
||||
@DatabaseField(columnName = ID_FIELD_NAME, id = true)
|
||||
private int id;
|
||||
@DatabaseField(columnName = NAME_FIELD_NAME, canBeNull = false)
|
||||
private String name;
|
||||
|
||||
public DatabaseTest(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DatabaseTest() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ import java.math.BigInteger;
|
|||
import java.util.Date;
|
||||
|
||||
@DatabaseTable(tableName = "T_TRANSACTION")
|
||||
public class DbTransaction {
|
||||
public class Transaction {
|
||||
@DatabaseField(columnName = "transactionId", generatedId = true, unique = true)
|
||||
private int id;
|
||||
@DatabaseField(columnName = "transactionDate")
|
||||
|
@ -25,11 +25,11 @@ public class DbTransaction {
|
|||
@DatabaseField(columnName = "transactionUnit")
|
||||
private String unit;
|
||||
|
||||
public DbTransaction() {
|
||||
public Transaction() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DbTransaction(Date transactionDate, String sourceAddress, String destAddress, String transactionHash, String blockNumber, BigInteger amount, String unit) {
|
||||
public Transaction(Date transactionDate, String sourceAddress, String destAddress, String transactionHash, String blockNumber, BigInteger amount, String unit) {
|
||||
super();
|
||||
this.transactionDate = transactionDate;
|
||||
this.sourceAddress = sourceAddress;
|
|
@ -1,51 +1,21 @@
|
|||
package monnethic.mobile.user;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by Guillaume on 15/04/2018.
|
||||
*/
|
||||
|
||||
|
||||
public class User {
|
||||
private int userId;
|
||||
private String name;
|
||||
private String firstname;
|
||||
private String email;
|
||||
private String password;
|
||||
private Date creationDate;
|
||||
private Date modificationDate;
|
||||
private boolean verified;
|
||||
private boolean approved;
|
||||
|
||||
public User(String name, String firstname, String email, String password) {
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package monnethic.mobile.test.database;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import org.junit.Test;
|
||||
import monnethic.mobile.database.DatabaseHelper;
|
||||
import monnethic.mobile.database.DatabaseTest;
|
||||
|
||||
|
||||
//Testing class for postgresql connection
|
||||
public class DatabaseHelperTest {
|
||||
private DatabaseHelper dbh = new DatabaseHelper();
|
||||
|
||||
//Test connection by getting existing data in T_TEST
|
||||
@Test
|
||||
public void TestConnection(){
|
||||
Dao<DatabaseTest, Integer> testDao;
|
||||
try{
|
||||
testDao = DaoManager.createDao(dbh.setupDatabaseConnection(),DatabaseTest.class);
|
||||
DatabaseTest dbt = testDao.queryForId(1);
|
||||
assert dbt != null;
|
||||
assert "thomas".equals(dbt.getName());
|
||||
}catch (Exception e){
|
||||
System.out.println("\n"+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue