Skip to content

Commit

Permalink
pom updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nicol committed Sep 10, 2023
1 parent 6ddac25 commit d6d688a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<jwt.version>0.11.5</jwt.version>
<lucene.version>9.7.0</lucene.version>
<artemis.version>2.30.0</artemis.version>
<flatlaf.version>3.2</flatlaf.version>
<flatlaf.version>3.2.1</flatlaf.version>
<qwartz.version>2.5.0-rc1</qwartz.version>
<rome.version>2.1.0</rome.version>
<log4j.version>2.20.0</log4j.version>
Expand Down Expand Up @@ -458,7 +458,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
Expand Down
66 changes: 54 additions & 12 deletions src/main/java/org/beta/RedisDAO.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.beta;

import java.sql.SQLException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -21,13 +22,20 @@
import org.magic.api.beans.shop.Transaction;
import org.magic.api.beans.technical.ConverterItem;
import org.magic.api.beans.technical.GedEntry;
import org.magic.api.beans.technical.audit.DAOInfo;
import org.magic.api.interfaces.MTGSerializable;
import org.magic.api.interfaces.abstracts.extra.AbstractKeyValueDao;
import org.magic.services.TechnicalServiceManager;
import org.magic.services.tools.IDGenerator;
import org.magic.services.tools.POMReader;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.event.command.CommandBaseEvent;
import io.lettuce.core.event.command.CommandFailedEvent;
import io.lettuce.core.event.command.CommandListener;
import io.lettuce.core.event.command.CommandStartedEvent;
import io.lettuce.core.event.command.CommandSucceededEvent;

public class RedisDAO extends AbstractKeyValueDao {

Expand Down Expand Up @@ -55,10 +63,44 @@ public String getVersion() {
@Override
public void init() throws SQLException {
redisClient = RedisClient.create(getDBLocation());

var listener = new CommandListener() {

DAOInfo obj;


@Override
public void commandStarted(CommandStartedEvent event) {
obj = new DAOInfo();
obj.setQuery(event.getCommand().toString());
}

@Override
public void commandFailed(CommandFailedEvent event) {
obj.setMessage(event.getCause().getMessage());
save(event);
}

@Override
public void commandSucceeded(CommandSucceededEvent event) {
save(event);
}

private void save(CommandBaseEvent event) {
obj.setEnd(Instant.now());

TechnicalServiceManager.inst().store(obj);

}
};

redisClient.addListener(listener);
connection = redisClient.connect();
syncCommands = connection.sync();




saveCollection(new MagicCollection("Library"));

}
Expand Down Expand Up @@ -435,34 +477,34 @@ public void changePassword(Contact c, String newPassword) throws SQLException {



//TODO found how to remove element from sets
@Override
public void removeCard(MagicCard mc, MagicCollection collection) throws SQLException {
//TODO doesn't work. find index set
var k = key(collection,mc.getCurrentSet());
var opt = syncCommands.smembers(k).stream().map(str->serialiser.fromJson(str, MagicCard.class)).filter(c->c.equals(mc)).findFirst();

if(opt.isPresent())
{
var ret= syncCommands.srem(k, serialiser.toJson(opt.get()));
logger.info("remove element index at {}",ret);
}
syncCommands.srem(k, serialiser.toJson(mc));
}




@Override
public List<Transaction> listTransactions(Contact c) throws SQLException {
// TODO Auto-generated method stub
return new ArrayList<>();
return listTransactions().stream().filter(t->t.getContact().getId()==c.getId()).collect(Collectors.toList());
}



@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
// TODO Auto-generated method stub
return new ArrayList<>();
var c = new ArrayList<MagicCollection>();

for(var collection : listCollections())
{
if(listCardsFromCollection(collection).stream().anyMatch(card->card.getId().equals(mc.getId())))
c.add(collection);
}
return c;

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ private MagicCard generateCardsFromRs(ResultSet rs,boolean load) throws SQLExcep
mc.setReprintedCard(rs.getBoolean(IS_REPRINT));
mc.setReserved(rs.getBoolean(IS_RESERVED));
mc.setFlavorName(rs.getString(FLAVOR_NAME));
mc.setSide(rs.getString(SIDE));
mc.setSide(rs.getString(SIDE)!=null?rs.getString(SIDE):"a");
mc.setStorySpotlight(rs.getBoolean(IS_STORY_SPOTLIGHT));
mc.setHasAlternativeDeckLimit(rs.getBoolean(HAS_ALTERNATIVE_DECK_LIMIT));
mc.setFullArt(rs.getBoolean(IS_FULLART));
Expand Down

0 comments on commit d6d688a

Please sign in to comment.