@Override public OrmMetadata createMetadata() { DefaultOrmMetadata md = new DefaultOrmMetadata(); md.setDomains(domains); md.setSqlRegistry(sqlRegistry); md.setConfig(config); return md; }
@Override public EntityMapping getEntityMapping(String entityName) throws ObjectNotFoundException { EntityMapping em = tryGetEntityMapping(entityName); if(null == em){ throwEntityNotFound(entityName); } return em; }
@Override public SqlFragment getSqlFragment(String key) throws ObjectNotFoundException { SqlFragment fragment = tryGetSqlFragment(key); if(null == fragment){ throwFragmentNotFound(key); } return fragment; }
@Override public SqlCommand getSqlCommand(String entityName, String commandName) throws ObjectNotFoundException { SqlCommand cmd = tryGetSqlCommand(entityName, commandName); if(null == cmd){ throwSqlNotFound(entityName, commandName); } return cmd; }
@Override public EntityMapping removeEntityMapping(String entityName) { Args.notEmpty(entityName,"entity name"); EntityMapping em = tryGetEntityMapping(entityName); if(null != em){ removeEntityMapping(em); } return em; }
@Override public SqlCommand tryGetSqlCommand(String entityName, String commandName) { Args.notEmpty(entityName,"entity name"); Args.notEmpty(commandName,"command name"); return keyToSqlCommands.get(formatSqlCommandKey(entityName, commandName)); }
protected void checkNotExist(EntityMapping em) throws ObjectExistsException { checkNotExist(em.getEntityName()); checkNotExist(em.getEntityClass()); }
@Override public SqlCommand getSqlCommand(String key) throws ObjectNotFoundException { SqlCommand cmd = tryGetSqlCommand(key); if(null == cmd){ throwSqlNotFound(key); } return cmd; }
@Override public void addSqlCommand(EntityMapping entityMapping, String commandName, SqlCommand cmd) throws ObjectExistsException { Args.notNull(entityMapping,"entity mapping"); Args.notEmpty(commandName,"command name"); Args.notNull(cmd,"sql command"); synchronized (_sqlLock) { if(null != entityMapping.getEntityClass()){ String key = formatSqlCommandKey(entityMapping.getEntityClass(), commandName); if(keyToSqlCommands.containsKey(key)){ throw new ObjectExistsException("sql command '" + commandName + "' of entity class '" + entityMapping.getEntityClass().getName() + "' aleady exists"); } keyToSqlCommands.put(key, cmd); } String key = formatSqlCommandKey(entityMapping.getEntityName(), commandName); if(keyToSqlCommands.containsKey(key)){ throw new ObjectExistsException("sql command '" + commandName + "' of entity '" + entityMapping.getEntityName() + "' aleady exists"); } keyToSqlCommands.put(key, cmd); } }
@Override public void addEntityMapping(EntityMapping em) throws ObjectExistsException { Args.notNull(em); synchronized (_entityLock) { checkNotExist(em); if(null != em.getEntityClass()){ classToEntityMappings.put(em.getEntityClass(),em); } if(null != em.getExtendedEntityClass()) { classToEntityMappings.put(em.getExtendedEntityClass(), em); } if(null != em.getModelClass()){ modelToEntityMappings.put(em.getModelClass(), em); } nameToEntityMappings.put(em.getEntityName().toLowerCase(), em); tableToEntityMappings.put(em.getTableName().toLowerCase(), em); } }
@Override public EntityMapping getEntityMapping(Class<?> entityClass) { EntityMapping em = tryGetEntityMapping(entityClass); if(null == em){ throwEntityNotFound(entityClass); } return em; }