@ -3,6 +3,7 @@ package org.qortal.repository.hsqldb;
import org.qortal.arbitrary.misc.Service ;
import org.qortal.arbitrary.misc.Service ;
import org.qortal.data.arbitrary.ArbitraryResourceInfo ;
import org.qortal.data.arbitrary.ArbitraryResourceInfo ;
import org.qortal.crypto.Crypto ;
import org.qortal.crypto.Crypto ;
import org.qortal.data.arbitrary.ArbitraryResourceNameInfo ;
import org.qortal.data.network.ArbitraryPeerData ;
import org.qortal.data.network.ArbitraryPeerData ;
import org.qortal.data.transaction.ArbitraryTransactionData ;
import org.qortal.data.transaction.ArbitraryTransactionData ;
import org.qortal.data.transaction.ArbitraryTransactionData.* ;
import org.qortal.data.transaction.ArbitraryTransactionData.* ;
@ -279,9 +280,10 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
}
}
@Override
@Override
public List < ArbitraryResourceInfo > getArbitraryResources ( Service service , String identifier ,
public List < ArbitraryResourceInfo > getArbitraryResources ( Service service , String identifier , String name ,
boolean defaultResource , Integer limit , Integer offset , Boolean reverse ) throws DataException {
boolean defaultResource , Integer limit , Integer offset , Boolean reverse ) throws DataException {
StringBuilder sql = new StringBuilder ( 512 ) ;
StringBuilder sql = new StringBuilder ( 512 ) ;
List < Object > bindParams = new ArrayList < > ( ) ;
sql . append ( "SELECT name, service, identifier FROM ArbitraryTransactions WHERE 1=1" ) ;
sql . append ( "SELECT name, service, identifier FROM ArbitraryTransactions WHERE 1=1" ) ;
@ -292,14 +294,19 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
if ( defaultResource ) {
if ( defaultResource ) {
// Default resource requested - use NULL identifier
// Default resource requested - use NULL identifier
// The AND ? IS NULL AND ? IS NULL is a hack to make use of the identifier params in checkedExecute()
sql . append ( " AND identifier IS NULL" ) ;
identifier = null ;
sql . append ( " AND (identifier IS NULL AND ? IS NULL AND ? IS NULL)" ) ;
}
}
else {
else {
// Non-default resource requested
// Non-default resource requested
// Use an exact match identifier, or list all if supplied identifier is null
// Use an exact match identifier, or list all if supplied identifier is null
sql . append ( " AND (identifier = ? OR (? IS NULL))" ) ;
sql . append ( " AND (identifier = ? OR (? IS NULL))" ) ;
bindParams . add ( identifier ) ;
bindParams . add ( identifier ) ;
}
if ( name ! = null ) {
sql . append ( " AND name = ?" ) ;
bindParams . add ( name ) ;
}
}
sql . append ( " GROUP BY name, service, identifier ORDER BY name" ) ;
sql . append ( " GROUP BY name, service, identifier ORDER BY name" ) ;
@ -312,12 +319,12 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
List < ArbitraryResourceInfo > arbitraryResources = new ArrayList < > ( ) ;
List < ArbitraryResourceInfo > arbitraryResources = new ArrayList < > ( ) ;
try ( ResultSet resultSet = this . repository . checkedExecute ( sql . toString ( ) , identifier , identifier ) ) {
try ( ResultSet resultSet = this . repository . checkedExecute ( sql . toString ( ) , bindParams . toArray ( ) ) ) {
if ( resultSet = = null )
if ( resultSet = = null )
return null ;
return null ;
do {
do {
String name = resultSet . getString ( 1 ) ;
String nameResult = resultSet . getString ( 1 ) ;
Service serviceResult = Service . valueOf ( resultSet . getInt ( 2 ) ) ;
Service serviceResult = Service . valueOf ( resultSet . getInt ( 2 ) ) ;
String identifierResult = resultSet . getString ( 3 ) ;
String identifierResult = resultSet . getString ( 3 ) ;
@ -327,7 +334,7 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
}
}
ArbitraryResourceInfo arbitraryResourceInfo = new ArbitraryResourceInfo ( ) ;
ArbitraryResourceInfo arbitraryResourceInfo = new ArbitraryResourceInfo ( ) ;
arbitraryResourceInfo . name = name ;
arbitraryResourceInfo . name = nameResult ;
arbitraryResourceInfo . service = serviceResult ;
arbitraryResourceInfo . service = serviceResult ;
arbitraryResourceInfo . identifier = identifierResult ;
arbitraryResourceInfo . identifier = identifierResult ;
@ -340,6 +347,64 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
}
}
}
}
@Override
public List < ArbitraryResourceNameInfo > getArbitraryResourceCreatorNames ( Service service , String identifier ,
boolean defaultResource , Integer limit , Integer offset , Boolean reverse ) throws DataException {
StringBuilder sql = new StringBuilder ( 512 ) ;
sql . append ( "SELECT name FROM ArbitraryTransactions WHERE 1=1" ) ;
if ( service ! = null ) {
sql . append ( " AND service = " ) ;
sql . append ( service . value ) ;
}
if ( defaultResource ) {
// Default resource requested - use NULL identifier
// The AND ? IS NULL AND ? IS NULL is a hack to make use of the identifier params in checkedExecute()
identifier = null ;
sql . append ( " AND (identifier IS NULL AND ? IS NULL AND ? IS NULL)" ) ;
}
else {
// Non-default resource requested
// Use an exact match identifier, or list all if supplied identifier is null
sql . append ( " AND (identifier = ? OR (? IS NULL))" ) ;
}
sql . append ( " GROUP BY name ORDER BY name" ) ;
if ( reverse ! = null & & reverse ) {
sql . append ( " DESC" ) ;
}
HSQLDBRepository . limitOffsetSql ( sql , limit , offset ) ;
List < ArbitraryResourceNameInfo > arbitraryResources = new ArrayList < > ( ) ;
try ( ResultSet resultSet = this . repository . checkedExecute ( sql . toString ( ) , identifier , identifier ) ) {
if ( resultSet = = null )
return null ;
do {
String name = resultSet . getString ( 1 ) ;
// We should filter out resources without names
if ( name = = null ) {
continue ;
}
ArbitraryResourceNameInfo arbitraryResourceNameInfo = new ArbitraryResourceNameInfo ( ) ;
arbitraryResourceNameInfo . name = name ;
arbitraryResources . add ( arbitraryResourceNameInfo ) ;
} while ( resultSet . next ( ) ) ;
return arbitraryResources ;
} catch ( SQLException e ) {
throw new DataException ( "Unable to fetch arbitrary transactions from repository" , e ) ;
}
}
// Peer file tracking
// Peer file tracking