Skip to content

Instantly share code, notes, and snippets.

@magro
magro / HelloMorphia.java
Created December 16, 2010 00:01
A hello world that shows how to use morphia with an immutable id type
import java.net.UnknownHostException;
import org.apache.commons.lang.builder.ToStringBuilder;
import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;
import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.converters.SimpleValueConverter;
import com.google.code.morphia.converters.TypeConverter;
@magro
magro / MongoDBUpdateFieldByAnotherField.java
Created March 10, 2011 22:24
MongoDB hello: Shows how to update a field with the value of another field by using either eval (nolock, for mongodb >= 1.8) or map/reduce (mongodb 1.6).
package hello.mongodb;
import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MapReduceOutput;
@magro
magro / setup-jdk-alternatives.sh
Created April 25, 2011 12:47
Installs sun/oracle jdk stuff as alternatives, tested for fedora (14) 64bit (see also http://www.javakaffee.de/blog/2010/12/26/installing-java-on-fedora-using-alternatives/)
#!/bin/sh
#
# Installs sun/oracle jdk stuff as alternatives, tested for fedora (14) 64bit.
# See also http://www.javakaffee.de/blog/2010/12/26/installing-java-on-fedora-using-alternatives/
# Author: martin(dot)grotzke(at)googlemail(dot)com
if [ $# -ne 3 ]; then
echo 1>&2 "Usage: $0 <major-version> <minor-version> <priority>"
echo "E.g. $0 1.6.0 2 20000"
exit 127
@magro
magro / FullObjectCache.java
Created October 14, 2011 21:45
A simple cache that holds all entries for a given type and updates itself in the background to keep the cache up to date.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicReference;
@magro
magro / FullObjectEhCache.java
Created October 14, 2011 21:49
An ehcache backed cache that holds all entries for a given type and updates itself in the background to keep the cache up to date.
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
@magro
magro / CouchbaseMockTest.java
Created December 22, 2011 15:01
couchbasemock issue
package de.javakaffee.web.msm;
import java.net.URI;
import java.util.Arrays;
import net.spy.memcached.MemcachedClient;
import org.couchbase.mock.CouchbaseMock;
public class CouchbaseMockTest {
@magro
magro / MorphiaEmbeddedInheritanceTest.java
Created January 5, 2012 15:00
Test that shows a issue of morphia with an inheritance stucture of @Embedded objects.
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import com.google.code.morphia.Morphia;
import com.google.code.morphia.annotations.Converters;
import com.google.code.morphia.annotations.Embedded;
import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
@magro
magro / JmxInitListener.java
Last active December 16, 2015 04:09
This class allows you to start a jmx connector server in a way that allows to connect from the outside through a firewall: the rmi communication is bound to specific ports. Additionally this solution allows you to start several jvms with the same port configurations, as the rmi registry and the connector server will be bound to a specific ip add…
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@magro
magro / jboss.log
Created August 16, 2013 14:15
Log output of hibernate4 sample (https://github.com/magro/jboss-as-quickstart/tree/master/hibernate4) deployment in JBoss EAP 6.1 with TRACE level enabled for JPA
14:54:45,887 INFO [org.jboss.as.repository] (management-handler-thread - 1) JBAS014900: Content added at location /opt/jboss-eap-6.1_official/standalone/data/content/0a/40dca46c50291b27bf1fafe382d0a2be4994cf/content
14:54:45,901 INFO [org.jboss.web] (ServerService Thread Pool -- 51) JBAS018224: Unregister web context: /jboss-as-hibernate4
14:54:45,917 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 54) JBAS011403: Stopping Persistence Unit Service 'jboss-as-hibernate4.war#primary'
14:54:45,919 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 54) HHH000227: Running hbm2ddl schema export
14:54:45,921 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) JBAS016009: Stopping weld service for deployment jboss-as-hibernate4.war
14:54:45,925 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 54) HHH000230: Schema export complete
14:54:45,946 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-9) JBAS010409: Unbound data sour
@magro
magro / SpringSecurityUserRegistration.java
Last active December 21, 2015 21:48
A custom kryo serializer for the Spring Security User class - for memcached-session-manager's kryo serialization. Can be registered as customConverter in the msm config (see https://code.google.com/p/memcached-session-manager/wiki/SetupAndConfiguration), s.th. like: <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" ... tra…
package de.javakaffee.web.msm.serializer.kryo;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;