Skip to content

Commit

Permalink
Add type mapper to column config
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Oct 13, 2015
1 parent 417dc1b commit 5e8c336
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 13 deletions.
18 changes: 6 additions & 12 deletions src/main/java/com/speedment/component/TypeMapperComponent.java
Expand Up @@ -33,29 +33,23 @@ public interface TypeMapperComponent extends Component {
/**
* Installs the specified type mapper in this component.
*
* @param <DB_TYPE> the database type
* @param <JAVA_TYPE> the java type
* @param typeMapperSupplier the constructor for a mapper to install
*/
<DB_TYPE, JAVA_TYPE> void install(Supplier<TypeMapper<DB_TYPE, JAVA_TYPE>> typeMapperSupplier);
void install(Supplier<TypeMapper<?, ?>> typeMapperSupplier);

/**
* Streams over all the type mappers installed in this component.
*
* @param <DB_TYPE> the database type
* @param <JAVA_TYPE> the java type
* @return all mappers
* @return all mappers
*/
<DB_TYPE, JAVA_TYPE> Stream<TypeMapper<DB_TYPE, JAVA_TYPE>> stream();
Stream<TypeMapper<?, ?>> stream();

/**
* Retreive and return the type mapper with the specified absolute class
* name. If it is not installed, return an empty optional.
*
* @param <DB_TYPE> the database type
* @param <JAVA_TYPE> the java type
* @param absoluteClassName the name as returned by {@code Class.getName()}
* @return the type mapper or empty
* @param absoluteClassName the name as returned by {@code Class.getName()}
* @return the type mapper or empty
*/
<DB_TYPE, JAVA_TYPE> Optional<TypeMapper<DB_TYPE, JAVA_TYPE>> get(String absoluteClassName);
Optional<TypeMapper<?, ?>> get(String absoluteClassName);
}
23 changes: 23 additions & 0 deletions src/main/java/com/speedment/config/Column.java
Expand Up @@ -24,6 +24,7 @@
import com.speedment.internal.core.config.ColumnImpl;
import com.speedment.config.aspects.ColumnCompressionTypeable;
import com.speedment.config.aspects.FieldStorageTypeable;
import com.speedment.config.mapper.TypeMapper;
import static java.util.Objects.requireNonNull;
import java.util.Optional;
import java.util.function.Supplier;
Expand Down Expand Up @@ -170,4 +171,26 @@ default Class<Table> getParentInterfaceMainClass() {
*/
@External(type = Class.class)
void setMapping(Class<?> mappedClass);

/**
* Returns the mapper class that will be used to generate a java
* representation of the database types.
* <p>
* This property is editable in the GUI through reflection.
*
* @return the mapper class
*/
@External(type = Class.class)
Class<? extends TypeMapper<?, ?>> getTypeMapper();

/**
* Sets the mapper class that will be used to generate a java
* representation of the database types.
* <p>
* This property is editable in the GUI through reflection.
*
* @param mapper the new mapper class
*/
@External(type = Class.class)
void setTypeMapper(Class<? extends TypeMapper<?, ?>> mapper);
}
14 changes: 14 additions & 0 deletions src/main/java/com/speedment/internal/core/config/ColumnImpl.java
Expand Up @@ -19,8 +19,10 @@
import com.speedment.config.Column;
import com.speedment.config.Table;
import com.speedment.config.aspects.Parent;
import com.speedment.config.mapper.TypeMapper;
import com.speedment.config.parameters.ColumnCompressionType;
import com.speedment.config.parameters.FieldStorageType;
import com.speedment.internal.core.config.mapper.identity.StringIdentityMapper;
import com.speedment.internal.util.Cast;
import java.util.Optional;

Expand All @@ -37,6 +39,7 @@ public final class ColumnImpl extends AbstractOrdinalConfigEntity implements Col
private FieldStorageType fieldStorageType;
private ColumnCompressionType columnCompressionType;
private Class<?> mapping;
private Class<? extends TypeMapper<?, ?>> typeMapper;

@Override
protected void setDefaults() {
Expand All @@ -45,6 +48,7 @@ protected void setDefaults() {
setFieldStorageType(FieldStorageType.INHERIT);
setColumnCompressionType(ColumnCompressionType.INHERIT);
setMapping(String.class);
setTypeMapper(StringIdentityMapper.class);
}

@Override
Expand Down Expand Up @@ -116,4 +120,14 @@ public Boolean isAutoincrement() {
public void setAutoincrement(Boolean autoincrement) {
this.autoincrement = autoincrement;
}

@Override
public Class<? extends TypeMapper<?, ?>> getTypeMapper() {
return typeMapper;
}

@Override
public void setTypeMapper(Class<? extends TypeMapper<?, ?>> mapper) {
this.typeMapper = mapper;
}
}
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. 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 com.speedment.internal.core.config.mapper.identity;

import com.speedment.config.mapper.TypeMapper;
Expand Down
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. 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 com.speedment.internal.core.config.mapper.identity;

/**
Expand Down
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. 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 com.speedment.internal.core.config.mapper.identity;

/**
Expand Down
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. 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 com.speedment.internal.core.config.mapper.identity;

/**
Expand Down
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. 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 com.speedment.internal.core.config.mapper.identity;

import java.sql.Timestamp;
Expand Down
Expand Up @@ -59,7 +59,7 @@ public final Class<TypeMapperComponent> getComponentClass() {
}

@Override
public final <DB_TYPE, JAVA_TYPE> void install(Supplier<TypeMapper<DB_TYPE, JAVA_TYPE>> typeMapperConstructor) {
public final void install(Supplier<TypeMapper<?, ?>> typeMapperConstructor) {
final TypeMapper mapper = typeMapperConstructor.get();
mappers.put(mapper.getClass().getName(), mapper);
}
Expand Down

0 comments on commit 5e8c336

Please sign in to comment.