persistent

Java maintaining a persistent TCP connection

 ̄綄美尐妖づ 提交于 2019-12-05 10:13:08
问题 I am trying to send multiple data from server to client using TCP. I want to create only one TCP connection for the entire session. How do I go about doing this? I tried a code with the following flow, but the program stops after the first response is received. Client side 1.create sockets and streams 2.send request for first data 3.wait for response from server 4.send next request <----------- server doesn't seem to handle this request 5.get next response from server Server side 1.Create

How to store variables/preferences in Python for later use

半腔热情 提交于 2019-12-05 04:10:37
I'm working on a program in Python for Windows, and would like to save variables and user preferences so that I can recall them even after the program has been terminated and restarted. Is there an ideal way to do this on Windows machines? Would _winreg and the Windows registry be suited for this task? Or do I need to create some sort of database of my own? You're usually going to want to store it in a configuration folder in the "home" folder. That's easy on *nix systems, more difficult in windows, because you actually need to get the "application data" directory. This usually works for me:

Two classes with almost duplicate code inside

自古美人都是妖i 提交于 2019-12-05 02:20:28
问题 At this moment, I have two classes: UserHibernateDao and TicketHibernateDao : import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import model.dao.Dao; import model.entity.User; public class UserDaoHibernate extends HibernateDaoSupport implements Dao<User> { public User get(long id) { return getHibernateTemplate().get(User.class, id); } public void save(User user) { getHibernateTemplate().save(user); } public void remove(long id) {

Store existing data-type with Yesod's Persistent

ε祈祈猫儿з 提交于 2019-12-04 19:32:54
问题 All the tutorials and references that I could find about Persistent describe in great detail how Persistent can automatically create a new data-type, schema, migration, etc. out of a single definition in its DSL. However, I couldn't find an explanation on how to get Persistent to handle already existing data-types. An example: Suppose I have an already existing Haskell module for some game logic. It includes a record type for a player. (It's meant to be used through lenses, hence the

Foreign key constraints in Yesod/Persistent?

爷,独闯天下 提交于 2019-12-04 12:57:08
I am trying to use Database.Persistant to make a database for a Scotty app, and I cannot figure out the syntax for adding a foreign key constraint between tables. For example, I have a User table and a Post table, and I want the Post table to have an attribute authorId which references UserId in User . This can be accomplished quite easily in raw SQL, but I want to be able to access the data through haskell without resorting to raw sql commands. Also, the constraints would be overwritting upon database migrations. This is what I have at the moment to define the database: share [mkPersist

MaybeT and Transactions in runDb

a 夏天 提交于 2019-12-04 09:46:40
For my previous question on chaining failures, Michael Snoyman had suggested I use MaybeT to run them so if any of them fails, it will just short-circuit to Nothing . I was under the impression runDb runs everything in a transaction. So shouldn't a failure at any point in code automatically rollback the transaction? mauth <- runDb $ runMaybeT $ do valid <- MaybeT $ return $ listToMaybe errs uid <- MaybeT $ insertUnique u vid <- MaybeT $ getBy $ UniqueField v -- this step fails but previous insert does not roll back auth <- liftIO $ createAuthToken uid return auth When I run the above code, the

Haskell Persistent: how get entity from db by key if i have key in integer variable?

时间秒杀一切 提交于 2019-12-04 02:17:03
I use Persistent orm with scotty web framework. I want to get value from db by id. These id are coming to me from GET request There are "get" function that takes "Key Entity" variable and returns "Maybe Entity". I use following code to get value from db k <- keyFromValues $ [(PersistInt64 myOwnIntVarFromRequest)] case k of Left _ -> {-some processing-} Right x -> do t <- liftIO . runDb $ get (x::Key Post) --Post is one of my models case t of Nothing -> {-processing-} Just x -> {-processing-} These code is extremly ugly. But i don't know how to do it better So my question is how obtain variable

MongoDB Example for Yesod / Persistent

孤街醉人 提交于 2019-12-04 02:10:24
Haskell and Yesod newbie here. I've been trying to follow the Integration with Yesod example from the Persistent chapter in the Yesod book (http://www.yesodweb.com/book/persistent). The Sqlite compiles and runs fine it seems. However, I'm trying to use MongDB and am having a hard time getting things to work. Specifically: In the example for sqlite: share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist| The Yesod book says "Mongo code will use mongoSettings instead." But I can't find it in any of the modules, and the code doesn't compile. So instead, I had to use this instead of

Setting persistent cookie from Java doesn't work in IE

我与影子孤独终老i 提交于 2019-12-03 19:34:34
问题 All, Although I see related topics on the forum, but I don't see a clear solution on this issue. I am trying to set a javax.servlet.http.Cookie with an expiration time (so that it persists across browser sessions). Code: public void respond(HttpServletRequest req, HttpServletResponse resp) { int expiration = 3600; Cookie cookie = new Cookie("TestCookie", "xyz"); cookie.setDomain(""); cookie.setVersion(0); cookie.setPath("/"); cookie.setMaxAge(expiration); cookie.setSecure(false); resp

Why pickle eat memory?

自古美人都是妖i 提交于 2019-12-03 19:26:44
问题 I trying to deal with writing huge amount of pickled data to disk by small pieces. Here is the example code: from cPickle import * from gc import collect PATH = r'd:\test.dat' @profile def func(item): for e in item: f = open(PATH, 'a', 0) f.write(dumps(e)) f.flush() f.close() del f collect() if __name__ == '__main__': k = [x for x in xrange(9999)] func(k) open() and close() placed inside loop to exclude possible causes of accumulation of data in memory. To illustrate problem I attach results