Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Data MapR DB

Quick start

MapR Template

MapRTemplate is the central support class for MapR database operations.

Spring Data repositories

To simplify the creation of data repositories Spring Data MapR DB provides a generic repository programming model. It will automatically create a repository proxy for you.

public interface UserRepository extends MapRRepository <User, String> {
}

Configuration

You can use Java to configure your Spring Data environment as show below. Make sure that folder for database is created and you have permissions for write in this folder.

@Configuration
@EnableMapRRepository
class Config extends AbstractMapRConfiguration {

    @Override
    protected String getDatabaseName() { 
        return "DB_FOLDER_NAME";
    }

    @Override
    protected String getHost() {
        return "HOST";
    }

    @Override
    protected String getUsername() {
        return "USERNAME";
    }

    @Override
    protected String getPassword() {
        return "PASSWORD";
    }

}

Entity

Mark your entity with annotation @Document, then table's name will be generated by class name, or you can specify custom name for table by annotation's parameter(@Document("TABLE_NAME")). Add @Id annotation before ID field.

@Document
//@Document("TABLE_NAME")
public class User {
    @Id
    private String id;
    
    private String name;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Service example

You can use repository as shown below:

@Service
public class MyService {
    
    private final UserRepository userRepository;
    
    @Autowired
    public MyService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }
    
    public void doWork() {
    
         userRepository.deleteAll();
    
         User user = new User();
         user.setId("test_id");
         user.setName("Test user");
         
         userRepository.save(user);
         
         User userById = userRepository.findById("test_id").get();
     }
}

Ordering with Spring Data

As Spring Data implementation for MaprDB uses OJAI you have to configure Drill for ordering. Querying in OJAI Applications

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages