2019-04-18 16:08:22 +02:00
package it.cavallium.strangedb.tests ;
import it.cavallium.strangedb.java.annotations.DbDataType ;
import it.cavallium.strangedb.java.annotations.DbField ;
import it.cavallium.strangedb.java.database.IDatabaseTools ;
import it.cavallium.strangedb.java.objects.EnhancedObject ;
import it.cavallium.strangedb.java.objects.lists.EnhancedObjectStrangeDbList ;
import java.io.IOException ;
import java.util.Random ;
2019-04-20 16:03:50 +02:00
import java.util.concurrent.* ;
2019-04-18 16:08:22 +02:00
public class ListContainer extends EnhancedObject {
@DbField ( id = 0 , type = DbDataType . ENHANCED_OBJECT )
public EnhancedObjectStrangeDbList < User > usersList ;
public ListContainer ( ) {
}
public ListContainer ( IDatabaseTools databaseTools , int count ) throws IOException {
super ( databaseTools ) ;
this . usersList = new EnhancedObjectStrangeDbList < > ( databaseTools , User . class ) ;
Random random = new Random ( ) ;
2019-04-22 00:10:21 +02:00
ExecutorService threadPool = Executors . newWorkStealingPool ( ) ;
2019-04-18 16:08:22 +02:00
for ( int i = 0 ; i < count ; i + + ) {
2019-04-20 16:03:50 +02:00
threadPool . execute ( ( ) - > {
try {
User usr ;
int randomInt = random . nextInt ( 2 ) ;
switch ( randomInt ) {
case 0 :
usr = new User ( databaseTools , " Rossi " + count + " Mario " + count , " the " + count + " _mariorossi99 " , " Long long big " + count + " giant bio mario rossi 99 abcdefghijklmnopqrstuvwxyz " ) ;
break ;
case 1 :
usr = new User ( databaseTools , QueryTests . constantFirstName , QueryTests . constantUsername , QueryTests . constantBio ) ;
break ;
case 2 :
usr = new User ( databaseTools , QueryTests . constantFirstName , " b " + count + " a " , QueryTests . constantBio ) ;
break ;
default :
throw new ArrayIndexOutOfBoundsException ( ) ;
}
this . usersList . add ( usr ) ;
} catch ( IOException ex ) {
throw new CompletionException ( ex ) ;
}
} ) ;
}
threadPool . shutdown ( ) ;
try {
threadPool . awaitTermination ( Long . MAX_VALUE , TimeUnit . DAYS ) ;
} catch ( InterruptedException e ) {
throw new IOException ( e ) ;
2019-04-18 16:08:22 +02:00
}
}
}