java


Where to write and store mongoDB map/reduce functions in java project


Does anyone have any advice, or know of any best practice for where and how in a Java project to write and store javascript map/reduce functions for use with a MongoDB database?
The criteria I'm looking for are:
When writing and editing the functions I'd like the benefit of syntax highlighting and error checking provided by an IDE (I'm using Eclipse).
I don't want to have to copy the functions to a different location when I'm finished editing them, if possible.
I'd rather store the functions in the source code than the DB itself, for ease of reference, version control, etc.
Any examples of how you've solved this problem would be great.
EDIT: I'm not sure I've explained myself properly, so here's another go:
I'm not asking about basic resource management. What I'm after is, if possible, a working environment that allows me the benefits of my IDE while editing the functions 'in place'. You'll have to excuse me if I'm missing something blindingly obvious.
What I want to avoid are things such as you might see with SQL, such as when its stored as a String in a class file:
private static final String MAP_FUNC =
"function() { " +
" emit(this.id, {total : this.total}); " +
"};";
or in a java properties file:
map.func=function() {
\ emit(this.id, {total : this.total});
\ };
where you have to enter a load of extraneous characters such as "s and \s. You have to write it somewhere else, then copy and paste it in and add these characters in (or you might have a tool that does it for you - you still have to do it).
Since javascript is validated by Eclipse when it's written in .js files, I don't want to have to do any of this. I'd like to store the functions in .js files in such a way as they are ready for easy consumption by a map/reduce call when needed.
Does anyone do this, or similar? My initial idea was just to create a single .js file for each function, however a .js file with nothing but an anonymous function in it fails validation in eclipse, which makes it pointless - you have to assign it to a var - which means its not in the correct form for consumption by map/reduce. I suppose I could create files of just the content of the functions? But all this sounds a bit messy, and I was hoping someone else might have come across the problem, and have a neat solution.
The convention I use and I've seen in most open source projects (including Spring et al) is to put all non-java files under a resources directory, under a descriptive directory:
module-root/
src/
main/
java/
(Java sources go here)
resources/
log4j.xml
spring/ (spring xmls go here)
sql/ (sql scripts go here)
mongo/ (<-- seems like a good place for mongoDB functions)
test/
unit/
java/ (unit test java sources go here)
resources/ (unit test specific resources - usually none)
integration/
java/ (integration test java sources go here)
resources/
spring/ (usually an ITestAssembly.xml goes here)
The buildfile then packs the resources into a resource jar, which gets deployed along wiht all the other jars.
We place the JS files as application resources in the (Eclipse) project and then upon application initialisation those files are read by the Java apps (either web app or daemons in our case), stored in a singleton management class and then used as needed when invoking, say, a map/reduce.
It's relatively straightforward resource management.

Related Links

How can I get List of nested objects using JpaRepository?
How to use rest API to login facebook in android
How can I run my Java program from different directory [duplicate]
How to style custom control inside a ListView in JavaFX
FFMPEG set -ss and -to with string
Collection Sort
How to store values in JSON with Spring sessions and Redis?
logback-spring.xml does not work when deloy on tomcat
Losing initial log events using log4j2 socket appender when destination disconnects tcp connection after idle time out
JfreeChart on JavaFX tooltips are shown in different locations
Android grid view on click listener get selected item
Display records from a database using stateless ejb
track idle time on Mac in Java
Using android-async-http to download a large file in android
More concise way to check for Integers in ArrayList?
Is it possible to assign the same xml-path value to multiple java attributes using MOXy?

Categories

HOME
gerrit
mockito
smarty
jira
sharepoint-designer
portia
add
windows-10-universal
usergrid
dynamics-crm-online
clearcase-ucm
libtiff
database-replication
google-cloud-speech
viewport
jtextfield
clickonce
arabic
sylius
excel-2007
zurb-foundation-6
tibco-mdm
crystal-reports-2010
microsoft-sync-framework
chromebook
ejabberd-module
nouislider
fabric8
directx-10
uisplitview
code-contracts
perlin-noise
overlap
suricata
retina-display
lto
objectlistview
unspecified
g-code
botbuilder
vao
apple-news
prolog-setof
errordocument
typescript1.8
tizen-native-app
svmlight
nativeapplication
typed-lambda-calculus
google-perftools
android-cursor
dtexec
sybase-asa
pillow
pdfclown
spring-cache
hittest
color-profile
or-tools
nested-sets
file-writing
gstreamer-0.10
connect-by
sigabrt
rvest
xpath-1.0
wapiti
ford-fulkerson
natvis
srand
maven-tomcat-plugin
msys
cyclomatic-complexity
appfabric-cache
processmodel
c++03
oxwall
gadt
knuth
google-style-guide
codeigniter-routing
id3v2
wordpress-theme-customize
uitouch
expected-exception
concurrent-collections
terminal-services
pushbackinputstream
seed
pygit2
type-equivalence
kyotocabinet
specification-pattern
chuck
libstdc++
quickdialog
pysimplesoap
postgresql-performance
pendrive
netdna-api
boost-filesystem
php-parser
spyware
xmemcached
gamma
preference
asp.net-profiles
vc90
sustainable-pace
defensive-programming
msdev
signal-handling

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App