Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Added example using @HelenaColumnBean implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Hjort authored and marcust committed Oct 13, 2010
1 parent 64d09df commit fae3ea8
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 31 deletions.
74 changes: 74 additions & 0 deletions src/org/thiesen/helenaorm/example/Attendance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* The MIT License
*
* Copyright (c) 2010 Marcus Thiesen (marcus@thiesen.org)
*
* This file is part of HelenaORM.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.thiesen.helenaorm.example;

import org.thiesen.helenaorm.annotations.ColumnProperty;
import org.thiesen.helenaorm.annotations.HelenaColumnBean;
import org.thiesen.helenaorm.annotations.KeyProperty;
import org.thiesen.helenaorm.annotations.ValueProperty;

@HelenaColumnBean(keyspace = "Keyspace1", columnFamily = "Standard1")
public class Attendance {

@KeyProperty
private String user;

@ColumnProperty
private String event;

@ValueProperty
private Long time;

public String getUser() {
return user;
}

public void setUser(String user) {
this.user = user;
}

public String getEvent() {
return event;
}

public void setEvent(String event) {
this.event = event;
}

public Long getTime() {
return time;
}

public void setTime(Long time) {
this.time = time;
}

@Override
public String toString() {
return "Attendance [user=" + user + ", event=" + event + ", time=" + time + "]";
}

}
98 changes: 67 additions & 31 deletions src/org/thiesen/helenaorm/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,55 @@
import java.util.List;
import java.util.UUID;

import org.thiesen.helenaorm.HelenaColumnDAO;
import org.thiesen.helenaorm.HelenaDAO;
import org.thiesen.helenaorm.HelenaORMDAOFactory;
import org.thiesen.helenaorm.SerializeUnknownClasses;

import com.google.common.collect.ImmutableList;


public class Main {

public static void main( final String... args ) {
simpleExample();
superColumnExample();
columnValueExample();
}

private static void simpleExample() {

final HelenaORMDAOFactory factory = HelenaORMDAOFactory.withConfig(
"localhost",
9160,
SerializeUnknownClasses.YES );

final PublicEvent exampleEvent = new PublicEvent();
exampleEvent.setName( "Session im Irish Rover" );
exampleEvent.setDescription( "Gute Irische Livemusik" );
exampleEvent.setId( UUID.randomUUID() );
exampleEvent.setUrl( URI.create( "http://www.thiesen.org" ) );
exampleEvent.setType( EventType.CONCERT );

final HelenaDAO<PublicEvent> dao = factory.makeDaoForClass( PublicEvent.class );

dao.insert( exampleEvent );

System.out.println( "Stored as " + exampleEvent.getId() );

final PublicEvent publicEvent = dao.get( exampleEvent.getId().toString() );

System.out.println( publicEvent );

final List<PublicEvent> events = dao.get( ImmutableList.of( exampleEvent.getId().toString() ) );

System.out.println( events );

dao.delete( exampleEvent );
}

private static void superColumnExample() {
final User admin = new User();

final User admin = new User();
admin.setType( UserType.ADMINISTRATOR );
admin.setFirstname( "Emil" );
admin.setLastname("Admin");
Expand All @@ -56,20 +89,17 @@ private static void superColumnExample() {
normalUser.setLastname( "Example" );
normalUser.setUsername( "joex20" );


final User normalUseress = new User();
normalUseress.setType( UserType.USER );
normalUseress.setFirstname( "Jane" );
normalUseress.setLastname( "Example" );
normalUseress.setUsername( "jane73" );


final HelenaORMDAOFactory factory = HelenaORMDAOFactory.withConfig(
"localhost",
9160,
SerializeUnknownClasses.NO );


final HelenaDAO<User> userDAO = factory.makeDaoForClass( User.class );

userDAO.insert( admin );
Expand All @@ -79,34 +109,40 @@ private static void superColumnExample() {
System.out.println( userDAO.get( UserType.USER.toString(), ImmutableList.of( "jane73", "joex20" ) ) );
}

private static void simpleExample() {
final HelenaORMDAOFactory factory = HelenaORMDAOFactory.withConfig(
private static void columnValueExample() {

final HelenaORMDAOFactory factory = HelenaORMDAOFactory.withConfig(
"localhost",
9160,
SerializeUnknownClasses.YES );

final PublicEvent exampleEvent = new PublicEvent();
exampleEvent.setName( "Session im Irish Rover" );
exampleEvent.setDescription( "Gute Irische Livemusik" );
exampleEvent.setId( UUID.randomUUID() );
exampleEvent.setUrl( URI.create( "http://www.thiesen.org" ) );
exampleEvent.setType( EventType.CONCERT );

final HelenaDAO<PublicEvent> dao = factory.makeDaoForClass( PublicEvent.class );

dao.insert( exampleEvent );

System.out.println( "Stored as " + exampleEvent.getId() );

final PublicEvent publicEvent = dao.get( exampleEvent.getId().toString() );

System.out.println( publicEvent );

final List<PublicEvent> events = dao.get( ImmutableList.of( exampleEvent.getId().toString() ) );

System.out.println( events );

dao.delete( exampleEvent );

final HelenaColumnDAO<Attendance> attDAO = factory.makeColumnDaoForClass( Attendance.class );

final String[] users = {"joex20", "jane73", "iso263"};

for (String user : users) {
for (int i = 1; i <= 3; i++) {

Attendance att = new Attendance();
att.setUser(user);
att.setEvent(UUID.randomUUID().toString());
att.setTime(System.currentTimeMillis());

System.out.println("Inserting attendance: " + att);
attDAO.insert(att);
}
}

for (String user : users) {
for (String event : attDAO.getColumns(user)) {
System.out.println("User '" + user + "' attended to event '" + event + "'");

Attendance att = new Attendance();
att.setUser(user);
att.setEvent(event);
attDAO.delete(att);
}
}
}

}
}

0 comments on commit fae3ea8

Please sign in to comment.