adding beginnings of some common abstractions

This commit is contained in:
trisberg
2010-07-19 15:40:39 -04:00
parent 6939db89a7
commit be8817f443
14 changed files with 213 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2010 the original author or authors.
*
* 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 "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.core;
/**
* Class used to map data to a business object.
*
* @author Thomas Risberg
* @since 1.0
*/
public interface DataMapper<S, T> {
T map(S source);
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2010 the original author or authors.
*
* 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 "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.core;
/**
* Class used to map a business object to an object providing the data value.
*
* @author Thomas Risberg
* @since 1.0
*/
public interface DataValueSource<S, T> {
T getValue(S source);
}

View File

@@ -0,0 +1,5 @@
package org.springframework.data.core;
public interface QueryDefinition {
}

View File

@@ -0,0 +1,31 @@
package org.springframework.datastore.core;
import java.util.List;
import org.springframework.data.core.DataMapper;
import org.springframework.data.core.QueryDefinition;
public abstract class AbstractDatastoreTemplate<C> {
protected DatastoreConnectionFactory<C> datastoreConnectionFactory;
public DatastoreConnectionFactory<C> getDatastoreConnectionFactory() {
return datastoreConnectionFactory;
}
public void setDatastoreConnectionFactory(DatastoreConnectionFactory<C> datastoreConnectionFactory) {
this.datastoreConnectionFactory = datastoreConnectionFactory;
}
public <T> T execute(DatastoreConnectionCallback<C, T> action) {
try {
return action.doInConnection(datastoreConnectionFactory.getConnection());
}
catch (Exception e) {
throw new UncategorizedDatastoreException("Failure executing using datastore connection", e);
}
}
public abstract <S, T> List<T> query(QueryDefinition query, DataMapper<S, T> mapper);
}

View File

@@ -0,0 +1,8 @@
package org.springframework.datastore.core;
import org.springframework.dao.DataAccessException;
public interface DatastoreConnectionCallback<C, T> {
T doInConnection(C con) throws DataAccessException;
}

View File

@@ -0,0 +1,5 @@
package org.springframework.datastore.core;
public interface DatastoreConnectionFactory<C> {
C getConnection();
}

View File

@@ -0,0 +1,12 @@
package org.springframework.datastore.core;
import org.springframework.dao.UncategorizedDataAccessException;
public class UncategorizedDatastoreException extends
UncategorizedDataAccessException {
public UncategorizedDatastoreException(String msg, Throwable cause) {
super(msg, cause);
}
}

View File

@@ -1,4 +1,4 @@
package org.springframework.data.serialization;
package org.springframework.datastore.serialization;
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;