data-access

simple jdbc wrapper

不想你离开。 提交于 2019-11-30 11:46:28
To implement data access code in our application we need some framework to wrap around jdbc (ORM is not our choice, because of scalability). The coolest framework I used to work with is Spring-Jdbc . However, the policy of my company is to avoid external dependencies, especially spring, J2EE, etc. So we are thinking about writing own handy-made jdbc framework, with functionality similar Spring-jdbc: row mapping, error handling, supporting features of java5, but without transaction support. Does anyone have experience of writing such jdbc wrapper framework? If anyone has experience of using

Reading parts of large files from drive

余生长醉 提交于 2019-11-29 11:19:59
I'm working with large files in C# (can be up to 20%-40% of available memory) and I will only need small parts of the files to be loaded into memory at a time (like 1-2% of the file). I was thinking that using a FileStream would be the best option, but idk. I will need to give a starting point (in bytes) and a length (in bytes) and copy that region into a byte[]. Access to the file might need to be shared between threads and will be at random spots in the file (non-linear access). I also need it to be fast. The project already has unsafe methods, so feel free to suggest things from the more

Saving multiple objects in a single call in rails

喜夏-厌秋 提交于 2019-11-28 14:35:59
问题 I have a method in rails that is doing something like this: a = Foo.new("bar") a.save b = Foo.new("baz") b.save ... x = Foo.new("123", :parent_id => a.id) x.save ... z = Foo.new("zxy", :parent_id => b.id) z.save The problem is this takes longer and longer the more entities I add. I suspect this is because it has to hit the database for every record. Since they are nested, I know I can't save the children before the parents are saved, but I would like to save all of the parents at once, and

What's Up with O(1)?

萝らか妹 提交于 2019-11-28 13:51:14
问题 I have been noticing some very strange usage of O(1) in discussion of algorithms involving hashing and types of search, often in the context of using a dictionary type provided by the language system, or using dictionary or hash-array types used using array-index notation. Basically, O(1) means bounded by a constant time and (typically) fixed space. Some pretty fundamental operations are O(1), although using intermediate languages and special VMs tends to distort ones thinking here (e.g., how

Can I have an optional OUTPUT parameter in a stored procedure?

耗尽温柔 提交于 2019-11-28 10:39:19
I have a stored procedure that has a bunch of input and output parameters because it is Inserting values to multiple tables. In some cases the stored proc only inserts to a single table (depending on the input parameters). Here is a mocked up scenario to illustrate. Tables / Data Objects: Person Id Name Address Name Id FirstName LastName Address Id Country City Say I have a stored procedure that inserts a person. If the address doesn't exist I won't add it to the Address table in the database. Thus when I generate the code to call the stored procedure I don't want to bother adding the Address

Is it bad practice to run tests on a database instead of on fake repositories?

ε祈祈猫儿з 提交于 2019-11-28 09:54:15
I know what the advantages are and I use fake data when I am working with more complex systems. What if I am developing something simple and I can easily set up my environment in a real database and the data being accessed is so small that the access time is not a factor, and I am only running a few tests. Is it still important to create fake data or can I forget the extra coding and skip right to the real thing? When I said real database I do not mean a production database, I mean a test database, but using a real live DBMS and the same schema as the real database. Uncle Bob The reasons to

Data access, unit testing, dependency injection

為{幸葍}努か 提交于 2019-11-28 09:33:37
问题 I've recently got a task to create a simple utility that allows to import data from a file with special format to the database. I've implemented console application with few classes(Program class operates with business logic class, business logic class in turn operates with data access class). Everything works ok, but now I'm thinking about creating some unit tests and refactoring application (I have not created real unit tests before, just a bunch of integration tests a long time ago, so I

Reading parts of large files from drive

旧巷老猫 提交于 2019-11-28 04:49:04
问题 I'm working with large files in C# (can be up to 20%-40% of available memory) and I will only need small parts of the files to be loaded into memory at a time (like 1-2% of the file). I was thinking that using a FileStream would be the best option, but idk. I will need to give a starting point (in bytes) and a length (in bytes) and copy that region into a byte[]. Access to the file might need to be shared between threads and will be at random spots in the file (non-linear access). I also need

Execute multiple SQL commands in one round trip

狂风中的少年 提交于 2019-11-27 20:26:42
I am building an application and I want to batch multiple queries into a single round-trip to the database. For example, lets say a single page needs to display a list of users, a list of groups and a list of permissions. So I have stored procs (or just simple sql commands like "select * from Users"), and I want to execute three of them. However, to populate this one page I have to make 3 round trips. Now I could write a single stored proc ("getUsersTeamsAndPermissions") or execute a single SQL command "select * from Users;exec getTeams;select * from Permissions". But I was wondering if there

Should I use public or private variables?

淺唱寂寞╮ 提交于 2019-11-27 19:08:13
问题 I am doing a large project for the first time. I have lots of classes and some of them have public variables, some have private variables with setter and getter methods and same have both types. I decided to rewrite this code to use primarily only one type. But I don't know which I should use (variables which are used only for methods in the same object are always private and are not subject of this question). I know the theory what public and private means, but what is used in the real world