Skip to content

Commit

Permalink
Added a new view, "KeyValueTable" onto XFlat tables
Browse files Browse the repository at this point in the history
Signed-off-by: gburgett <gordon.burgett@gmail.com>
  • Loading branch information
gburgett committed Mar 30, 2013
1 parent c03f4c1 commit ec352e7
Show file tree
Hide file tree
Showing 30 changed files with 1,363 additions and 100 deletions.
19 changes: 15 additions & 4 deletions java/XFlat/src/com/thoughtworks/xstream/io/xml/JDom2Writer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Copyright 2013 Gordon Burgett and individual contributors
*
* 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 com.thoughtworks.xstream.io.xml;

import com.thoughtworks.xstream.io.naming.NameCoder;
Expand Down
8 changes: 8 additions & 0 deletions java/XFlat/src/org/xflatdb/xflat/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public interface Database {
*/
public <T> Table<T> getTable(Class<T> persistentClass, String name);

/**
* Gets the named table as a KeyValueTable, which can be used to store data
* as key-value pairs.
* @param name The name of the table.
* @return A table for manipulating rows of key-value data.
*/
public KeyValueTable getKeyValueTable(String name);

/**
* Gets the database's {@link TransactionManager}. The TransactionManager
* allows opening transactions in the database.
Expand Down
128 changes: 128 additions & 0 deletions java/XFlat/src/org/xflatdb/xflat/KeyValueTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright 2013 Gordon Burgett and individual contributors
*
* 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.xflatdb.xflat;

import java.util.List;
import org.xflatdb.xflat.query.XPathQuery;
import org.xflatdb.xflat.query.XPathUpdate;

/**
* This interface represents a "KeyValue" view to an XFlat table. The KeyValue
* view allows storing arbitrary convertible objects by key in the database.
* @author Gordon
*/
public interface KeyValueTable {

//CREATE
/**
* Inserts a key value pair as a row in the table.
* @param key The key to which the value is associated.
* @param row The value to insert as XML. Cannot be null.
* @throws DuplicateKeyException if a row with the given key already exists.
*/
public <T> void add(String key, T row)
throws DuplicateKeyException;

/**
* Puts a value with the given key in the database. If the value already
* exists, it is overwritten.
* @param <T>
* @param key The key to which the value is associated.
* @param row The new value for the row. Cannot be null.
*/
public <T> void set(String key, T row);

/**
* Puts a value with the given key in the database. If the value already
* exists, it is overwritten and the old value is returned.
* @param <T>
* @param key The key to which the value is associated.
* @param row The new value for the row. Cannot be null.
* @return The old value for the row, or null if it did not previously exist.
*/
public <T> T put(String key, T row);

//READ
/**
* Finds one value by key
* @param key The key to which the value is associated.
* @param clazz The type as which the value should be deserialized.
* @return The row value, or null if the row does not exist.
*/
public <T> T get(String key, Class<T> clazz);

/**
* Finds the first value matching the Xpath query.
* @param query The query to match.
* @param clazz The type as which the value should be deserialized.
* @return the value of the matched row, or null if no row was matched.
*/
public <T> T findOne(XPathQuery query, Class<T> clazz);

/**
* Gets a cursor over all the values matching the Xpath query.
* @param query The query to match.
* @param clazz The type as which the value should be deserialized.
* @return A cursor over each matching row.
*/
public <T> Cursor<T> find(XPathQuery query, Class<T> clazz);

/**
* Gets a list of all the values matching the Xpath query.
* This is the same as {@link #find(org.xflatdb.xflat.query.XPathQuery) }
* but without the hassle of a cursor.
* @param query The query to match.
* @param clazz The type as which the value should be deserialized.
* @return A list of all the matching values.
*/
public <T> List<T> findAll(XPathQuery query, Class<T> clazz);

//UPDATE
/**
* Replaces a value with the new value by ID. This is the same as "Save"
* in some other document databases.
* @param key The key to which the value is associated.
* @param newValue The new value to replace the old value.
*/
public <T> void replace(String key, T newValue)
throws KeyNotFoundException;

/**
* Applies an update to the data in a given row.
* @param key The key to which the value is associated.
* @param update The update to apply.
* @return true if the update actually applied, false if the row was found
* but the update did not select an existing document element.
* @throws KeyNotFoundException if the row does not exist.
*/
public boolean update(String key, XPathUpdate update)
throws KeyNotFoundException;

//DELETE
/**
* Deletes the row associated to the given key.
* @param key The key to which the value is associated.
*/
public void delete(String key)
throws KeyNotFoundException;

/**
* Deletes all rows matching the given query.
* @param query The query selecting elements to delete.
* @return the number of rows that were deleted.
*/
public int deleteAll(XPathQuery query);
}
1 change: 0 additions & 1 deletion java/XFlat/src/org/xflatdb/xflat/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.List;
import org.xflatdb.xflat.query.XPathQuery;
import org.xflatdb.xflat.query.XPathUpdate;
import org.jdom2.Element;

/**
* Represents a table in the database. A Table provides CRUD access to the underlying
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Copyright 2013 Gordon Burgett and individual contributors
*
* 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.xflatdb.xflat.convert.converters;

import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Copyright 2013 Gordon Burgett and individual contributors
*
* 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.xflatdb.xflat.convert.converters;

import java.beans.XMLDecoder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Copyright 2013 Gordon Burgett and individual contributors
*
* 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.xflatdb.xflat.convert.converters;

import com.thoughtworks.xstream.XStream;
Expand Down
Loading

0 comments on commit ec352e7

Please sign in to comment.