This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed unique serializers to be easier to locate
Added serializer to create row format necessary for unique ledger
- Loading branch information
Todd Nine
committed
Feb 24, 2015
1 parent
8c581a4
commit c2989fc
Showing
9 changed files
with
447 additions
and
12 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
.../java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueFieldEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.apache.usergrid.persistence.collection.serialization.impl; | ||
|
||
|
||
import java.util.UUID; | ||
|
||
import org.apache.usergrid.persistence.model.entity.Id; | ||
import org.apache.usergrid.persistence.model.field.Field; | ||
|
||
|
||
/** | ||
* Class that encapsulates a unique field with the entity and version that own it | ||
*/ | ||
public class UniqueFieldEntry { | ||
|
||
private final UUID version; | ||
private final Field field; | ||
|
||
|
||
/** | ||
* Create a unique field with the specified version and field | ||
* @param version | ||
* @param field | ||
*/ | ||
public UniqueFieldEntry( final UUID version, final Field field ) { | ||
this.version = version; | ||
this.field = field; | ||
} | ||
|
||
|
||
public UUID getVersion() { | ||
return version; | ||
} | ||
|
||
|
||
public Field getField() { | ||
return field; | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
...apache/usergrid/persistence/collection/serialization/impl/UniqueFieldEntrySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* | ||
* * | ||
* * Licensed to the Apache Software Foundation (ASF) under one | ||
* * or more contributor license agreements. See the NOTICE file | ||
* * distributed with this work for additional information | ||
* * regarding copyright ownership. The ASF licenses this file | ||
* * to you 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.apache.usergrid.persistence.collection.serialization.impl; | ||
|
||
|
||
import java.nio.ByteBuffer; | ||
import java.util.UUID; | ||
|
||
import org.apache.usergrid.persistence.core.astyanax.DynamicCompositeParserImpl; | ||
import org.apache.usergrid.persistence.model.field.BooleanField; | ||
import org.apache.usergrid.persistence.model.field.DoubleField; | ||
import org.apache.usergrid.persistence.model.field.Field; | ||
import org.apache.usergrid.persistence.model.field.FieldTypeName; | ||
import org.apache.usergrid.persistence.model.field.FloatField; | ||
import org.apache.usergrid.persistence.model.field.IntegerField; | ||
import org.apache.usergrid.persistence.model.field.LongField; | ||
import org.apache.usergrid.persistence.model.field.StringField; | ||
import org.apache.usergrid.persistence.model.field.UUIDField; | ||
|
||
import com.netflix.astyanax.model.CompositeBuilder; | ||
import com.netflix.astyanax.model.CompositeParser; | ||
import com.netflix.astyanax.model.Composites; | ||
import com.netflix.astyanax.model.DynamicComposite; | ||
import com.netflix.astyanax.serializers.AbstractSerializer; | ||
import com.netflix.astyanax.serializers.DynamicCompositeSerializer; | ||
|
||
|
||
/** | ||
* Serialize a unique field into a column name | ||
*/ | ||
public class UniqueFieldEntrySerializer extends AbstractSerializer<UniqueFieldEntry> { | ||
|
||
|
||
private static final UniqueFieldEntrySerializer INSTANCE = new UniqueFieldEntrySerializer(); | ||
|
||
|
||
|
||
|
||
@Override | ||
public ByteBuffer toByteBuffer( final UniqueFieldEntry value ) { | ||
|
||
CompositeBuilder builder = Composites.newDynamicCompositeBuilder(); | ||
|
||
|
||
final UUID version = value.getVersion(); | ||
final Field<?> field = value.getField(); | ||
|
||
final FieldTypeName fieldType = field.getTypeName(); | ||
final String fieldValue = field.getValue().toString().toLowerCase(); | ||
|
||
|
||
builder.addUUID( version ); | ||
builder.addString( field.getName() ); | ||
builder.addString( fieldValue ); | ||
builder.addString( fieldType.name() ); | ||
|
||
return builder.build(); | ||
} | ||
|
||
|
||
@Override | ||
public UniqueFieldEntry fromByteBuffer( final ByteBuffer byteBuffer ) { | ||
|
||
final CompositeParser composite = new DynamicCompositeParserImpl( byteBuffer ); | ||
|
||
final UUID version = composite.readUUID(); | ||
|
||
final String name = composite.readString(); | ||
|
||
final String value = composite.readString(); | ||
|
||
final String typeString = composite.readString(); | ||
|
||
|
||
final FieldTypeName fieldType = FieldTypeName.valueOf( typeString ); | ||
|
||
final Field<?> field; | ||
|
||
switch ( fieldType ) { | ||
case BOOLEAN: | ||
field = new BooleanField( name, Boolean.parseBoolean( value ) ); | ||
break; | ||
case DOUBLE: | ||
field = new DoubleField( name, Double.parseDouble( value ) ); | ||
break; | ||
case FLOAT: | ||
field = new FloatField( name, Float.parseFloat( value )); | ||
break; | ||
case INTEGER: | ||
field = new IntegerField( name, Integer.parseInt( value ) ); | ||
break; | ||
case LONG: | ||
field = new LongField( name, Long.parseLong( value ) ); | ||
break; | ||
case STRING: | ||
field = new StringField( name, value ); | ||
break; | ||
case UUID: | ||
field = new UUIDField( name, UUID.fromString( value ) ); | ||
break; | ||
default: | ||
throw new RuntimeException( "Unknown unique field type" ); | ||
} | ||
|
||
return new UniqueFieldEntry( version, field ); | ||
} | ||
|
||
|
||
/** | ||
* Get the singleton serializer | ||
*/ | ||
public static UniqueFieldEntrySerializer get() { | ||
return INSTANCE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.