/** * Get the {@code Geometries} with the given integer SQL type code. * * @param sqlType the code to look up. * @return the matching type or {@code null} if no match was found */ public static Geometries getForSQLType(int sqlType) { for (Geometries gt : Geometries.values()) { if (gt.sqlType == sqlType) { return gt; } } return null; } }
/** * Get the {@code Geometries} for the specified name. * * @param name The name of the geometry, eg: "POINT" * @return The constant for the name. */ public static Geometries getForName(String name) { for (Geometries gt : Geometries.values()) { if (gt.getName().equalsIgnoreCase(name)) { return gt; } } return null; }
@Override public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) { super.registerClassToSqlMappings(mappings); // add geometry mappings for (Geometries g : Geometries.values()) { mappings.put(g.getBinding(), g.getSQLType()); } // override some internal defaults mappings.put(Long.class, Types.INTEGER); mappings.put(Double.class, Types.REAL); mappings.put(Boolean.class, Types.INTEGER); }
/** Tests getName and getSimpleName */ @Test public void testGetName() { // System.out.println(" getName and getSimpleName"); for (Geometries type : Geometries.values()) { String className = type.getBinding().getSimpleName(); assertTrue(type.getName().equalsIgnoreCase(className)); if (className.startsWith("Multi")) { assertTrue(type.getSimpleName().equalsIgnoreCase(className.substring(5))); } else { assertTrue(type.getSimpleName().equalsIgnoreCase(className)); } } }
@Test public void testGetForSQLType() { // System.out.println(" getSQLType and getForSQLType"); for (Geometries type : Geometries.values()) { int sqlType = type.getSQLType(); assertEquals(type, Geometries.getForSQLType(sqlType)); } } }
@Override public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) { super.registerClassToSqlMappings(mappings); // add geometry mappings for (Geometries g : Geometries.values()) { mappings.put(g.getBinding(), g.getSQLType()); } // override some internal defaults mappings.put(Long.class, Types.INTEGER); mappings.put(Double.class, Types.REAL); mappings.put(Boolean.class, Types.INTEGER); }