2017-09-13 16:12:22 +00:00
package cy.agorise.crystalwallet.dao ;
2018-11-29 18:20:25 +00:00
import androidx.lifecycle.LiveData ;
import androidx.paging.DataSource ;
import androidx.room.Dao ;
import androidx.room.Insert ;
import androidx.room.OnConflictStrategy ;
import androidx.room.Query ;
2017-09-13 16:12:22 +00:00
2018-01-29 01:18:38 +00:00
import java.util.Date ;
2017-09-13 16:12:22 +00:00
import java.util.List ;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction ;
2018-05-22 01:38:05 +00:00
import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended ;
2017-09-13 16:12:22 +00:00
/ * *
* Created by Henry Varona on 12 / 9 / 2017.
* /
@Dao
public interface TransactionDao {
2018-06-17 02:17:27 +00:00
static final String transactionsQuery = "SELECT cct.*, cna.name AS user_account_name, c.name AS contact_name, banc.name AS bitshares_account_name FROM crypto_coin_transaction cct " +
2018-05-22 01:38:05 +00:00
"LEFT JOIN crypto_net_account cna ON cct.account_id = cna.id " +
"LEFT JOIN contact c ON c.id = (SELECT ca.contact_id FROM contact_address ca WHERE ca.address LIKE (CASE is_input WHEN 1 THEN cct.\"from\" ELSE cct.\"to\" END) LIMIT 1) " +
2018-06-17 02:17:27 +00:00
"LEFT JOIN bitshares_account_name_cache banc ON banc.account_id = (CASE is_input WHEN 1 THEN cct.\"from\" ELSE cct.\"to\" END) " +
2018-09-18 02:02:21 +00:00
"WHERE user_account_name LIKE '%'||:search||'%' OR contact_name LIKE '%'||:search||'%' OR cct.\"from\" LIKE '%'||:search||'%' OR cct.\"to\" LIKE '%'||:search||'%' OR banc.name LIKE '%'||:search||'%'" ;
2018-05-22 01:38:05 +00:00
2017-09-13 16:12:22 +00:00
@Query ( "SELECT * FROM crypto_coin_transaction" )
LiveData < List < CryptoCoinTransaction > > getAll ( ) ;
2017-09-17 00:41:10 +00:00
2018-05-22 01:38:05 +00:00
@Query ( transactionsQuery + " ORDER BY date DESC" )
2018-06-10 18:35:06 +00:00
DataSource . Factory < Integer , CryptoCoinTransactionExtended > transactionsByDate ( String search ) ;
2017-09-18 02:38:05 +00:00
2018-05-22 01:38:05 +00:00
@Query ( transactionsQuery + " ORDER BY amount DESC" )
2018-06-10 18:35:06 +00:00
DataSource . Factory < Integer , CryptoCoinTransactionExtended > transactionsByAmount ( String search ) ;
2018-04-12 01:37:49 +00:00
2018-05-22 01:38:05 +00:00
@Query ( transactionsQuery + " ORDER BY is_input DESC" )
2018-06-10 18:35:06 +00:00
DataSource . Factory < Integer , CryptoCoinTransactionExtended > transactionsByIsInput ( String search ) ;
2018-04-12 01:37:49 +00:00
2018-05-22 01:38:05 +00:00
@Query ( transactionsQuery + " ORDER BY `from` DESC" )
2018-06-10 18:35:06 +00:00
DataSource . Factory < Integer , CryptoCoinTransactionExtended > transactionsByFrom ( String search ) ;
2018-04-12 01:37:49 +00:00
2018-05-22 01:38:05 +00:00
@Query ( transactionsQuery + " ORDER BY `to` DESC" )
2018-06-10 18:35:06 +00:00
DataSource . Factory < Integer , CryptoCoinTransactionExtended > transactionsByTo ( String search ) ;
2018-04-12 01:37:49 +00:00
2017-11-21 02:24:48 +00:00
@Query ( "SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date DESC" )
2017-10-23 01:00:51 +00:00
LiveData < List < CryptoCoinTransaction > > getByIdAccountLiveData ( long idAccount ) ;
2017-11-21 02:24:48 +00:00
@Query ( "SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date DESC" )
2017-10-23 01:00:51 +00:00
List < CryptoCoinTransaction > getByIdAccount ( long idAccount ) ;
2017-10-16 00:23:44 +00:00
2017-11-22 01:26:24 +00:00
@Query ( "SELECT * FROM crypto_coin_transaction WHERE id = :id" )
2018-10-18 03:32:17 +00:00
LiveData < CryptoCoinTransaction > getByIdLiveData ( long id ) ;
@Query ( "SELECT * FROM crypto_coin_transaction WHERE id = :id" )
CryptoCoinTransaction getById ( long id ) ;
2017-11-22 01:26:24 +00:00
2018-01-29 01:18:38 +00:00
@Query ( "SELECT * FROM crypto_coin_transaction WHERE date = :date and 'from' = :from and 'to' = :to and amount = :amount " )
CryptoCoinTransaction getByTransaction ( Date date , String from , String to , long amount ) ;
2017-09-17 00:41:10 +00:00
@Insert ( onConflict = OnConflictStrategy . REPLACE )
2017-09-27 02:24:23 +00:00
public long [ ] insertTransaction ( CryptoCoinTransaction . . . transactions ) ;
2017-09-20 01:59:14 +00:00
@Query ( "DELETE FROM crypto_coin_transaction" )
public void deleteAllTransactions ( ) ;
2017-09-13 16:12:22 +00:00
}