http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/HeapDump.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/HeapDump.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/HeapDump.java deleted file mode 100644 index e9fb3f2..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/HeapDump.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2009 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import org.qi4j.api.entity.EntityReference; - -public class HeapDump -{ - static final long DATA_AREA_OFFSET = 256; - private static final String HEAP_DATA_FILENAME = "heap.data"; - - private static RandomAccessFile dataFile; - - public static void main( String[] args ) - throws Exception - { - File dataDirectory = new File( args[ 0 ] ).getAbsoluteFile(); - File dataDir = dataDirectory.getAbsoluteFile(); - File file = new File( dataDir, HEAP_DATA_FILENAME ); - dataFile = new RandomAccessFile( file, "rw" ); - - long position = 256; - dataFile.seek( position ); // skip maintenance block. - while( dataFile.getFilePointer() < dataFile.length() ) - { - int blockSize = dataFile.readInt(); - if( blockSize == -1 ) - { - break; - } - int usage = dataFile.readByte(); - if( usage != 0 ) - { - long instanceVersion = dataFile.readLong(); - int schemaVersion = dataFile.readInt(); - long refPos = dataFile.getFilePointer(); - String ref = readReference().identity(); - System.out.print( ref ); - dataFile.seek( refPos + 129 ); - long mirror = dataFile.readLong(); - if( usage == 2 ) - dataFile.seek( mirror ); - if( usage == 3 || usage == 4 ) - { - System.err.println( "Inconsistent Heap: " + usage + ", pos: " + position ); - System.err.flush(); - } - int dataSize = dataFile.readInt(); - byte[] data = new byte[ dataSize ]; - dataFile.read( data, 0, dataSize ); - System.out.println( new String( data, "UTF-8" ) ); - System.out.flush(); - } - position = position + blockSize; - dataFile.seek( position ); - } - } - - private static EntityReference readReference() - throws IOException - { - int idSize = dataFile.readByte(); - if( idSize < 0 ) - { - idSize = idSize + 256; // Fix 2's-complement negative values of bytes into unsigned 8 bit. - } - byte[] idData = new byte[idSize]; - dataFile.read( idData ); - dataFile.skipBytes( 128 - idSize ); - return new EntityReference( new String( idData ) ); - } -}
http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityFile.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityFile.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityFile.java deleted file mode 100644 index 69af039..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityFile.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import org.qi4j.api.entity.EntityReference; - -/** - * For Slot 0 - * [version] - 4 bytes - * [noOfEntries] - 4 bytes - * [slotSize] - 4 bytes - * - * For Slot 1..n - * [isExtended] - 1 byte - * [position] - 8 bytes - * [identity] - [slotSize-16] bytes - */ -public class IdentityFile -{ - private static final int CURRENT_VERSION = 1; - - private RandomAccessFile identityStore; - private int entries; - private int slotSize; - private boolean closed; - private BucketManager bucketManager; - - private IdentityFile( RandomAccessFile store, File bucketDir, int slotSize, int entries ) - throws IOException - { - this.closed = false; - identityStore = store; - bucketManager = new BucketManager( bucketDir ); - this.slotSize = slotSize; - this.entries = entries; - } - - int entries() - { - return entries; - } - - long find( EntityReference reference ) - throws IOException - { - if( closed ) - { - throw new IdentityFileClosedException(); - } - if( reference.identity().length() > slotSize - 16 ) - { - throw new IdentityTooLongException( reference ); - } - final int slot = getSlot( reference ); - identityStore.seek( slot * slotSize ); - boolean isExtended = identityStore.readBoolean(); - if( !isExtended ) - { - long pos = identityStore.readLong(); - String idString = identityStore.readUTF(); - if( idString.length() == 0 ) - { - return -1; - } - EntityReference foundReference = new EntityReference( idString ); - if( foundReference.equals( reference ) ) - { - return pos; - } - return -1; - } - RandomAccessFile buckets = bucketManager.get( slot ); - int next = 0; - while( next * slotSize < buckets.length() ) - { - buckets.seek( next * slotSize ); - boolean isUsed = buckets.readBoolean(); - long pos = buckets.readLong(); - EntityReference foundReference = new EntityReference( buckets.readUTF() ); - if( isUsed && foundReference.equals( reference ) ) - { - return pos; - } - next++; - } - return -1; - } - - void remember( EntityReference reference, long pos ) - throws IOException - { - if( closed ) - { - throw new IdentityFileClosedException(); - } - if( reference.identity().length() > slotSize - 16 ) - { - throw new IdentityTooLongException( reference ); - } - final int slot = getSlot( reference ); - identityStore.seek( slot * slotSize ); - boolean isExtended = identityStore.readBoolean(); - if( isExtended ) - { - RandomAccessFile bucket = bucketManager.get( slot ); - bucket.seek( 0 ); - int next = 0; - while( next * slotSize < bucket.length() ) - { - bucket.seek( next * slotSize ); - boolean isUsed = bucket.readBoolean(); - if( !isUsed ) - { - break; - } - next++; - } - bucket.seek( next * slotSize ); - bucket.writeBoolean( true ); - bucket.writeLong( pos ); - bucket.writeUTF( reference.identity() ); - fillExtras( bucket, next, slotSize ); - } - else - { - long existingPos = identityStore.readLong(); - if( existingPos == -1 ) - { - // Not used yet. - identityStore.seek( slot * slotSize ); - identityStore.writeBoolean( false ); - identityStore.writeLong( pos ); - identityStore.writeUTF( reference.identity() ); - } - else - { - // Move existing record over to a new bucket. - RandomAccessFile bucket = bucketManager.get( slot ); - bucket.seek( 0 ); - bucket.writeBoolean( true ); - bucket.writeLong( existingPos ); - bucket.writeUTF( identityStore.readUTF() ); - fillExtras( bucket, 0, slotSize ); - bucket.seek( slotSize ); - bucket.writeBoolean( true ); - bucket.writeLong( pos ); - bucket.writeUTF( reference.identity() ); - fillExtras( bucket, 1, slotSize ); - identityStore.seek( slot * slotSize ); - identityStore.writeBoolean( true ); - identityStore.writeLong( -1 ); - identityStore.writeUTF( "" ); - fillExtras( identityStore, slot, slotSize ); - } - } - } - - void drop( EntityReference reference ) - throws IOException - { - if( closed ) - { - throw new IdentityFileClosedException(); - } - if( reference.identity().length() > slotSize - 16 ) - { - throw new IdentityTooLongException( reference ); - } - final int slot = getSlot( reference ); - identityStore.seek( slot * slotSize ); - boolean isExtended = identityStore.readBoolean(); - if( isExtended ) - { - RandomAccessFile buckets = bucketManager.get( slot ); - int next = 0; - while( next * slotSize < buckets.length() ) - { - buckets.seek( next * slotSize ); - boolean isUsed = buckets.readBoolean(); - buckets.readLong(); //ignore, should probably be changed to skip(8); - EntityReference foundReference = new EntityReference( buckets.readUTF() ); - if( isUsed && foundReference.equals( reference ) ) - { - buckets.seek( next * slotSize ); - buckets.writeBoolean( false ); - return; - } - next++; - } - } - else - { - identityStore.readLong(); // ignore the pos - EntityReference foundReference = new EntityReference( identityStore.readUTF() ); - if( reference.equals( foundReference ) ) - { - // found, no erase. - identityStore.seek( slot * slotSize ); - identityStore.writeBoolean( false ); - identityStore.writeLong( -1 ); - identityStore.writeUTF( "" ); - fillExtras( identityStore, slot, slotSize ); - } - } - } - - private int getSlot( EntityReference identity ) - { - int hashCode = identity.hashCode(); - hashCode = hashCode < 0 ? -hashCode : hashCode; - return 1 + hashCode % entries; - } - - public void close() - throws IOException - { - bucketManager.close(); - identityStore.close(); - closed = true; - } - - private static void initialize( RandomAccessFile newFile, int entries, int slotSize ) - throws IOException - { - for( int i = 1; i <= entries + 1; i++ ) - { - newFile.seek( i * slotSize ); - newFile.writeBoolean( false ); // Extended - newFile.writeLong( -1 ); // Position - newFile.writeUTF( "" ); // Identity - fillExtras( newFile, i, slotSize ); - } - newFile.seek( 0 ); - newFile.writeInt( CURRENT_VERSION ); - newFile.writeInt( entries ); - newFile.writeInt( slotSize ); - } - - private static void fillExtras( RandomAccessFile accessFile, int slot, int slotSize ) - throws IOException - { - long pointer = accessFile.getFilePointer(); - long fillTo = ( slot + 1 ) * slotSize - 1; - long arraysize = fillTo - pointer; - if( arraysize < 0 ) - { - System.err.println( "Negative Array Size detected:" + arraysize ); - } - byte[] extras = new byte[(int) arraysize]; - accessFile.write( extras ); - } - - public static IdentityFile use( File identityDir ) - throws MalformedIdentityDirectoryException, IOException - { - File idFile = new File( identityDir, "id-hash.data" ); - if( !idFile.exists() ) - { - throw new MalformedIdentityDirectoryException( identityDir ); - } - File bucketDir = new File( identityDir, "buckets" ); - if( !bucketDir.exists() ) - { - throw new MalformedIdentityDirectoryException( identityDir ); - } - RandomAccessFile store = new RandomAccessFile( idFile, "rw" ); - int version = store.readInt(); // Read Version - int entries = store.readInt(); // Read entries - int slotSize = store.readInt(); // Read slotSize - return new IdentityFile( store, bucketDir, slotSize, entries ); - } - - public static IdentityFile create( File identityDir, int slotSize, int idEntries ) - throws IOException - { - FileUtils.delete( identityDir ); - identityDir.mkdirs(); - File idFile = new File( identityDir, "id-hash.data" ); - RandomAccessFile store = new RandomAccessFile( idFile, "rw" ); - initialize( store, idEntries, slotSize ); - File bucketDir = new File( identityDir, "buckets" ); - return new IdentityFile( store, bucketDir, slotSize, idEntries ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityFileClosedException.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityFileClosedException.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityFileClosedException.java deleted file mode 100644 index 4b663b6..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityFileClosedException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.spi.entitystore.EntityStoreException; - -public class IdentityFileClosedException extends EntityStoreException -{ -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityTooLongException.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityTooLongException.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityTooLongException.java deleted file mode 100644 index bb5c4a0..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/IdentityTooLongException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.api.entity.EntityReference; -import org.qi4j.spi.entitystore.EntityStoreException; - -public class IdentityTooLongException extends EntityStoreException -{ - public IdentityTooLongException( EntityReference identity ) - { - super( "The identity is too long for the configured store: " + identity.toString().length() + ", " + identity ); - - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/MalformedIdentityDirectoryException.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/MalformedIdentityDirectoryException.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/MalformedIdentityDirectoryException.java deleted file mode 100644 index 613e35d..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/MalformedIdentityDirectoryException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import java.io.File; - -public class MalformedIdentityDirectoryException extends Exception -{ - private File idDir; - - public MalformedIdentityDirectoryException( File idDir ) - { - this.idDir = idDir; - } - - public File getDirectory() - { - return idDir; - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/RecordManager.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/RecordManager.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/RecordManager.java deleted file mode 100644 index 9bd7efa..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/RecordManager.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.api.entity.EntityReference; -import org.qi4j.io.Input; -import org.qi4j.spi.entitystore.EntityStoreException; - -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.io.Reader; -import java.util.ArrayList; - -public class RecordManager - implements UndoManager -{ - private static final byte UNDO_DELETE = 2; - private static final byte UNDO_MODIFY = 3; - private static final byte UNDO_NEW_IDENTITY = 4; - private static final byte UNDO_DROP_IDENTITY = 5; - private static final byte UNDO_EXTEND = 6; - - private DataStore dataStore; - private RandomAccessFile undoJournal; - private ArrayList<UndoCommand> commands; - - public RecordManager( File dataDir, boolean recover ) - throws IOException - { - File undoFile = new File( dataDir, "undo.data" ); - dataStore = new DataStore( dataDir, this ); - commands = new ArrayList<UndoCommand>(); - if( undoFile.exists() ) - { - undoJournal = new RandomAccessFile( undoFile, "rw" ); - if( recover && undoJournal.length() > 0 ) - { - recover(); - } - } - else - { - undoFile.createNewFile(); - undoJournal = new RandomAccessFile( undoFile, "rw" ); - } - - } - - public void putData( DataBlock data ) - throws IOException - { - dataStore.putData( data ); - } - - public void deleteData( EntityReference reference ) - throws IOException - { - dataStore.delete( reference ); - } - - public DataBlock readData( EntityReference reference ) - throws IOException - { - return dataStore.readData( reference ); - } - - - public void commit() - throws IOException - { - dataStore.flush(); - commands.clear(); - undoJournal.setLength( 0 ); - } - - public void discard() - throws IOException - { - for( UndoCommand command : commands ) - { - command.undo( dataStore.dataFile(), dataStore.identityFile() ); - } - commands.clear(); - undoJournal.setLength( 0 ); - } - - public void close() - throws IOException - { - dataStore.close(); - } - - public void saveUndoCommand( UndoCommand command ) - { - commands.add( command ); - try - { - if( command instanceof UndoDeleteCommand ) - { - undoJournal.write( UNDO_DELETE ); - command.save( undoJournal ); - } - else if( command instanceof UndoModifyCommand ) - { - undoJournal.write( UNDO_MODIFY ); - command.save( undoJournal ); - } - else if( command instanceof UndoDropIdentityCommand ) - { - undoJournal.write( UNDO_DROP_IDENTITY ); - command.save( undoJournal ); - } - else if( command instanceof UndoNewIdentityCommand ) - { - undoJournal.write( UNDO_NEW_IDENTITY ); - command.save( undoJournal ); - } - else if( command instanceof UndoExtendCommand ) - { - undoJournal.write( UNDO_EXTEND ); - command.save( undoJournal ); - } - else - { - throw new InternalError(); - } - } - catch( IOException e ) - { - throw new EntityStoreException( "Undo storage medium is malfunctioning." ); - } - } - - private void recover() - { - try - { - undoJournal.seek( 0 ); - while( undoJournal.getFilePointer() < undoJournal.length() ) - { - byte type = undoJournal.readByte(); - UndoCommand command; - if( type == UNDO_MODIFY ) - { - command = UndoModifyCommand.load( undoJournal ); - } - else if( type == UNDO_DELETE ) - { - command = UndoDeleteCommand.load( undoJournal ); - } - else if( type == UNDO_DROP_IDENTITY ) - { - command = UndoDropIdentityCommand.load( undoJournal ); - } - else if( type == UNDO_EXTEND ) - { - command = UndoExtendCommand.load( undoJournal ); - } - else if( type == UNDO_NEW_IDENTITY ) - { - command = UndoNewIdentityCommand.load( undoJournal ); - } - else - { - throw new InternalError(); - } - commands.add( command ); - } - discard(); - } - catch( IOException e ) - { - throw new EntityStoreException( "Unable to recover from previous crash." ); - } - } - - public Input<Reader, IOException> data() - { - return dataStore.data(); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/StoreIterator.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/StoreIterator.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/StoreIterator.java deleted file mode 100644 index 69d1fd6..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/StoreIterator.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.api.entity.EntityReference; - -import java.io.IOException; -import java.io.RandomAccessFile; -import java.util.Iterator; - -class StoreIterator - implements Iterator<EntityReference> -{ - private boolean isAvailable; - private RandomAccessFile store; - private EntityReference identity; - private long position; - private int identityMaxLength; - - StoreIterator( RandomAccessFile store, int identityMaxLength ) - { - this.store = store; - this.position = DataStore.DATA_AREA_OFFSET; - this.identityMaxLength = identityMaxLength; - getNext(); - } - - public boolean hasNext() - { - return isAvailable; - } - - public EntityReference next() - { - EntityReference result = identity; - getNext(); - return result; - } - - private void getNext() - { - try - { - while( store.getFilePointer() < store.length() ) - { - store.seek( position ); - int blockSize = store.readInt(); - if( blockSize == 0 ) - { - // TODO This is a bug. Why does it occur?? - isAvailable = false; - return; - } - position = position + blockSize; // position for next round... - byte usage = store.readByte(); - if( usage == 1 || usage == 2 ) - { - store.skipBytes( 12 ); - identity = readIdentity(); - isAvailable = true; - return; - } - } - isAvailable = false; - } - catch( IOException e ) - { - identity = null; - isAvailable = false; - } - } - - public void remove() - { - throw new UnsupportedOperationException(); - } - - private EntityReference readIdentity() - throws IOException - { - int idSize = store.readByte(); - if( idSize < 0 ) - { - idSize = idSize + 256; // Fix 2's-complement negative values of bytes into unsigned 8 bit. - } - byte[] idData = new byte[idSize]; - store.read( idData ); - store.skipBytes( identityMaxLength - idSize ); - return new EntityReference( new String( idData ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftConfiguration.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftConfiguration.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftConfiguration.java deleted file mode 100644 index b36db15..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftConfiguration.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.api.common.Optional; -import org.qi4j.api.common.UseDefaults; -import org.qi4j.api.configuration.ConfigurationComposite; -import org.qi4j.api.property.Property; - -public interface SwiftConfiguration extends ConfigurationComposite -{ - Property<String> storageDirectory(); - - @Optional @UseDefaults Property<Boolean> turboMode(); - - @Optional @UseDefaults Property<Boolean> recover(); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreAssembler.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreAssembler.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreAssembler.java deleted file mode 100644 index 55c217b..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreAssembler.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.api.common.Visibility; -import org.qi4j.bootstrap.Assembler; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.spi.uuid.UuidIdentityGeneratorService; - -public class SwiftEntityStoreAssembler - implements Assembler -{ - private String configurationModuleName; - - public SwiftEntityStoreAssembler( String configurationModule ) - { - this.configurationModuleName = configurationModule; - } - - public void assemble( ModuleAssembly module ) throws AssemblyException - { - module.services( SwiftEntityStoreService.class, UuidIdentityGeneratorService.class ); - ModuleAssembly config = module.layer().module( configurationModuleName ); - config.entities( SwiftConfiguration.class ).visibleIn( Visibility.layer ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreMixin.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreMixin.java deleted file mode 100644 index 89cf3e5..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreMixin.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.api.configuration.Configuration; -import org.qi4j.api.entity.EntityReference; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.injection.scope.Uses; -import org.qi4j.api.service.ServiceActivation; -import org.qi4j.api.service.ServiceDescriptor; -import org.qi4j.io.Input; -import org.qi4j.spi.entitystore.EntityNotFoundException; -import org.qi4j.spi.entitystore.EntityStoreException; -import org.qi4j.spi.entitystore.helpers.MapEntityStore; - -import java.io.*; -import java.util.concurrent.locks.ReadWriteLock; -import org.qi4j.api.entity.EntityDescriptor; - -public class SwiftEntityStoreMixin - implements ServiceActivation, MapEntityStore -{ - private @This ReadWriteLock lock; - @Uses private ServiceDescriptor descriptor; - @This private Configuration<SwiftConfiguration> configuration; - private RecordManager recordManager; - - public void activateService() - throws Exception - { - SwiftConfiguration conf = configuration.get(); - String storage = conf.storageDirectory().get(); - File storageDir; - storageDir = new File( storage ); - Boolean recover = conf.recover().get(); - if( recover == null ) - { - recover = Boolean.TRUE; - } - recordManager = new RecordManager( storageDir, recover ); - } - - public void passivateService() - throws Exception - { - recordManager.close(); - } - - public Reader get( EntityReference entityReference ) - throws EntityStoreException - { - try - { - DataBlock dataBlock = recordManager.readData( entityReference ); - if( dataBlock == null ) - { - throw new EntityNotFoundException( entityReference ); - } - StringReader reader = new StringReader( new String( dataBlock.data, "UTF-8" ) ); - return reader; - } - catch( UnsupportedEncodingException e ) - { - // Can not happen. - throw new InternalError(); - } - catch( IOException e ) - { - throw new EntityStoreException( "Unable to read '" + entityReference + "' from the store.", e ); - } - } - - public Input<Reader, IOException> entityStates() - { - return recordManager.data(); - } - - public void applyChanges( MapChanges changes ) - throws IOException - { - try - { - changes.visitMap( new MapChanger() - { - public Writer newEntity( final EntityReference ref, EntityDescriptor entityType ) throws IOException - { - return new StringWriter( 1000 ) - { - @Override public void close() throws IOException - { - super.close(); - - byte[] stateArray = toString().getBytes( "UTF-8" ); - DataBlock block = new DataBlock( ref, stateArray, 0, 0 ); - recordManager.putData( block ); - } - }; - } - - public Writer updateEntity( final EntityReference ref, EntityDescriptor entityType ) throws IOException - { - return new StringWriter( 1000 ) - { - @Override public void close() throws IOException - { - super.close(); - byte[] stateArray = toString().getBytes( "UTF-8" ); - DataBlock block = new DataBlock( ref, stateArray, 0, 0 ); - recordManager.putData( block ); - } - }; - } - - public void removeEntity( EntityReference ref, EntityDescriptor entityType ) throws EntityNotFoundException - { - try - { - recordManager.deleteData( ref ); - } - catch( IOException e ) - { - throw new EntityStoreException( e ); - } - } - } ); - recordManager.commit(); - } - catch( Exception e ) - { - recordManager.discard(); - if( e instanceof IOException ) - { - throw (IOException) e; - } - else if( e instanceof EntityStoreException ) - { - throw (EntityStoreException) e; - } - else - { - IOException exception = new IOException(); - exception.initCause( e ); - throw exception; - } - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreService.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreService.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreService.java deleted file mode 100644 index 3386862..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/SwiftEntityStoreService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.api.concern.Concerns; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.service.ServiceActivation; -import org.qi4j.library.locking.LockingAbstractComposite; -import org.qi4j.spi.entitystore.ConcurrentModificationCheckConcern; -import org.qi4j.spi.entitystore.EntityStateVersions; -import org.qi4j.spi.entitystore.EntityStore; -import org.qi4j.spi.entitystore.StateChangeNotificationConcern; -import org.qi4j.spi.entitystore.helpers.MapEntityStoreMixin; - -@Concerns( { StateChangeNotificationConcern.class, ConcurrentModificationCheckConcern.class } ) -@Mixins( { MapEntityStoreMixin.class, SwiftEntityStoreMixin.class } ) -public interface SwiftEntityStoreService - extends ServiceActivation, EntityStore, EntityStateVersions, LockingAbstractComposite -{ -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoCommand.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoCommand.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoCommand.java deleted file mode 100644 index 8570716..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import java.io.IOException; -import java.io.RandomAccessFile; - -public interface UndoCommand -{ - void undo( RandomAccessFile dataFile, IdentityFile idFile ) throws IOException; - - void save( RandomAccessFile undoJournal ) throws IOException; -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoDeleteCommand.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoDeleteCommand.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoDeleteCommand.java deleted file mode 100644 index 32eff50..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoDeleteCommand.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import java.io.IOException; -import java.io.RandomAccessFile; - -/** - * Record has been deleted and we want to restore it. - * - * Block Structure - * [blockSize] 4 bytes - * [usage] 1 byte (0=Unused, 1=prime, 2=mirror, 3=primeChanged, 4=mirrorChanged) - * [instanceVersion] 8 bytes - * [schemaVersion] 4 bytes - * [identitySize] 1 byte - * [identity] IDENTITY_MAX_LENGTH bytes - * [mirrorPointer] 8 bytes - * [primeDataLength] 4 bytes - * [primeData] n bytes - * [mirrorDataLength] 4 bytes - * [mirrorData] n bytes - */ -public class UndoDeleteCommand - implements UndoCommand -{ - private long position; - private byte usage; - - public UndoDeleteCommand( long position, byte usage ) - { - this.position = position; - this.usage = usage; - } - - public void undo( RandomAccessFile dataFile, IdentityFile idFile ) - throws IOException - { - dataFile.seek( position ); - dataFile.skipBytes( 4 ); - dataFile.writeByte( usage ); - } - - public void save( RandomAccessFile undoJournal ) throws IOException - { - undoJournal.writeLong( position ); - undoJournal.writeByte( usage ); - } - - static UndoDeleteCommand load( RandomAccessFile undoJournal ) - throws IOException - { - long position = undoJournal.readLong(); - byte usage = undoJournal.readByte(); - return new UndoDeleteCommand( position, usage ); - } - -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoDropIdentityCommand.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoDropIdentityCommand.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoDropIdentityCommand.java deleted file mode 100644 index f0b6f43..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoDropIdentityCommand.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - - -import java.io.IOException; -import java.io.RandomAccessFile; -import org.qi4j.api.entity.EntityReference; - -public class UndoDropIdentityCommand - implements UndoCommand -{ - private EntityReference reference; - private long position; - - public UndoDropIdentityCommand( EntityReference reference, long position ) - { - this.reference = reference; - this.position = position; - } - - public void undo( RandomAccessFile dataFile, IdentityFile idFile ) throws IOException - { - idFile.remember( reference, position ); - } - - public void save( RandomAccessFile undoJournal ) throws IOException - { - undoJournal.writeUTF( reference.identity() ); - undoJournal.writeLong( position ); - } - - static UndoDropIdentityCommand load( RandomAccessFile undoJournal ) - throws IOException - { - String idString = undoJournal.readUTF(); - EntityReference ref = new EntityReference( idString ); - long pos = undoJournal.readLong(); - return new UndoDropIdentityCommand( ref, pos ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoExtendCommand.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoExtendCommand.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoExtendCommand.java deleted file mode 100644 index f4145f7..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoExtendCommand.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import java.io.IOException; -import java.io.RandomAccessFile; - -/** - * The DataFile has been extended at the end. - * - * To undo this we simply set the Length of the file to the previously known length. - * Block Structure - * [blockSize] 4 bytes - * [usage] 1 byte (0=Unused, 1=prime, 2=mirror, 3=primeChanged, 4=mirrorChanged) - * [instanceVersion] 8 bytes - * [schemaVersion] 4 bytes - * [identitySize] 1 byte - * [identity] IDENTITY_MAX_LENGTH bytes - * [mirrorPointer] 8 bytes - * [primeDataLength] 4 bytes - * [primeData] n bytes - * [mirrorDataLength] 4 bytes - * [mirrorData] n bytes - */ -public class UndoExtendCommand - implements UndoCommand -{ - private long previousLength; - - public UndoExtendCommand( long previousLength ) - { - this.previousLength = previousLength; - } - - public void undo( RandomAccessFile dataFile, IdentityFile idFile ) throws IOException - { - dataFile.setLength( previousLength ); - dataFile.seek( dataFile.length() ); - dataFile.writeInt( -1 ); // Put in the EOF - } - - public void save( RandomAccessFile undoJournal ) throws IOException - { - undoJournal.writeLong( previousLength ); - } - - static UndoExtendCommand load( RandomAccessFile undoJournal ) - throws IOException - { - long position = undoJournal.readLong(); - return new UndoExtendCommand( position ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoManager.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoManager.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoManager.java deleted file mode 100644 index a9dc23e..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoManager.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -public interface UndoManager -{ - void saveUndoCommand( UndoCommand command ); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoModifyCommand.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoModifyCommand.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoModifyCommand.java deleted file mode 100644 index 2331725..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoModifyCommand.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import java.io.IOException; -import java.io.RandomAccessFile; - -/** - * Record has been modified and we can restore it. - * - * Block Structure - * [blockSize] 4 bytes - * [usage] 1 byte (0=Unused, 1=prime, 2=mirror, 3=primeChanged, 4=mirrorChanged) - * [instanceVersion] 8 bytes - * [schemaVersion] 4 bytes - * [identitySize] 1 byte - * [identity] IDENTITY_MAX_LENGTH bytes - * [mirrorPointer] 8 bytes - * [primeDataLength] 4 bytes - * [primeData] n bytes - * [mirrorDataLength] 4 bytes - * [mirrorData] n bytes - */ -public class UndoModifyCommand - implements UndoCommand -{ - private long position; - private byte usage; - private long instanceVersion; - private int schemaVersion; - - public UndoModifyCommand( long position, byte usage, long instanceVersion, int schemaVersion ) - { - this.position = position; - this.usage = usage; - this.instanceVersion = instanceVersion; - this.schemaVersion = schemaVersion; - } - - public void undo( RandomAccessFile dataFile, IdentityFile idFile ) throws IOException - { - dataFile.seek( position + 4 ); - dataFile.writeByte( usage ); - dataFile.writeLong( instanceVersion ); - dataFile.writeInt( schemaVersion ); - } - - public void save( RandomAccessFile undoJournal ) - throws IOException - { - undoJournal.writeLong( position ); - undoJournal.writeByte( usage ); - undoJournal.writeLong( instanceVersion ); - undoJournal.writeInt( schemaVersion ); - } - - static UndoCommand load( RandomAccessFile undoJournal ) - throws IOException - { - long position = undoJournal.readLong(); - byte usage = undoJournal.readByte(); - long instanceVersion = undoJournal.readLong(); - int schemaVersion = undoJournal.readInt(); - return new UndoModifyCommand( position, usage, instanceVersion, schemaVersion ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoNewIdentityCommand.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoNewIdentityCommand.java b/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoNewIdentityCommand.java deleted file mode 100644 index 9293513..0000000 --- a/extensions/entitystore-swift/src/main/java/org/qi4j/entitystore/swift/UndoNewIdentityCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.spi.entity.QualifiedIdentity; -import org.qi4j.api.entity.EntityReference; - -import java.io.IOException; -import java.io.RandomAccessFile; - -public class UndoNewIdentityCommand - implements UndoCommand -{ - private EntityReference reference; - - public UndoNewIdentityCommand( EntityReference reference ) - { - this.reference = reference; - } - - public void undo( RandomAccessFile dataFile, IdentityFile idFile ) throws IOException - { - idFile.drop( reference ); - } - - public void save( RandomAccessFile undoJournal ) throws IOException - { - undoJournal.writeUTF( reference.toString() ); - } - - static UndoNewIdentityCommand load( RandomAccessFile undoJournal ) - throws IOException - { - String idString = undoJournal.readUTF(); - EntityReference ref = new EntityReference( idString ); - return new UndoNewIdentityCommand( ref ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/main/resources/org/qi4j/entitystore/quick/QuickEntityStoreService.properties ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/main/resources/org/qi4j/entitystore/quick/QuickEntityStoreService.properties b/extensions/entitystore-swift/src/main/resources/org/qi4j/entitystore/quick/QuickEntityStoreService.properties deleted file mode 100644 index 32422c2..0000000 --- a/extensions/entitystore-swift/src/main/resources/org/qi4j/entitystore/quick/QuickEntityStoreService.properties +++ /dev/null @@ -1,17 +0,0 @@ - -### Configuration for the Quick EntityStore. -### The commented out properties are the default values if not specified. - - -### The recovery system is needed to ensure a consistent database after a non-managed shutdown, such -### power-failure, JVM crash and "kill -9" -## If there is an Undo file on the file system, use it to undo the pending changes. -# recover=true - -### Storage Directory is the place (relative to current working directory) where the database -### will store its files. This directory needs to be dedicated to Quick EntityStore. -# storageDirectory=qi4j/quickstore - -### TurboMode disables the use of regular Java serialization and uses custom Objcet streams -### for performance reasons. -# turboMode=false \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/DataFileTest.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/DataFileTest.java b/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/DataFileTest.java deleted file mode 100644 index 783b416..0000000 --- a/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/DataFileTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.junit.Assert; -import org.junit.Test; -import org.qi4j.api.entity.EntityReference; - -import java.io.File; - -public class DataFileTest -{ - @Test - public void whenPuttingDataThenExpectSameDataBack() - throws Exception - { - File dir = new File( "swift-store" ); - RecordManager man = new RecordManager( dir, false ); - try - { - EntityReference ref = createReference( "12345678" ); - String data = "Hej hopp du glade man!!"; - DataBlock originalData = new DataBlock( ref, data.getBytes(), 81273, 91283 ); - man.putData( originalData ); - - DataBlock retrieveData = man.readData( ref ); - Assert.assertEquals( "Incorrect Data retrieved.", originalData, retrieveData ); - } - finally - { - FileUtils.delete( dir ); - } - } - - @Test - public void whenPutting100DataWithIndividualCommitsThenExpectSameDataBack() - throws Exception - { - File dir = new File( "swift-store" ); - RecordManager man = new RecordManager( dir, false ); - try - { - EntityReference[] ids = new EntityReference[100]; - String[] values = new String[100]; - int[] schemas = new int[100]; - long[] versions = new long[100]; - long t0 = System.currentTimeMillis(); - for( int i = 0; i < 100; i++ ) - { - ids[ i ] = createReference( "habba" + i ); - values[ i ] = "Hej hopp du glade man!!" + Math.random(); - DataBlock originalData = new DataBlock( ids[ i ], values[ i ].getBytes(), versions[ i ], schemas[ i ] ); - man.putData( originalData ); - man.commit(); - } - long t1 = System.currentTimeMillis(); - System.out.println( "Thruoughput: " + 100000 / ( t1 - t0 ) + " creations/sec" ); - for( int i = 0; i < 100; i++ ) - { - DataBlock data = man.readData( ids[ i ] ); - Assert.assertEquals( "Incorrect Data retrieved.", ids[ i ], data.reference ); - Assert.assertEquals( "Incorrect Data retrieved.", versions[ i ], data.instanceVersion ); - Assert.assertEquals( "Incorrect Data retrieved.", values[ i ], new String( data.data ) ); - Assert.assertEquals( "Incorrect Data retrieved.", schemas[ i ], data.schemaVersion ); - } - } - finally - { - FileUtils.delete( dir ); - } - } - - @Test - public void whenPutting100DataWithSingleCommitThenExpectSameDataBack() - throws Exception - { - File dir = new File( "swift-store" ); - RecordManager man = new RecordManager( dir, false ); - try - { - EntityReference[] ids = new EntityReference[100]; - String[] values = new String[100]; - int[] schemas = new int[100]; - long[] versions = new long[100]; - long t0 = System.currentTimeMillis(); - for( int i = 0; i < 100; i++ ) - { - ids[ i ] = createReference( "habba" + i ); - values[ i ] = "Hej hopp du glade man!!" + Math.random(); - DataBlock originalData = new DataBlock( ids[ i ], values[ i ].getBytes(), versions[ i ], schemas[ i ] ); - man.putData( originalData ); - } - man.commit(); - long t1 = System.currentTimeMillis(); - System.out.println( "Thruoughput: " + 100000 / ( t1 - t0 ) + " creations/sec" ); - for( int i = 0; i < 100; i++ ) - { - DataBlock data = man.readData( ids[ i ] ); - Assert.assertEquals( "Incorrect Data retrieved.", ids[ i ], data.reference ); - Assert.assertEquals( "Incorrect Data retrieved.", versions[ i ], data.instanceVersion ); - Assert.assertEquals( "Incorrect Data retrieved.", values[ i ], new String( data.data ) ); - Assert.assertEquals( "Incorrect Data retrieved.", schemas[ i ], data.schemaVersion ); - } - } - finally - { - FileUtils.delete( dir ); - } - } - - - @Test - public void whenEntityReferenceIsAtMaxThenExpectSameDataBack() - throws Exception - { - File dir = new File( "swift-store" ); - RecordManager man = new RecordManager( dir, false ); - try - { - EntityReference ref = createReference( "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678912" ); - String data = "Hej hopp du glade man!!"; - DataBlock originalData = new DataBlock( ref, data.getBytes(), 81273, 91283 ); - man.putData( originalData ); - man.commit(); - - DataBlock retrieveData = man.readData( ref ); - Assert.assertEquals( "Incorrect Data retrieved.", originalData, retrieveData ); - } - finally - { - FileUtils.delete( dir ); - } - - } - - @Test - public void whenTooLongEntityReferenceThenExpectException() - throws Exception - { - File dir = new File( "swift-store" ); - RecordManager man = new RecordManager( dir, false ); - try - { - StringBuffer buf = new StringBuffer(); - for( int i=0 ; i < 129 ; i++ ) - buf.append( (i % 10) ); - EntityReference ref = createReference( buf.toString() ); - - String data = "Hej hopp du glade man!!"; - DataBlock originalData = new DataBlock( ref, data.getBytes(), 81273, 91283 ); - man.putData( originalData ); - Assert.fail( "Exceeeding max length didn't cause Exception." ); - } - catch( IdentityTooLongException e ) - { - // Expected. - } - finally - { - FileUtils.delete( dir ); - } - - } - - private EntityReference createReference( String identity ) - { - return new EntityReference( identity ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/IdentityFileTest.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/IdentityFileTest.java b/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/IdentityFileTest.java deleted file mode 100644 index 6af5d81..0000000 --- a/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/IdentityFileTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import java.io.File; -import java.io.IOException; -import java.util.Random; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; -import org.qi4j.api.entity.EntityReference; - -@SuppressWarnings( { "ResultOfMethodCallIgnored" } ) -public class IdentityFileTest -{ - private File idFile; - private IdentityFile file; - - @Test - public void whenCreatingNewIdentityFileThenSucceed() - throws Exception - { - idFile = new File( "swift-store" ); - idFile.mkdirs(); - file = IdentityFile.create( idFile, 64, 1000 ); - } - - @Test - public void whenCreatingAnEntryThenGetTheResultBack() - throws Exception - { - idFile = new File( "swift-store" ); - idFile.mkdirs(); - file = IdentityFile.create( idFile, 64, 1000 ); - populateRandom( file ); - long value = 9783249823L; - EntityReference identity = createIdentity( "SomeIdentity" ); - file.remember( identity, value ); - long recalled = file.find( identity ); - Assert.assertEquals( "Wrong position retrieved for item.", value, recalled ); - } - - @Test - public void whenCreating50EntriesThenGetTheResultBack() - throws Exception - { - idFile = new File( "swift-store" ); - idFile.mkdirs(); - file = IdentityFile.create( idFile, 64, 1000 ); - populateRandom( file ); - long[] pos = new long[50]; - for( int i = 0; i < 50; i++ ) - { - pos[ i ] = (long) ( Math.random() * Long.MAX_VALUE ); - EntityReference identity = createIdentity( "Identity-" + i ); - file.remember( identity, pos[ i ] ); - } - - for( int i = 0; i < 50; i++ ) - { - EntityReference identity = createIdentity( "Identity-" + i ); - long recalled = file.find( identity ); - Assert.assertEquals( "Wrong position retrieved for item " + i + ".", pos[ i ], recalled ); - } - } - - - @Test - public void whenIdentityIsLongerThanAllowedExpectException() - throws Exception - { - idFile = new File( "swift-store" ); - idFile.mkdirs(); - file = IdentityFile.create( idFile, 24, 1000 ); - try - { - EntityReference identity = createIdentity( "12345678901" ); - file.remember( identity, 827349813743908274L ); - Assert.fail( "Should not allow this long identity." ); - } - catch( IdentityTooLongException e ) - { - // expected - } - } - - @Test - public void whenNotEnoughSpaceIsAvailableExpectThatCanStillStore() - throws Exception - { - idFile = new File( "swift-store" ); - idFile.mkdirs(); - file = IdentityFile.create( idFile, 64, 1 ); - long[] pos = new long[150]; - for( int i = 0; i < 150; i++ ) - { - pos[ i ] = (long) ( Math.random() * Long.MAX_VALUE ); - EntityReference identity = createIdentity( "Identity-" + i ); - file.remember( identity, pos[ i ] ); - } - - for( int i = 0; i < 150; i++ ) - { - EntityReference identity = createIdentity( "Identity-" + i ); - long recalled = file.find( identity ); - Assert.assertEquals( "Wrong position retrieved for item " + i + ".", pos[ i ], recalled ); - } - } - - @Test - public void whenDroppingAnIdentityExpectMinusOneWhenLookingUp() - throws Exception - { - idFile = new File( "swift-store" ); - idFile.mkdirs(); - file = IdentityFile.create( idFile, 64, 5 ); - long[] pos = new long[150]; - for( int i = 0; i < 150; i++ ) - { - pos[ i ] = (long) ( Math.random() * Long.MAX_VALUE ); - EntityReference identity = createIdentity( "Identity-" + i ); - file.remember( identity, pos[ i ] ); - } - - for( int i = 0; i < 150; i++ ) - { - EntityReference identity = createIdentity( "Identity-" + i ); - file.drop( identity ); - } - - for( int i = 0; i < 150; i++ ) - { - EntityReference identity = createIdentity( "Identity-" + i ); - Assert.assertEquals( "Identity entry not gone.", -1, file.find( identity ) ); - } - } - - @After - public void cleanUp() - { - try - { - file.close(); - } - catch( IOException e ) - { - e.printStackTrace(); - } - delete( idFile ); - } - - private void delete( File file ) - { - if( file.isDirectory() ) - { - for( File child : file.listFiles() ) - { - delete( child ); - } - } - file.delete(); - } - - private EntityReference createIdentity( String identity ) - { - return new EntityReference( identity ); - } - - private void populateRandom( IdentityFile file ) - throws IOException - { - Random rnd = new Random(); - int max = (int) ( file.entries() * 0.5 ); - for( int i = 0; i < max; i++ ) - { - String id = String.valueOf( rnd.nextInt(16) ); - EntityReference ref = new EntityReference( id ); - file.remember(ref, i); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/SwiftEntityStoreTest.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/SwiftEntityStoreTest.java b/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/SwiftEntityStoreTest.java deleted file mode 100644 index e039475..0000000 --- a/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/SwiftEntityStoreTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -import org.qi4j.api.common.Visibility; -import org.qi4j.api.value.ValueSerialization; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.test.entity.AbstractEntityStoreTest; -import org.qi4j.spi.uuid.UuidIdentityGeneratorService; -import org.qi4j.test.EntityTestAssembler; -import org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService; - -public class SwiftEntityStoreTest extends AbstractEntityStoreTest -{ - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - super.assemble( module ); - module.services( SwiftEntityStoreService.class, UuidIdentityGeneratorService.class ); - module.services( OrgJsonValueSerializationService.class ).taggedWith( ValueSerialization.Formats.JSON ); - - ModuleAssembly config = module.layer().module( "config" ); - config.entities( SwiftConfiguration.class ).visibleIn( Visibility.layer ); - new EntityTestAssembler().assemble( config ); - } - -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/SwiftStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/SwiftStorePerformanceTest.java b/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/SwiftStorePerformanceTest.java deleted file mode 100644 index affae56..0000000 --- a/extensions/entitystore-swift/src/test/java/org/qi4j/entitystore/swift/SwiftStorePerformanceTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2009 Niclas Hedhman. - * - * 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.qi4j.entitystore.swift; - -// import org.qi4j.test.entity.performance.AbstractEntityStorePerformanceTest; -import org.junit.Ignore; -import org.qi4j.bootstrap.Assembler; - -@Ignore( "Needs org.qi4j.test.performance dependency" ) -public class SwiftStorePerformanceTest // extends AbstractEntityStorePerformanceTest -{ - public SwiftStorePerformanceTest() - { - // super( "SwiftEntityStore", createAssembler() ); - } - - private static Assembler createAssembler() - { - return new SwiftEntityStoreAssembler( "config" ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/entitystore-swift/src/test/resources/org/qi4j/entitystore/swift/SwiftEntityStoreService.properties ---------------------------------------------------------------------- diff --git a/extensions/entitystore-swift/src/test/resources/org/qi4j/entitystore/swift/SwiftEntityStoreService.properties b/extensions/entitystore-swift/src/test/resources/org/qi4j/entitystore/swift/SwiftEntityStoreService.properties deleted file mode 100644 index 56cc119..0000000 --- a/extensions/entitystore-swift/src/test/resources/org/qi4j/entitystore/swift/SwiftEntityStoreService.properties +++ /dev/null @@ -1 +0,0 @@ -storageDirectory=target/swiftdb http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/extensions/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/pom.xml b/extensions/pom.xml deleted file mode 100644 index 7093373..0000000 --- a/extensions/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <groupId>org.qi4j.sandbox</groupId> - <artifactId>qi4j-sandbox</artifactId> - <version>0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <artifactId>qi4j-sandbox-extensions</artifactId> - <name>Qi4j Sandbox Extensions - Build POM</name> - <packaging>pom</packaging> - - <modules> - <module>entitystore-jndi</module> - <module>entitystore-cassandra</module> - <module>entitystore-jgroups</module> - <module>entitystore-rmi</module> - <module>entitystore-s3</module> - <module>entitystore-swift</module> - - <!-- Coherence needs a manual installation - <module>entitystore-coherence</module> --> - - </modules> -</project> http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/dev-status.xml ---------------------------------------------------------------------- diff --git a/libraries/beans/dev-status.xml b/libraries/beans/dev-status.xml deleted file mode 100644 index 0c93156..0000000 --- a/libraries/beans/dev-status.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<module xmlns="http://www.qi4j.org/schemas/2008/dev-status/1"> - <status> - <codebase>early</codebase> - <!--none,early,beta,stable,mature--> - <documentation>none</documentation> - <!-- none, brief, good, complete --> - <unittests>some</unittests> - <!-- none, some, good, complete --> - </status> - <licenses> - <license>ALv2</license> - </licenses> -</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/pom.xml ---------------------------------------------------------------------- diff --git a/libraries/beans/pom.xml b/libraries/beans/pom.xml deleted file mode 100644 index c8c36c7..0000000 --- a/libraries/beans/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.qi4j.sandbox</groupId> - <artifactId>qi4j-sandbox-libraries</artifactId> - <version>0-SNAPSHOT</version> - </parent> - <groupId>org.qi4j.library</groupId> - <artifactId>org.qi4j.library.beans</artifactId> - <name>Qi4j Library - Beans</name> - <dependencies> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.api</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.spi</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.bootstrap</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.runtime</artifactId> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.testsupport</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Getters.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Getters.java b/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Getters.java deleted file mode 100644 index 14bca23..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Getters.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.qi4j.library.beans.properties; - -import org.qi4j.api.common.AppliesToFilter; - -import java.lang.reflect.Method; - -/** - * Filter for getter methods. Method name must match "get*" or "is*" or "has*". - */ -public class Getters implements AppliesToFilter -{ - public static final MethodPrefixFilter GET = new MethodPrefixFilter( "get" ); - public static final MethodPrefixFilter IS = new MethodPrefixFilter( "is" ); - public static final MethodPrefixFilter HAS = new MethodPrefixFilter( "has" ); - public static final AppliesToFilter GETTERS = new OrAppliesToFilter( GET, IS, HAS ); - - public boolean appliesTo( Method method, Class mixin, Class compositeType, Class modelClass ) - { - return GETTERS.appliesTo( method, mixin, compositeType, modelClass ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Iterables.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Iterables.java b/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Iterables.java deleted file mode 100644 index fe82b96..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Iterables.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2008 Wen Tao. All Rights Reserved. - * - * 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.qi4j.library.beans.properties; - -import org.qi4j.api.common.AppliesToFilter; - -import java.beans.Introspector; -import java.lang.reflect.Method; - -public class Iterables implements PropertyNameExtractor, AppliesToFilter -{ - public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass ) - { - return matches( method.getName() ); - } - - public boolean matches( String methodName ) - { - return methodName.endsWith( "Iterator" ) || "iterator".equals( methodName ); - } - - public String extractPropertyName( String methodName ) - { - if( !matches( methodName ) ) - { - return null; - } - return Introspector.decapitalize( methodName.substring( 0, methodName.length() - 8 ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/properties/MethodPrefixFilter.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/MethodPrefixFilter.java b/libraries/beans/src/main/java/org/qi4j/library/beans/properties/MethodPrefixFilter.java deleted file mode 100644 index bcb7634..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/MethodPrefixFilter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2008 Wen Tao. All Rights Reserved. - * - * 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.qi4j.library.beans.properties; - -import org.qi4j.api.common.AppliesToFilter; - -import java.beans.Introspector; -import java.lang.reflect.Method; - -public class MethodPrefixFilter implements PropertyNameExtractor, AppliesToFilter -{ - private String prefix; - - public MethodPrefixFilter( String prefix ) - { - this.prefix = prefix; - } - - public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass ) - { - return matches( method.getName() ); - } - - public boolean matches( String methodName ) - { - return methodName.startsWith( prefix ); - } - - public String extractPropertyName( String methodName ) - { - if( !matches( methodName ) ) - { - return null; - } - return Introspector.decapitalize( methodName.substring( prefix.length() ) ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/properties/OrAppliesToFilter.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/OrAppliesToFilter.java b/libraries/beans/src/main/java/org/qi4j/library/beans/properties/OrAppliesToFilter.java deleted file mode 100644 index 87a4673..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/OrAppliesToFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2008 Wen Tao. All Rights Reserved. - * - * 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.qi4j.library.beans.properties; - -import org.qi4j.api.common.AppliesToFilter; - -import java.lang.reflect.Method; - -public final class OrAppliesToFilter - implements AppliesToFilter -{ - private final AppliesToFilter[] filters; - - public OrAppliesToFilter( AppliesToFilter... filters ) - { - this.filters = filters; - } - - public final boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass ) - { - for( AppliesToFilter filter : filters ) - { - if( filter.appliesTo( method, mixin, compositeType, fragmentClass ) ) - { - return true; - } - } - return false; - } -}
